Send GPS data over Bluetooth

I am having some difficulties sending Long, Lat, and other data via Bluetooth.

Hardware used:
GPS Shield (Software Serial pins(2,3))
Bluetooth Mate Silver (UART pins(0,1))
Arduino UNO R2

Few things I have done already:
I have used AT command to set the baud rate to 4800 (same as GPS) and also I have set it to 9600, and 115200 none of these settings work. I have also tried to set the BT Module to a slave or master. The only data that is displayed is:

CHARS=0 SENTENCES=0 CSUM ERR=0
CHARS=0 SENTENCES=0 CSUM ERR=0
CHARS=0 SENTENCES=0 CSUM ERR=0

Here is my Sketch:

#include <SoftwareSerial.h>

#include <TinyGPS.h>

/* This sample code demonstrates the normal use of a TinyGPS object.
   It requires the use of SoftwareSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 3(rx) and 4(tx).
*/

TinyGPS gps;
SoftwareSerial ss(2, 3);

void setup()
{
  Serial.begin(4800);
  ss.begin(4800);
  
  Serial.print("Simple TinyGPS library v. "); Serial.println(TinyGPS::library_version());
  Serial.println("by Mikal Hart");
  Serial.println();
}

void loop()
{
  bool newData = false;
  unsigned long chars;
  unsigned short sentences, failed;

  // For one second we parse GPS data and report some key values
  for (unsigned long start = millis(); millis() - start < 1000;)
  {
    while (ss.available())
    {
      char c = ss.read();
      // Serial.write(c); // uncomment this line if you want to see the GPS data flowing
      if (gps.encode(c)) // Did a new valid sentence come in?
        newData = true;
    }
  }

  if (newData)
  {
    float flat, flon;
    unsigned long age;
    gps.f_get_position(&flat, &flon, &age);
    Serial.print("LAT=");
    Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
    Serial.print(" LON=");
    Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
    Serial.print(" SAT=");
    Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
    Serial.print(" PREC=");
    Serial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
  }
  
  gps.stats(&chars, &sentences, &failed);
  Serial.print(" CHARS=");
  Serial.print(chars);
  Serial.print(" SENTENCES=");
  Serial.print(sentences);
  Serial.print(" CSUM ERR=");
  Serial.println(failed);
}

I am guessing the reason it is not receiving the data is due to the baud rate but I have been unable to get it to work.

Any help would be greatly appreciated.

Thanks

That you are getting that readout says that your hardware serial and blueooth link is working, but it appears that your software serial is not.

Even at incorrect baud rates, you would still trigger this part:

    while (ss.available())
    {
      char c = ss.read();
      // Serial.write(c); // uncomment this line if you want to see the GPS data flowing
      if (gps.encode(c)) // Did a new valid sentence come in?
        newData = true;
    }

So, to see if it is even working at all, uncomment that line Serial.write(c) and you should be seeing it spit out the raw data being read from the GPS (even if it is garbage.)

Hey Retroplayer,

I forgot to add I did check to see if that commented Serial.write(c) was sending any data to the serial monitor and it does not send any data I see the same data I was seeing before:

CHARS=0 SENTENCES=0 CSUM ERR=0
CHARS=0 SENTENCES=0 CSUM ERR=0
CHARS=0 SENTENCES=0 CSUM ERR=0

It is def. my software serial that is having the issue. I have tried just using the GPS (software serial) and Arduino (UART) without the BT and this code works fine, but as soon as I add the BT I don't get the GPS data.

htimmis:
It is def. my software serial that is having the issue. I have tried just using the GPS (software serial) and Arduino (UART) without the BT and this code works fine, but as soon as I add the BT I don't get the GPS data.

Those two statements don't quite mesh. The bluetooth is using the hardware serial (the same one you are checking without it) the GPS is on the software serial. As it is right now, you are not having problems with the hardware serial OR the bluetooth link or you would not be getting anything at all.

Are you sure something else didn't change between your test with the UART and with the Bluetooth?

The only way I can see it interferring is that the GPS and blueooth are both operating on 2.4GHz. But I would expect that you would still get values from the GPS, but they would just be a bunch of errors telling you that it couldn't sync with a satellite.

I would go back and retry (without changing anything else) the normal UART. I think something has changed and I expect that it won't work that way either now.

ok the configuration has been the same GPS is using the software serial, and the bluetooth is using the hardware serial the BT is set to 4800 and the GPS is set to 4800

when I am using just the Arduino's UART and the GPS (soft serial) everything works fine

when I use the BT connected to the Arduino's HW Serial and the GPS connected to the soft serial I receive no GPS data

I don't know what I am missing, but it is probably something simple that I am over looking, but as far as the configuration that is it.

When I just use the Arduino and GPS with the same sketch I get the correct data:

LAT=28.283180 LON=-81.335876 SAT=9 PREC=100 CHARS=3094 SENTENCES=25 CSUM ERR=1
$GPGGA,222615.000,2816.9914,N,08120.1534,W,1,09,1.0,15.0,M,-30.8,M,,000054
$GPGSA,A,3,23,13,03,07,16,06,19,20,31,,,,1.5,1.0,1.1
39
$GPRMC,222615.000,A,2816.9914,N,08120.1534,W,0.71,275.05,130413,,16
LAT=28.283189 LON=-81.335891 SAT=9 PREC=100 CHARS=3298 SENTENCES=27 CSUM ERR=1
$GPGGA,222616.000,2816.9913,N,08120.1534,W,1,08,1.2,15.3,M,-30.8,M,,0000
50
$GPGSA,A,3,23,13,03,07,16,06,19,20,,,,,2.1,1.2,1.738
$GPRMC,222616.000,A,2816.9913,N,08120.1534,W,0.18,235.43,130413,,1B
$GPGGA,22LAT=28.283180 LON=-81.335891 SAT=8 PREC=120 CHARS=3509 SENTENCES=29 CSUM ERR=1
2617.000,2816.9910,N,08120.1530,W,1,07,1.6,15.8,M,-30.8,M,,0000
56
$GPGSA,A,3,23,13,03,07,06,19,20,,,,,,2.5,1.6,1.9
31
$GPGSV,3,1,12,23,73,250,40,03,72,114,37,06,56,070,30,13,56,309,2474
$GPGSV,3,2,12,19,52,159,32,16,42,030,08,07,17,307,19,20,10,214,19
73
$GPGSV,3,3,12,31,08,102,,32,06,191,,11,07,177,,10,03,303,*79
$GPRMC,222617.000,A,2816.9910,N,08120.1530,W,0.33,204.32,130413,,10
$GPGGA,222618.000,2816.9908,N,08120.1524,W,1,07,1.6,16.3,M,-30.8,M,,0000
5D

So the UART seems to be working.

Then I am just as stumped as you. There is nothing inherently odd about the connection to the bluetooth, and indeed that part is working. It can't be that connecting the bluetooth messes with timing because then the hardware UART without bluetooth wouldn't work either.

The only thing I am left with assuming is that the interference from the bluetooth is preventing the GPS module from working. Or possibly there isn't enough power for both?

Are you powering both modules off the arduino supply? Are grounds all connected together?

All grounds are connected to one another. I am power both devices with the Arduino. Yeah I know this problem is a pain.

Try this:

Connect the bluetooth module power and the GPS up, but don't connect the bluetooth to tx and rx. Use the USB UART to test and see if it works that way. If not, the problem is probably power related.

ps. It's not causing me any pain. :wink: Just you. lol

Using the USB UART, and GPS Software Serial, Power is connected to the Bluetooth nothing else.

Yeah I tried that and I get the correct GPS data.

LAT=28.283199 LON=-81.335830 SAT=8 PREC=110 CHARS=210 SENTENCES=2 CSUM ERR=1
LAT=28.283199 LON=-81.335830 SAT=8 PREC=110 CHARS=682 SENTENCES=4 CSUM ERR=1
LAT=28.283199 LON=-81.335830 SAT=8 PREC=110 CHARS=1022 SENTENCES=8 CSUM ERR=1

So I am guessing something else is going on.

Well I went ahead and switch my shields around I put the BT on top of the GPS and guess what it now works...

Weird. Must have been something with the RF pattern. Shrug Glad you got it working.

Hi, Htimmis and Retroplayer.

Sorry for my english as i am Spaniard.

I am doing almost the same project as you do, and i have a doubt with your code:


/* This sample code demonstrates the normal use of a TinyGPS object.
It requires the use of SoftwareSerial, and assumes that you have a
4800-baud serial GPS device hooked up on pins 3(rx) and 4(tx).
*/

TinyGPS gps;
SoftwareSerial ss(2, 3);


U say that u have your gps hoocked on pins 3 and 4, but the code says (2,3) is that correct?

On the other hand my gps is hoocked on pins 8,9, and want to send the data over the bluetooth on pins 0,1.

Here my code:


// 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 inBuffer[300] = "";
char GPS_RMC[100]="";
char GPS_GGA[100]="";

void setup(){

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

void loop(){
  
  // Read the RMC sentence from GPS
  byteGPS = 0;
  byteGPS = gps.read();
  while(byteGPS != 'R'){
    byteGPS = gps.read();
  }
  GPS_RMC[0]='

I recive the data correctly via USB on port 18, but wanted to receive it via bluetooth.
What changes should i do?

Change line Serial.print to SerialWrite ?

Thanks a lot for your time.
;
  GPS_RMC[1]='G';
  GPS_RMC[2]='P';   
  GPS_RMC[3]='R';
 
    i = 4;
    while(byteGPS != '*'){                 
      byteGPS = gps.read();       
      inBuffer[i]=byteGPS;
      GPS_RMC[i]=byteGPS;
      i++;                     
  }
 
  // Read GGA sentence from GPS
  byteGPS = 0;
  byteGPS = gps.read();
  while(byteGPS != 'A'){
    byteGPS = gps.read();
  }
  GPS_GGA[0]='


___________________________________________________________________

I recive the data correctly via USB on port 18, but wanted to receive it via bluetooth.
What changes should i do?

Change line Serial.print to SerialWrite ?

Thanks a lot for your time.
;
  GPS_GGA[1]='G';
  GPS_GGA[2]='P';    
  GPS_GGA[3]='G';
  GPS_GGA[4]='G';
  GPS_GGA[5]='A';
  
    i = 6;
    while(byteGPS != '*'){                  
      byteGPS = gps.read();         
      inBuffer[i]=byteGPS;
      GPS_GGA[i]=byteGPS;
      i++;                      
  }
    
  // print the GGA sentence to USB
  Serial.print("GGA sentence: ");
  h = 0;
  while(GPS_GGA[h] != 42){
    Serial.print(GPS_GGA[h],BYTE);
    h++;
  }
  Serial.println();
  
  // print the RMC sentence to USB
  Serial.print("RMC sentence: ");
  h = 0;
  while(GPS_RMC[h] != 42){
    Serial.print(GPS_RMC[h],BYTE);
    h++;
  }
  Serial.println();
}

I recive the data correctly via USB on port 18, but wanted to receive it via bluetooth.
What changes should i do?

Change line Serial.print to SerialWrite ?

Thanks a lot for your time.

    while(byteGPS != '*'){                  
      byteGPS = gps.read();         
      inBuffer[i]=byteGPS;
      GPS_RMC[i]=byteGPS;
      i++;                      
  }

This assumes that GPS data arrives all at once. That is no where near a valid assumption. Stop making it. There is a available() method that you must use.

thx a lot.

sir the code is not running