Tuesday, 8 October 2013

Little Victories :)

Awhile ago I got an Adafruit ultimate GPS module that runs at 10Hz with all the goodies. Awesome! but what now? Her sample sketchs were... Complicated.... And I am, well, not the best programmer, to put it lightly. I loaded up the echo sketch, ran it at 10Hz, and it went fine :) tried the parsing sketch, fine, parsing sketch at 10Hz, not so fine. That and I didn't understand what the heck was going on. Fast forward a bit and I find that arduino 1.0.5 has a CSV parsing function built in. Awesome! sit down and figure this should be pretty easy to implement. Nope. Struggled for 2.5 hours without sucess, and then finally, I UNDERSTOOD! I had to wait till the serial buffer was almost full, if (GPS.available() > 62) not just greater than 0, and I figured out that GPS.find("$GPRMC"); The GPRMC had to be in quotes for it to work. So now I have a sketch that just needs to parse the CSV's into some floats, and I'm golden :) Here is the whole sketch as it stands. It brings the CSV strings from the GPS in over softwareserial, parses them, and sends them out over serial to my laptop running the serial moniter. It refreshes every 15 seconds right now, because I am going to glean some real life data as I walk to school today, and perhaps post that later. Right now the GPS is spitting out at 1Hz, 9600 baud, it's default setting, but this SHOULD work with heavier duty speeds too. It uses the same softwareserial pins as in the adafruit tutorial, and spits it back out over the USB port. If anyone actually reads this, feel free to use however you wish, it should just copy and paste into arduino and compile correctly. It does in arduino 1.0.5.

#include <SoftwareSerial.h>
SoftwareSerial GPS(3, 2);

void setup() 

void loop()
  if (GPS.available() > 62)
    float tim = GPS.parseFloat();
    float lat = GPS.parseFloat();
    float lon = GPS.parseFloat();
    float spd = GPS.parseFloat();
    float hdg = GPS.parseFloat();
    Serial.print("Time: ");
    Serial.print(tim, DEC);
    Serial.print(" Lat: ");
    Serial.print(lat, DEC);
    Serial.print(" Long: ");
    Serial.print(lon, DEC);
    Serial.print(" Speed: ");
    Serial.print(spd, DEC);
    Serial.print(" Heading: ");
    Serial.println(hdg, DEC);

No comments:

Post a Comment