Created Fri, 13 Jul 2012 07:56:37 +0000 by mamumo
Fri, 13 Jul 2012 07:56:37 +0000
Hello!
I am working with max32 board and basic I/O shield and this GPS module: http://www.cooking-hacks.com/index.php/gps-module-for-arduino.html
I want to see on the screen (graphic oled) GPS sentences, but it appears a failure of "invalid conversion" , I don't know what type of instruction I have to use to write the character on the display.
This is my program:
#include <IOShieldOled.h> #include <SoftwareSerial.h>
#define txPin 70 //el pin tx para conexión con GPS #define rxPin 71 //el pin rx para conexión con GPS
SoftwareSerial gps = SoftwareSerial(rxPin,txPin); //llama a la libreria SoftwareSerial para configurar rx y tx
//variables byte byteGPS = 0; // declara 'byteGPS' como byte(almacena un valor numerico de 8 bits sin decimales) int i= 0; int h= 0;
//buffers para datos de entrada
char inBuffer[100]=""; char GPS_RMC[70]="";
void setup(){
IOShieldOled.begin();
//confifguracion para mi puerto serie pinMode (rxPin, INPUT); pinMode (txPin, OUTPUT); gps.begin(4800);
//configuracion para el puerto serie Serial.begin(19200);
delay(1000); }
void loop(){
//leer la sentencia RMC del GPS byteGPS=0; byteGPS=gps.read(); while(byteGPS!='R') //lee los datos de GPS hasta que encuentra 'R' GPS_RMC[0]='$'; //cuando ya ha encontrado 'R' escribe lo siguiente GPS_RMC[1]='G'; GPS_RMC[2]='P'; GPS_RMC[3]='R';
i=4; while(byteGPS!='') //mientras no encuentre el '' sigue leyendo y dando valores a la variable byteGPS
//pasa las sentencias de RMC al USB
Serial.print("RMC sentence:"); h=0; while(GPS_RMC[h]!=42) { //j=0; Serial.print(GPS_RMC[h],BYTE); IOShieldOled.setCursor(0, 0); IOShieldOled.putString(byteGPS); // I think here is the problem h++;
} Serial.println(); }
If anyone can help me I will be grateful Thank you!
(Sorry my english)
Fri, 13 Jul 2012 09:52:45 +0000
Is it a compilation error you get? If so, what line is it on?
Fri, 13 Jul 2012 10:37:10 +0000
Majenko this is:
sketch_jul13b.cpp: In function 'void loop()': sketch_jul13b.cpp:71:31: error: invalid conversion from 'byte' to 'char*' sketch_jul13b.cpp:71:31: error: initializing argument 1 of 'void IOShieldOledClass::putString(char*)'
Fri, 13 Jul 2012 10:44:02 +0000
I thougth maybe with this other sentences, will be good
IOShieldOled.putString(GPS_RMC[h]);
but I have a invalid conversion char to char
I don't know how convert my 'char GPS_RMC[h]' so that it can be read by the oled display.
Fri, 13 Jul 2012 10:51:03 +0000
invalid conversion from 'byte' to 'char*'
That is saying that you are providing a single 8-bit value, but the function is expecting a pointer to an array of characters (note the * - it's important).
To use .putString you will need to convert that byte into a character string. If the byte is a number that you want to display as a number, then you will need to format it as such. The easiest way is with "sprintf".
char buffer[4];
sprintf(buffer,"%d",GPS_RMC[h]);
IOShieldOled.putString(buffer);
Fri, 13 Jul 2012 11:27:13 +0000
Thank you majenko!!
I have tried your sentences, but I don't understand the meaning of this instruction sprintf(inBuffer,"%d",GPS_RMC[h]); and either the two numbers that appear on my screen and do not stop moving.
You know??
Fri, 13 Jul 2012 11:34:33 +0000
the sprintf function formats a string of variables and places them into a buffer.
"%d" is a placeholder for an integer value (you can use %i too, but I'm old-school). The %d is replaced by the value in the third parameter (your GPS data) as a decimal number, and the results are stored in the buffer pointed to by the first parameter.
If the data in the GPS_RMC[h] variable isn't meant to be represented as a number, then you will have do display it in some other way (if it's a single character, then replace the %d with %c).
I don't know what it is you're storing in the GPS_RMC array, so I can't say how you should format it. What would you be expecting to see?
Fri, 13 Jul 2012 11:48:58 +0000
I am very grateful for your explanation!!
Gps signal of RMC provides many data like date, time, latitude, longitude... this is an example:
RMC sentence:$GPRMC,114614.871,V,,,,,,,130712,,,N RMC sentence:$GPRMC,114615.871,V,,,,,,,130712,,,N
Is not a good signal because I am indoors.
I want numeric datas of latitude and longitude for my screen.
Fri, 13 Jul 2012 11:55:01 +0000
In this web there are good sentences of GPS.
http://www.gpsinformation.org/dale/nmea.htm#RMC
Fri, 13 Jul 2012 12:03:26 +0000
Right
So you have a string of characters in the GPS_RMC array.
You can print the entire array with
IOShieldOled.putString(GPS_RMC);
But, to do anything intelligible with it you will need to extract the data from it.
The string is separated into fields using the ',' character. You can split the incoming data up into different strings when you hit the ',' character, or you can read it all in to one string (as you are now doing) and then split it up afterwards. The easiest way might be to do it an reading time:
char lat[20];
char lon[20];
char inByte;
byte field;
byte cpos;
field = 0;
cpos = 0;
inByte = gps.read();
while(inByte != '*')
{
if(inByte == ',')
{
field++;
cpos=0;
} else {
if(field == 1)
{
lat[cpos++] = inByte;
lat[cpos] = 0;
}
if(field == 9)
{
lon[cpos++] = inByte;
lon[cpos] = 0;
}
}
inByte = gps.read();
}
Then you have two string "lat" and "lon" that you can print where you like on the display with
IOShieldOled.putString(lat);
// and
IOShieldOled.putString(lon);
You can of course expand the code to get the data for other fields as well.
Fri, 13 Jul 2012 12:23:26 +0000
OOOOHHHH!!
I have seen the time in my screennn, I am very happy!!
Thank you, Thank you,Thank you,Thank you.....
I'm very grateful for your help, you are a good person!
I will continue working with my board and I will tell you.
I never tire of saying thanks.
Muchas gracias desde España.