GPS string problems (Vincotech’s GPS module) [SOLVED]

Hi to all,
I’m trying to receive GPS sentences from the GPS Module Vincontech, like this: http://www.cooking-hacks.com/index.php/gps-module-for-arduino.html

I tried the tutorial on vendor site: http://www.cooking-hacks.com/index.php/documentation/tutorials/arduino-gps
but it doesn’t work and so…

I tried a smaller and simpler sketch, the following one:

// include the SoftwareSerial library
#include <SoftwareSerial.h>

// Constants
#define rxPin 9      //rx pin in gps connection
#define txPin 8      //tx pin in gps connection

// set up the serial port

SoftwareSerial gps = SoftwareSerial(rxPin, txPin);

// variables
byte byteGPS = 0;
int i = 0;
int h = 0;

// Buffers for data input
char GPS[310]="";
char inBuffer[310] = "";


void setup(){

  //setup for mySerial port
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  gps.begin(4800);
  
  //setup for Serial port (changed from 19200 to 9600)
  Serial.begin(9600);
  
  delay(1000);
}


void loop(){
  
  // waiting sentence from GPS (first character '

but I still have problems…
on monitor I receive wrong parts of sentences like these:

GPGSA,A,1,,,,,,ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿGPGGA,133515.972,,,,,0,00,,,M,0.0,M,,0000*

why I receive these non-ASCII characters?

NOTE: the baudrate of GPS, on site vendor, on vendro sketch (and on firmware pdf: http://www.cooking-hacks.com/skin/frontend/default/cooking/pdf/GPS_Firmware_GSC3_3.5.0_V4.2.pdf)
is set on 4800 Baut.
On vendor sketch I have Serial.begin(19200), but with this setting the monitor doesn’t works.
So I reduced to Serial.begin(9600), and it’s only baudrate that give ASCII text response on monitor.

(I don’t know very deeply baudrate rules, I only tried some configuration untill results)

tank you for all suggestions! = ASCII (dec) 36):
   byteGPS = 0;
   byteGPS = gps.read();
   
   while(byteGPS != 36){
     byteGPS = gps.read();
   }

// reading sentence from GPS (until reached '’ = ASCII (dec) 42):
   i = 0;
   
   while(byteGPS != 42){
     byteGPS = gps.read();      
     inBuffer[i]=byteGPS;
     Serial.print(inBuffer[i]);
     i++;                      
   }
 
 // print GPS sentence to USB:
   h = 0;
   while(h < i){          // (WARNING: string stop at "
", excluding checksum numbers)
     Serial.print(GPS[h]);
     h++;
   }
     
 // carriage return:
   Serial.println();  
}


but I still have problems..
on monitor I receive wrong parts of sentences like these:

§DISCOURSE_HOISTED_CODE_1§


why I receive these non-ASCII characters?

NOTE: the baudrate of GPS, on site vendor, on vendro sketch (and on firmware pdf: http://www.cooking-hacks.com/skin/frontend/default/cooking/pdf/GPS_Firmware_GSC3_3.5.0_V4.2.pdf)
is set on 4800 Baut.
On vendor sketch I have `§_DISCOURSE_HOISTED_CODE_2_§`, but with this setting the monitor doesn't works.
So I reduced to Serial.begin(9600), and it's only baudrate that give ASCII text response on monitor.

(I don't know very deeply baudrate rules, I only tried some configuration untill results)

tank you for all suggestions!

If you are not sure what speed it is outputting, try all the plausible speeds. One of them should work. 4800, 9600,etc

One of my devices, the spec says 9600 but it is actually 19200.

If none of them work, it is possible there is something wrong with it.

All of your code for reading the serial port looks wrong.

You are trying to read a char from the serial port, when there might not even be a char available. You need to get a better understanding of how to read serial input streams. The entire NMEA message may not arrive during a single iteration of loop().

the IDE serial monitor defaults to 9600, but make sure the app and IDE use the same rate.

Initialise empty global arrays like:

char GPS[310];
char inBuffer[310];

the heap space is 0 initialised when powered on, the first element will already have a null.

You read from the GPS without checking to see if there is any data. Does this matter for your code, it makes me wonder cos:

      byteGPS = gps.read();      
      inBuffer[i]=byteGPS;
      Serial.print(inBuffer[i]);
      i++;

You appear to be looping until the serial reaches a certain value, not so great if random data is incoming, i++ can go way out of bounds.

Tank you for helping…

try all the plausible speeds

I’m quite doing that, but seems to work fine only with one configuration.

You need to get a better understanding of how to read serial input streams

I know, I’m trying to learn :slight_smile:

The entire NMEA message may not arrive during a single iteration of loop().

I thought that if GPS run on 4800 baud => 4800 bit/s => 4800/8 byte = 600 that is very much more than a sentence.
Generally a GPS stream one sentence in a second (commonly a bit less than a second), so I can find a sentence in a loop (with delay = 1000)
Infact, I read all the sentence in every line, the problem is that sentence doesn’t give me checksum number (2 numbers after “*”) and other non-ascii characters…

the IDE serial monitor defaults to 9600, but make sure the app and IDE use the same rate.

If you mean serial monitor baudrate, I setted it on 9600, as Serial.begin()

Initialise empty global arrays like:
char GPS[310];
char inBuffer[310];

I did before Void.setup{ }, Do you ask me to move these lines? where?

You read from the GPS without checking to see if there is any data. Does this matter for your code, it makes me wonder cos:
byteGPS = gps.read();
inBuffer*=byteGPS;*
_ Serial.print(inBuffer*);_
_
i++; [/quote]_
ok…
I pasted wrong sketch, I used many tries.
Right sketch is (sorry):
_
*_ <em>*// reading sentence from GPS (until reached '*' = ASCII (dec) 42):     i = 0;     hh = 0;     while(byteGPS != 42){       hh = i;       byteGPS = gps.read();            GPS[i] = byteGPS;       i++;                          }     // print GPS sentence to USB:     h = 0;     while(h < hh){          // (WARNING: string stop at "*", excluding checksum numbers)       Serial.print(GPS[h]);       h++;     }         // carriage return:     Serial.println();  }*</em> _**_
do you read some error?
tank you all.

y umlaut is usually caused by printing 255 (-1) to the serial port. Negative one is what a serial.read command returns when there is no character to read. Your code does not use gps.available to see if there is a character from the gps to be read, so you're going to see a lot of those y characters.

  // waiting sentence from GPS (first character '
Why beat around the bush this way?
    while(byteGPS != '

No comment needed.

char GPS[310]="";
char inBuffer[310] = "";

There goes a significant portion of the SRAM available on a 328-based Arduino.

Are you REALLY expecting 310 character sentences? Do you REALLY need to make a copy of them? = ASCII (dec) 36):     byteGPS = 0;     byteGPS = gps.read();         while(byteGPS != 36){ ```

§_DISCOURSE_HOISTED_CODE_1_§

No comment needed.

§_DISCOURSE_HOISTED_CODE_2_§

There goes a significant portion of the SRAM available on a 328-based Arduino.

Are you REALLY expecting 310 character sentences? Do you REALLY need to make a copy of them?)     { ```

No comment needed.

§_DISCOURSE_HOISTED_CODE_2_§

There goes a significant portion of the SRAM available on a 328-based Arduino.

Are you REALLY expecting 310 character sentences? Do you REALLY need to make a copy of them? = ASCII (dec) 36):     byteGPS = 0;     byteGPS = gps.read();         while(byteGPS != 36){ ```

§_DISCOURSE_HOISTED_CODE_1_§

No comment needed.

§_DISCOURSE_HOISTED_CODE_2_§

There goes a significant portion of the SRAM available on a 328-based Arduino.

Are you REALLY expecting 310 character sentences? Do you REALLY need to make a copy of them?

wildbill: y umlaut is usually caused by printing 255 (-1) to the serial port. Negative one is what a serial.read command returns when there is no character to read. Your code does not use gps.available to see if there is a character from the gps to be read, so you're going to see a lot of those y characters.

Thank you, this looks a good reason, I was looking for something like. Now I try to study how it works gps.available (serial.available). Now I'm quite happy, it was a very demotivating result don't know why too many not-ASCII presence.

Are you REALLY expecting 310 character sentences? Do you REALLY need to make a copy of them?

I used the same number that appear on site vendor sketch. I think (as you) that is too much, but first I tried to understand a clear reception of sentences, then I'll try to perform at best my sketch. (tank you)

Ok, I don’t understand =(

new “test sketch”…

Setup, exactly as before (for void loop look under):

// include the SoftwareSerial library
#include <SoftwareSerial.h>

// Constants
#define rxPin 9      //rx pin in gps connection
#define txPin 8      //tx pin in gps connection

// set up the serial port

SoftwareSerial gps = SoftwareSerial(rxPin, txPin);

// variables
byte byteGPS = 0;
int i = 0;
int h = 0;

// Buffers for data input
char GPS[310]="";
char inBuffer[310] = "";


void setup(){

  //setup for mySerial port
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  gps.begin(4800);
  
  //setup for Serial port (changed from 19200 to 9600)
  Serial.begin(9600);
  
  delay(1000);
}

void loop:

void loop(){
  
  // waiting sentence from GPS;
    
    byteGPS = 0;
    byteGPS = gps.read();

  // reading sentence from GPS:
    i = 0;
    Serial.print("reading: ");
    Serial.print(byteGPS);
    inBuffer[i] = byteGPS;
    Serial.print(" => ");
    Serial.print(inBuffer[i]);
    
if (Serial.available() > 0) {
        Serial.print("available");
      byteGPS = gps.read();      
      inBuffer[i]=byteGPS;
      Serial.print(inBuffer[i]);
      i++;                      
    }
     
  // carriage return:
    Serial.println();  
}

Note, “if loop” repeat Serial.print(inBuffer*), but it happens only if: Serial.available() > 0*
Monitor returns:
```
*reading: 36 => $
reading: 71 => G
reading: 80 => P
reading: 71 => G
reading: 71 => G
reading: 65 => A
reading: 44 => ,
reading: 49 => 1
reading: 53 => 5
reading: 51 => 3
reading: 56 => 8
reading: 53 => 5
reading: 51 => 3
reading: 46 => .
reading: 51 => 3
reading: 53 => 5
reading: 48 => 0
reading: 44 => ,
reading: 44 => ,
reading: 44 => ,
reading: 44 => ,
reading: 44 => ,
reading: 48 => 0
reading: 44 => ,
reading: 48 => 0
reading: 48 => 0
reading: 44 => ,
reading: 44 => ,
reading: 44 => ,
reading: 77 => M
reading: 44 => ,
reading: 48 => 0
reading: 46 => .
reading: 48 => 0
reading: 44 => ,
reading: 77 => M
reading: 44 => ,
reading: 44 => ,
reading: 48 => 0
reading: 48 => 0
reading: 48 => 0
reading: 48 => 0
reading: 42 => *
reading: 53 => 5
reading: 57 => 9
reading: 13 =>

reading: 10 =>*
```
so…
everything works at well!!
… but, why I have never Serial.available() > 0 (if condition is true i wolud have on monitor “available”.(Serial.print(“available”))
Second question, why in this sketch every byte is corrected but I can’t write on serial monitor sentences one per line??
tank you.

void loop(){
  
  // waiting sentence from GPS;
    
    byteGPS = 0;
    byteGPS = gps.read();

  // reading sentence from GPS:
    i = 0;
    Serial.print("reading: ");
    Serial.print(byteGPS);
    inBuffer[i] = byteGPS;

In spite of the comment, the code does not wait for data to be available.

In spite of the comment, Serial.read() does not read a whole sentence. On any given pass through loop, you are going to read one character, print several, and store it in position 1 of the array.

I found a sketch that works fine at all:

// include the SoftwareSerial library
#include <SoftwareSerial.h>

// Constants
#define rxPin 9      //rx pin in gps connection
#define txPin 8      //tx pin in gps connection

// set up the serial port

SoftwareSerial gps = SoftwareSerial(rxPin, txPin);

// variables
byte byteGPS = 0;
int i = 0;
int h = 0;

// Buffers for data input
char GPS[310]="";
char inBuffer[310] = "";


void setup(){

  //setup for mySerial port
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  gps.begin(4800);
  
  //setup for Serial port (changed from 19200 to 9600)
  Serial.begin(9600);
  
  delay(1000);
}


void loop(){
  
  // waiting sentence from GPS (first character '

I don’t know why…
I don’t understand why i switch by itself…

Note: instead of: if (Serial.available() > 0){ that didn’t work (never entered in loop “if”)
I used if (inBuffer[i] > 0){

now I have to understand why…

ps: monitor response:

$GPGGA,160552.360,,,,,0,00,,,M,0.0,M,,0000*56

$GPGSA,A,1,,,,,,
$GPGGA,160553.361,,,,,0,00,,,M,0.0,M,,0000*56

$GPGSA,A,1,,,,,,,,,,,,,,,*1E

$GPRMC,160553.361,V,,,,,,,310113,,,N*4C

$GPGGA,160554.363,,,,,0,00,,,M,0.0,M,,0000*53

$GPGSA,A,1,,,,,,,,,,,,,,,*1E

$GPGSV,1,1,00*79

$GPRMC,160554.363,V,,,,,,,310113,,,N*49

$GPGGA,160555.362,,,,,0,00,,,M,0.0,M,,0000*53

$GPGSA,A,1,,,,,,,,,,,,,,,*1E

$GPRMC,160555.362,V,,,,,,,310113,,,N*49

$GPGGA,160556.360,,,,,0,00,,,M,0.0,M,,0000*52

= ASCII (dec) 36):
   
 byteGPS = 0;
 i = 0;

// reading sentence from GPS (until reached ‘*’ = ASCII (dec) 42):
 
 byteGPS = gps.read();
   if(byteGPS == 36){
     Serial.println();
     Serial.print("$");
   }
   else
   {      
     inBuffer[i]=byteGPS;
     if (inBuffer[i] > 0){
     Serial.print(inBuffer[i]);
     }      
   }
}


I don't know why..
I don't understand why i switch by itself..

Note: instead of: `§_DISCOURSE_HOISTED_CODE_1_§` that didn't work (never entered in loop "if")
I used `§_DISCOURSE_HOISTED_CODE_2_§`

now I have to understand why..

ps: monitor response:

§DISCOURSE_HOISTED_CODE_3§

PaulS: ``` void loop(){     // waiting sentence from GPS;         byteGPS = 0;     byteGPS = gps.read();

  // reading sentence from GPS:     i = 0;     Serial.print("reading: ");     Serial.print(byteGPS);     inBuffer[i] = byteGPS;



In spite of the comment, the code does not wait for data to be available. 

In spite of the comment, Serial.read() does not read a whole sentence. On any given pass through loop, you are going to read one character, print several, and store it in position 1 of the array.

sorry, i leaved old comments.. there were also refuse lines with duplicated commands.

Note: instead of: that didn't work (never entered in loop "if")

Are you sending the Arduino any serial data? The GPS is, but not via the hardware serial pins.

I used now I have to understand why..

You populated that array with data collected from another source.

Serial.available tells you whether there's anything to read on the hardware serial port. Unless you have the IDE's terminal program (or another) open and are typing stuff to send to the arduino, there will never be anything there. You need to be using gps.available to see if there is anything coming from the gps.

Now I solved my problem and I can leave a correct sketch for anyone will have the same problem.

Goal:
Use Vincotech GPS module with Arduino to send sentences to any GPS control Software.

NOTE: to try the system you can download a simple GPS software interface at this adress: http://homepage2.nifty.com/k8/gps/index.htm

Arduino sketch:

// this code permit to interface arduino with a GPS software
// NOTE: tested only on NMEA Monitor for Windows.
// you can find this free software on internet: http://homepage2.nifty.com/k8/gps/index.htm
// tank you to the owner.


// for any question or contribute about the code:
// Cassandr@email.it


// include the SoftwareSerial library
#include <SoftwareSerial.h>

// Constants
#define rxPin 9      //rx pin in gps connection
#define txPin 8      //tx pin in gps connection

// set up the serial port

SoftwareSerial gps = SoftwareSerial(rxPin, txPin);

// variables
byte byteGPS = 0;
int i = 0;

// Buffers for data input
char GPS[310]="";
char inBuffer[310] = "";


void setup(){

  //setup for mySerial port
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  gps.begin(4800);
  
  //setup for Serial port
  Serial.begin(9600);
  
  delay(1000);
}


void loop(){
  
  // read and write sentence (without any formatting)
  byteGPS = gps.read();
  inBuffer[i]=byteGPS;
  if (inBuffer[i] > 0) {
    Serial.print(inBuffer[i]);
  }
}

next step I’ll try the code on other (and more complex software, like Global Mapper, Oziexplorer, Google Heart…)
for any suggestion leave me a message.

Tank you,
I know that I’m not expert in Arduino programming, any suggestion to learn and increase my capabilities will be very appreciated.