Intel® Makers
Intel® Edison, Intel® Joule™, Intel® Curie™, Intel® Galileo
Announcements
Welcome - This is a Peer-to-Peer Forum only. Intel has discontinued these products but you may find support from other customers on this Forum
9882 Discussions

Grove GPS via Arduino IDE

idata
Community Manager
1,066 Views

(Message updated with TinyGPS)

I connected my GPS module (SIM28) to the UART port on the Grove only to find that SoftwareSerial doesn't work in the Arduino IDE. Looking around, I found discussions that either led on a wild goose chase or provided lengthy references to wade in.

So for sharing, you will find below my basic Grove GPS sketch that works well with TinyGPS - you can get the TinyGps files from https://github.com/mikalhart/TinyGPS here. Download them and place Tinygps.cpp and Tinygps.h in the same folder as this sketch. (The sketch is based off simple_test.ino found in the Github repo). The most important lines that gets this working on the Intel Edison is found on lines 3, 4, 9, 10, 22, and 23; the rest of the code is similar.

If you want to find out more about RingBuffer and TTYUARTClass, head over to this folder on your computer -

"\AppData\Local\Arduino15\packages\Intel\hardware\i686\1.6.7+1.0\cores\arduino" and look up Ringbuffer.cpp and TTYUART.cpp

# include "TinyGPS.h"

RingBuffer rx_buffer_GPS;

TTYUARTClass SerialGPS(&rx_buffer_GPS, 1, false);

TinyGPS gps;

void setup() {

SerialGPS.init_tty("/dev/ttyMFD1");

SerialGPS.begin(9600);

Serial.begin(9600);

Serial.println("Begin!");

}

void loop() {

bool newData = false;

unsigned long chars;

unsigned short sentences, failed;

for (unsigned long start = millis(); millis() - start < 1000;)

{

while (SerialGPS.available())

{

char c = SerialGPS.read();

//Serial.write(c); // uncomment this line if you want to see the GPS data flowing

if (gps.encode(c))

newData = true;

}

}

if (newData)

{

float flat, flon;

unsigned long age;

gps.f_get_position(&flat, &flon, &age);

Serial.println();

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.println(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);

if (chars == 0)

Serial.println("** No characters received from GPS: check wiring **");

}

And here is the sample output observed while outdoors:

$GPGGA,015116.000,0122.6789,N,10351.3328,E,1,4,16.26,131.8,M,4.0,M,,*5B

$GPGSA,A,3,26,03,16,22,,,,,,,,,22.12,16.26,15.00*36

$GPGSV,4,1,13,16,65,313,11,27,48,168,14,26,46,003,10,22,44,282,11*74

$GPGSV,4,2,13,14,43,092,12,32,40,106,,03,25,303,14,08,24,197,14*70

$GPGSV,4,3,13,31,17,031,12,10,14,155,,11,05,224,,01,05,242,13*7F

$GPGSV,,1,4$M1600.91128,,506,6

LAT=1.377982 LON=103.855545 SAT=4 PREC=1626

CHARS=15718 SENTENCES=44 CSUM ERR=17

Hope this helps someone.

Rgds,

Gavin

0 Kudos
0 Replies
Reply