Interfacing BlueNext GPS with arduino issues

I took apart my BlueNext BN909GR GPS and noticed it had serial contacts for the GPS, I connected these up but using example code from libelium and changing the baud rate to suit my GPS it kind of works…

Here is my code:

/*

  *  Copyright (C) 2008 Libelium Comunicaciones Distribuidas S.L.
  *  http://www.libelium.com

  *

  *  This program is free software: you can redistribute it and/or modify

  *  it under the terms of the GNU General Public License as published by

  *  the Free Software Foundation, either version 3 of the License, or

  *  (at your option) any later version.

  * 

  *  This program is distributed in the hope that it will be useful,

  *  but WITHOUT ANY WARRANTY; without even the implied warranty of

  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

  *  GNU General Public License for more details.

  * 

  *  You should have received a copy of the GNU General Public License

  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.

  *

  *  Version 0.1

  *  Author: Marcos Yarza <m.yarza [at] libelium [dot] com>

  */



// include the SoftwareSerial library

#include <SoftwareSerial.h>



// Constants

#define rxPin 9

#define txPin 8



// set up the serial port



SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);



// variables

byte byteGPS = 0;

int i = 0;

int indices[13];

int cont = 0;

int conta = 0;



char inBuffer[300] = "";



int k = 0;



void setup(){



  //setup for mySerial port

  pinMode(rxPin, INPUT);

  pinMode(txPin, OUTPUT);

  mySerial.begin(9600);

  

  //setup for Serial port

  Serial.begin(115200);



  // setup the GPS module

  Serial.println("Configuring GPS...");

  delay(1000);

  mySerial.println("$PSTMNMEACONFIG,0,4800,1,1");        // configure NMEA sentences to show only GGA                                                                                                                                                                                                                                 

                                                                                           

  delay(100);

  

  // command for setting time and position

  mySerial.println("$PSTMINITGPS,4140.000,N,00053.000,W,0197,22,10,2007,11,40,00");    



  // "4140.000,N" means: Latitude 41º40'00.0" North

  // "00053.000,W" means: Longitude 0º53'00.0" West

  // "0197" means 197 m elevation

  // "22,10,2007,11,40,00" means date and time (October 22, 2.007 - 11h 40min 00sec UTC time)

}



void loop(){

 

  byteGPS = 0;

  i = 0;

  while(byteGPS != 42){                   // read the GGA sentence

    byteGPS = mySerial.read();         

    inBuffer[i]=byteGPS;               

    i++;                      

  }

   

  k = 1;

  while(inBuffer[k] != 42){

    Serial.print(inBuffer[k]);            // write the GGA sentence

     k++;

  }

  Serial.println();

  delay(1000);

}

But this is what I get out of it:

Configuring GPS…
GPGGA,120755.000,5412.2538,N,00138.7660,W,1,06,1.4,61.4,M,47.7,M,0000
;? c?Íi?Y3&kÍ?,28,21,08,24,3.0,1®4,2.7
$GPRMC,1²0757.000,A,5412.2538,N,00138.7660,W,0®00,130609,A
$GPGGA,120759.000,5412.2538,N,00138.7660,W,1,06,1.4,61.4¬M,47.7,M,0000
?Æ&vÆ&?Æ&?Æ??Æ&FÆÆÆÆÆÆÆ6æ?Æ?æFÆ&æv¦6¦ÖL?Ò4ê´j5Ù3Y3Y³&cÌ?,60,068,35,10,56,191,42,28,38,128,34,24,25,266,16
GPGGA,120802.0°0,5412.2538,N,00138.7660,W,1,06,1.4,61.4,M,47.7,M,0000
Z4eÐ?³,10,27,28,21,08,24,3.0,1.4,2.7

$GPRMC,120804.000,A,5412.2538,N,00138.7660,W,0.00,130609,A
­??²4j´j5Ù3?3Y³&kÌ?,21,058,22,21,1¹,310,22,15,18,317,27,15,232,31
GPGGA,120807.000,5412.2538,N,00138.7660,W,1,06,1.4,61.4,M,47.7,M,0000
´jÐÖ¡,3,10,27,28,21,08,24,¬,3.1,1.4,2.7
RFì?5jShKÌ?°809.000,A,5412.2538,N,001³8.7660,W,0.00,130609,A
´??²4ê´j5Ù3?3Y³&cÌ?,21,058¬23,21,19,310,22,15,18,317,27,15,232,30
GPGGA,120812.000,5412.2538,N,00138.7660,W,1,06,1.4,61.4,M,47.7,M,0000
GPGSA,A,3,10,27,28,2±,08,24,3.1,1.4,2.7
Ì?ò4jjShKÌ?°814.000,A,5412.2538,N,00138.7660,W,0.00,130609,A

(Positions have been changed to not show people where I live…)

As you can see, it messes up the received data and I’m not sure why. Obviously the GPS is different to the one this code was intended for so things have to be changed but what have I missed? There is also a bs pin on my GPS which I have not connected up - should I have? What does it do?

Mowcius

I would start with just outputting the character from the GPS directly to the serial:

  char c;
  if (mySerial.available()) {
    c = mySerial.read();
    Serial.print(c, BYTE);
  }

If you aren't sure that the commands for the GPS settings are correct, then I'd leave them out. The GPS should send some data by default without any setup.

You may have already done this, but you might try changing the baud on the softserial and see what that gets you. I'd try 4800 just to see, since you are sending a "4800" command in the config string.

One other note: in the "read" portion of the loop, you are adding to the buffer array starting from position 0 (variable i) and in the "write" portion of the loop you are writing from position 1 (variable k).

Hope this helps some Rob

Ok, I didn't realise that I was sending 4800 command, I hadn't noticed that...

The GPS is 9600 so I will change the command I am sending and try just getting data from the GPS directly later today.

Thanks for the idea...

Mowcius

Ok, I tried it with just sending receiving the data and not sending anything and everything came through fine.

I then just removed the send command and it made no difference so I presume it is something to do with this bit:

void loop(){

byteGPS = 0;

i = 0;

while(byteGPS != 42){ // read the GGA sentence

byteGPS = mySerial.read();

inBuffer*=byteGPS;* * i++;* * }* * k = 1;* * while(inBuffer[k] != 42){* * Serial.print(inBuffer[k]); // write the GGA sentence* * k++;* * }* * Serial.println();* * delay(1000);* } [/quote] Anyway at least I know it works now, Thanks for the help, Mowcius

The code that is outputted from the GPS includes everything under the sun from amount of satellites to the position. I would like to receive both of these but just as numbers and not with all the GPRMC bla bla bla...

I would like to send the data to an lcd display and possibly store it on a microsd card as a csv document but I don't know what to send to the GPS... Is there any way I can just isolate it when it comes to the arduino...

Anyone understand me/got any ideas

Mowcius

The output is in the NMEA Sentence format, which is pretty much the standard. You can read more about them here Welcome gpsinformation.org - Hostmonster.com

If you can find the documentation on the GPS model, you can send a config string to it and turn off some of the data, but you are still going to get a single NMEA sentence at a minimum.

Ladyada’s test parsing sketch here GPS datalogging shield for Arduino takes that sentence and converts it into more readable data.

The TinyGPS TinyGPS | Arduiniana library also returns more readable data from a NMEA Sentence.

I have code to parse two of the sentences (GGA and RMC) and and write to the LCD, but I won’t be able to post it till later tonight. For the most part I reworked code from the parsing sketch I linked above.

Ok, if you could post your lcd code it would be a great help... I have just got the 20x4 serial display from sparkfun...

I am having a look through that code and when I get time I will have a go at modifying the tinygps software...

Mowcius

I have added a sample app that reads the gps, parses the sentence, and displays on the LCD. The code is too large to paste into a post, so I have zipped it up here: http://www.hiredgunsoftware.net/wp/download/gps_example.zip

I have a 2*16 lcd, but changed the code to display on 4 lines. You'll have to add your lcd pins, setup the serial, etc, but you should be able to get up and running easily.

Most of the code has been put together from samples, so may not be optimal yet, but it should work. Also note that it doesn't use the TinyGPS library.