Arduino GPS Clock

I had a Holux M-1000B Bluetooth GPS module that was just gathering dust in my room. I had bought it from DealExtreme back in the days when I had GPS-less (but external GPS capable) Nokia E51. Upgrading to a Nokia E52 has since made this receiver redundant. However, since getting an Arduino, and being put off by the price of GPS shields for them, I decided to use the GPS receiver I already have.

Once the receiver is connected to satellites, the device just spews GPS NMEA V3.01 data at you via Bluetooth SPP or a virtual USB COM port on the PC. Building Arduino projects are a bit like playing with Lego as a child - You spend hours rooting through the big box for one part (only in the case of Arduinos, it's the delivery of parts from electronics suppliers) and when you get it, you can finally finish it. The project sits on your desk for about 1 day to be admired, and then it gets dissembled, never to be rebuild (well, unless it's really good).

Despite opening the board up and finding the appropriate points to probe it was easier just to leave the GPS on the window ledge, and connect it to the PC via bluetooth. I could then pipe the output from the GPS serial port to the Arduino serial port. The settings for the GPS COM port are 38400 baud 8,N,1 if you want to look at what the device is sending out. Because NMEA is an ASCII based protocol, parsing programs are trivial to write. Below is a sample Linux command and some sample NMEA output sentences:

user@host:~$ cat /dev/rfcomm1
$GPRMC,152926,V,6027.8259,N,02225.6713,E,10.8,0.0,190803,5.9,E,S*22
$GPRMB,V,,,,,,,,,,,,A,S*0E
$GPGGA,152926,6027.8259,N,02225.6713,E,8,09,2.0,44.7,M,20.6,M,,*79
$GPGSA,A,3,07,08,09,11,18,23,26,28,29,,,,6.6,2.0,3.0*38
$GPGSV,3,1,09,07,29,138,44,08,22,099,42,09,30,273,44,11,07,057,35*75
$GPGSV,3,2,09,18,28,305,43,23,14,340,39,26,64,222,49,28,60,084,49*7E
$GPGSV,3,3,09,29,52,187,48*4E
$GPGLL,6027.8259,N,02225.6713,E,152926,V,S*48
$GPBOD,,T,,M,,*47
$PGRME,15.0,M,22.5,M,15.0,M*1B
$PGRMZ,147,f,3*19
$GPRTE,1,1,c,*37
$GPRMC,152928,V,6027.8319,N,02225.6713,E,10.8,0.0,190803,5.9,E,S*29 

Once you have verified that the GPS is working, it is time to pipe (redirect) the output from the GPS out to the Arduino. My GPS is connected at /dev/rfcomm1, and my Arduino is connected at /dev/ttyUSB0, so the command to first setup the device at the appropriate baud rate, and then redirect would be this:

stty -F /dev/ttyUSB0 38400
sudo cat /dev/rfcomm1 > /dev/ttyUSB0

Because the device has no configurable parameters, there is no need to transmit to the device. Therefore only a one way redirect is required.

#include <WString.h>                // include the String library
#include <nokia_3310_lcd.h>            //include LCD library

Nokia_3310_lcd lcd=Nokia_3310_lcd();    //instantiate LCD class
char buffer[250];                        //initialise char buffer
boolean DST=false;                        //DST enabled? else UTC

void setup()
{
Serial.begin(38400);                    //initialise serial port
lcd.init();                             //initialise LCD
}

void loop(){
   int ptr =0;
   while(Serial.available() > 0) {      //while there is serial data, read it
     buffer[ptr]=.read();            //store it in the buffer
     Serial.println(buffer[ptr]);
     if(buffer[ptr]=='/n'){                //break on newline
       break;
     }
     ptr++;;
   }

  if(((String) buffer).contains("$GPGGA")){    //cast char array as string to use strsearch
    if(DST){                                   //if DST enabled, do some nifty shufty stuff
      int hour=atoi((char*)(buffer[7],buffer[8]));  //cast hour chars from buffer as char*, and convert to int
      if (hour==23){
        buffer[7]=(char)0;                      //midnight case
        buffer[8]=(char)0;
      }else{
        hour++;                                  //increment hour
        char* hourchar;
        itoa(hour,hourchar,10);                  //convert int to char* 
        buffer[7]=hourchar[1];
        buffer[8]=hourchar[0];
      }
    }
    int j=0;
    (int i=7;i<13;i++){
      lcd.writeCharBig((j++)*12,0,buffer[i],0); //write date to screen.
    }
  }
}

You might notice that the methods in the Nokia_3310_lcd class have changed since my last project. I was planning to rewrite that class myself, but I'm glad I had a google before I did. Thanks to Andy for this updated library. This library is much leaner and more functional than the one supplied by nuelectronics.

This device project will probably exist for roughly 24 hours before being I get bored of it and need the Arduino board for something else. :)

Arduino GPS Clock

One thought on “Arduino GPS Clock

  1. Hehe... you are me and yes I will get bored with it after a day or so also but hey - who cares what it does when you get there... it's the ride that's fun!

    I'm doing this with an EMTAC CRUX II but will take the serial output direct to the Arduino... hopefully!

    Keep having fun!

Leave a Reply