Moderators: adafruit_support_bill, adafruit
// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
//
// This code just echos whatever is coming from the GPS unit to the
// serial monitor, handy for debugging!
//
// Tested and works great with the Adafruit Ultimate GPS module
// using MTK33x9 chipset
// ------> http://www.adafruit.com/products/746
// Pick one up today at the Adafruit electronics shop
// and help support open source hardware & software! -ada
#include <Adafruit_GPS.h>
// these are for Arduino 1.0
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2);
// Connect the GPS Power pin to 5V
// Connect the GPS Ground pin to ground
// Connect the GPS TX (transmit) pin to Digital 3
// Connect the GPS RX (receive) pin to Digital 2
Adafruit_GPS GPS(&mySerial);
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO true
// this keeps track of whether we're using the interrupt
// off by default!
boolean usingInterrupt = false;
void setup()
{
// connect at 115200 so we can read the GPS fast enuf and
// also spit it out
Serial.begin(115200);
Serial.println("Adafruit GPS library basic test!");
// 9600 NMEA is the default baud rate for MTK - some use 4800
GPS.begin(9600);
// You can adjust which sentences to have the module emit, below
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
// uncomment this line to turn on only the "minimum recommended" data for high update rates!
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
// uncomment this line to turn on all the available data - for 9600 baud you'll want 1 Hz rate
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_ALLDATA);
// Set the update rate
// 1 Hz update rate
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
// 5 Hz update rate- for 9600 baud you'll have to set the output to RMC or RMCGGA only (see above)
//GPS.sendCommand(PMTK_SET_NMEA_UPDATE_5HZ);
// 10 Hz update rate - for 9600 baud you'll have to set the output to RMC only (see above)
//GPS.sendCommand(PMTK_SET_NMEA_UPDATE_10HZ);
// the nice thing about this code is you can have a timer0 interrupt go off
// every 1 millisecond, and read data from the GPS for you. that makes the
// loop code a heck of a lot easier!
useInterrupt(true);
delay(1000);
}
// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect) {
char c = GPS.read();
// if you want to debug, this is a good time to do it!
if (GPSECHO)
if (c) UDR0 = c;
// writing direct to UDR0 is much much faster than Serial.print
// but only one character can be written at a time.
}
void useInterrupt(boolean v) {
if (v) {
// Timer0 is already used for millis() - we'll just interrupt somewhere
// in the middle and call the "Compare A" function above
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
usingInterrupt = true;
} else {
// do not call the interrupt function COMPA anymore
TIMSK0 &= ~_BV(OCIE0A);
usingInterrupt = false;
}
}
void loop() // run over and over again
{
// do nothing! all reading and printing is done in the interrupt
}$GPGSA,A,1,,,,,,,,1E
V1,3,,8,,*$RM20,,,,,45,
PV0T0.,.N2$GPGGA,202603.091,,,,,0,0,,,M,,M,,*45
$GPGLL,,,,,202603.091,V,N*77
$GPGSA,A,1,,,,,,,,*E
S1,3,18,,5$RM0.V,,0040,3PV,,,.0.,2$GPGGA,202604.091,,,,,0,0,,,M,,M,,*42
$GPGLL,,,,,202604.091,V,N*70
$GPGSA,A,1,,,,,,,,1E$V0,32,,2,7GRC69,,00145N
PV0T.0,0N2$GPGGA,202605.091,,,,,0,0,,,M,,M,,*43
$GPGLL,,,,,202605.091,V,N*71
$GPGSA,A,1,,,,,,,,,E
G,,3,3,,52
RM25,,,0040,4GPG0M.00K2
$GPGGA,202606.091,,,,,0,0,,,M,,M,,*40
$GPGLL,,,,,202606.091,V,N*72
$GPGSA,A,1,,,,,,,,*E
S,,3,18,,*$RM20,,,,,45,
PV0,0.0.,2$GPGGA,202607.091,,,,,0,0,,,M,,M,,*41
$GPGLL,,,,,202607.091,V,N*73
$GPGSA,A,1,,,,,,,,1E$V,,32,,2,7GRM60,,,0,45,
PV,T0.0.N2$GPGGA,202608.091,,,,,0,0,,,M,,M,,*4E
$GPGLL,,,,,202608.091,V,N*7C
$GPGSA,A,1,,,,,,,,E
$V,,32,,2,7GRC69,,,0145N
PV0,0.,0N2$GPGGA,202609.091,,,,,0,0,,,M,,M,,*4F
$GPGLL,,,,,202609.091,V,N*7D
$GPGSA,A,1,,,,,,,,1E$V,,32,,2,7GRC69,,00145,
PV0T.0,0N2$GPGGA,202610.091,,,,,0,0,,,M,,M,,*47
$GPGLL,,,,,202610.091,V,N*75
$GPGSA,A,1,,,,,,,,*E
S1,3,18,,*$RM20,,,,045,
PV,,,.0.,2$GPGGA,202611.091,,,,,0,0,,,M,,M,,*46
$GPGLL,,,,,202611.091,V,N*74
$GPGSA,A,1,,,,,,,,E
$V,,32,,2,7GRM69,,,0145N
PV0,0.,0N2$GPGGA,202612.091,,,,,0,0,,,M,,M,,*45
$GPGLL,,,,,202612.091,V,N*77
$GPGSA,A,1,,,,,,,,*E
G1,3,32,53
RM0.V,,0040,3PV,0,.0.K2$GPGGA,202613.091,,,,,0,0,,,M,,M,,*44
$GPGLL,,,,,202613.091,V,N*76
$GPGSA,A,1,,,,,,,,1E$S,,3,1,2,*$RM20,,,,,40,
PV0T0.00,2$GPGGA,202614.091,,,,,0,0,,,M,,M,,*43
$GPGLL,,,,,202614.091,V,N*71
$GPGSA,A,1,,,,,,,,*E
S1,3,18,,*$RM20,,,,045,
PV,,,.0.,2$GPGGA,202615.086,,,,,0,0,,,M,,M,,*44
$GPGLL,,,,,202615.086,V,N*76
$GPGSA,A,1,,,,,,
P,3,,,,,3PC18,0015,
P,,,.0.,2
P25.6,,,,4G,,,10V,
S,1,,,,1G,,007,,,,0$G,66,,0.0,1N
$V.,M0N0N2$GPGGA,202616.306,,,,,0,0,,,M,,M,,*4C
$GPGLL,,,,,202616.306,V,N*7E
$GPGSA,A,1,,,,,,,,E
$,,,32,,2,7GRC60,,00141N
PV0,.0N0*2$GPGGA,202617.306,,,,,0,0,,,M,,M,,*4D
$GPGLL,,,,,202617.306,V,N*7F
$GPGSA,A,1,,,,,,,,*E
G1,3,38,51
RM0.V,,0040,BPV,,,.0.K2$GPGGA,202618.306,,,,,0,0,,,M,,M,,*42
$GPGLL,,,,,202618.306,V,N*70
$GPGSA,A,1,,,,,,,,1E
V1,3,18,,*$RM23,,,,,45,
PV,T,.,.N2$GPGGA,202619.306,,,,,0,0,,,M,,M,,*43
$GPGLL,,,,,202619.306,V,N*71
$GPGSA,A,1,,,,,,,,1E$S,,3,1,2,*$RM23,,,,040,5PVG,,.00,2$GPGGA,202620.306,,,,,0,0,,,M,,M,,*49
$GPGLL,,,,,202620.306,V,N*7B
$GPGSA,A,1,,,,,,,,,E
G,,3,32,59
RM0.V,,0040,4PVG0M.00K2$GPGGA,202621.091,,,,,0,0,,,M,,M,,*45
$GPGLL,,,,,202621.091,V,N*77
$GPGSA,A,1,,,,,,,,1E
V1,3,,8,,*$RM20,,,,,45,
PV0T0.0.N2$GPGGA,202622.091,,,,,0,0,,,M,,M,,*46
$GPGLL,,,,,202622.091,V,N*74
$GPGSA,A,1,,,,,,,,1E$V,,32,,2,7GRC69,,0,145N
PV0T0.,0N2$GPGGA,202623.091,,,,,0,0,,,M,,M,,*47
$GPGLL,,,,,202623.091,V,N*75
$GPGSA,A,1,,,,,,,,1E
S1,3,18,,*$RM20,,,,,40,
PV,T,.0.,2$GPGGA,202624.091,,,,,0,void loop() // run over and over again
{
while (mySerial.available()) {
Serial.print((char)mySerial.read());
}
while (Serial.available()) {
mySerial.print((char)Serial.read());
}
}Stephanie wrote:I have a similar setup here, running the Ultimate GPS on a 32u4 at 8MHz. I'm using the interrupt routine and noticed that using only GGA and RMC sentences, I was losing characters. I remedied this with two fixes, while keeping the gps read inside the interrupt routine.
First, I modified the interrupt routine from reading a single byte to using a while-available loop, so it reads all available bytes.
Second, I edited the hardware_serial.cpp file in the Arduino cores and increased the serial buffer by about 50%. Since making those two changes, I have not seen any dropped characters.
Cheers!
// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
//
// This code just echos whatever is coming from the GPS unit to the
// serial monitor, handy for debugging!
//
// Tested and works great with the Adafruit Ultimate GPS module
// using MTK33x9 chipset
// ------> http://www.adafruit.com/products/746
// Pick one up today at the Adafruit electronics shop
// and help support open source hardware & software! -ada
#include <Adafruit_GPS.h>
#if ARDUINO >= 100
#include <SoftwareSerial.h>
#else
// Older Arduino IDE requires NewSoftSerial, download from:
// http://arduiniana.org/libraries/newsoftserial/
#include <NewSoftSerial.h>
// DO NOT install NewSoftSerial if using Arduino 1.0 or later!
#endif
// Connect the GPS Power pin to 5V
// Connect the GPS Ground pin to ground
// If using software serial (sketch example default):
// Connect the GPS TX (transmit) pin to Digital 3
// Connect the GPS RX (receive) pin to Digital 2
// If using hardware serial (e.g. Arduino Mega):
// Connect the GPS TX (transmit) pin to Arduino RX1, RX2 or RX3
// Connect the GPS RX (receive) pin to matching TX1, TX2 or TX3
// If using software serial, keep these lines enabled
// (you can change the pin numbers to match your wiring):
#if ARDUINO >= 100
SoftwareSerial mySerial(3, 2);
#else
NewSoftSerial mySerial(3, 2);
#endif
Adafruit_GPS GPS(&mySerial);
// If using hardware serial (e.g. Arduino Mega), comment
// out the above six lines and enable this line instead:
//Adafruit_GPS GPS(&Serial1);
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO true
// this keeps track of whether we're using the interrupt
// off by default!
boolean usingInterrupt = false;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
void setup()
{
// connect at 115200 so we can read the GPS fast enuf and
// also spit it out
Serial.begin(115200);
Serial.println("Adafruit GPS library basic test!");
// 9600 NMEA is the default baud rate for MTK - some use 4800
GPS.begin(9600);
// You can adjust which sentences to have the module emit, below
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
// GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
// uncomment this line to turn on only the "minimum recommended" data for high update rates!
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
// uncomment this line to turn on all the available data - for 9600 baud you'll want 1 Hz rate
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_ALLDATA);
// Set the update rate
// 1 Hz update rate
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
// 5 Hz update rate- for 9600 baud you'll have to set the output to RMC or RMCGGA only (see above)
// GPS.sendCommand(PMTK_SET_NMEA_UPDATE_5HZ);
// 10 Hz update rate - for 9600 baud you'll have to set the output to RMC only (see above)
//GPS.sendCommand(PMTK_SET_NMEA_UPDATE_10HZ);
// the nice thing about this code is you can have a timer0 interrupt go off
// every 1 millisecond, and read data from the GPS for you. that makes the
// loop code a heck of a lot easier!
useInterrupt(false);
delay(1000);
}
// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect) {
char c = GPS.read();
// if you want to debug, this is a good time to do it!
if (GPSECHO)
if (c) UDR0 = c;
// writing direct to UDR0 is much much faster than Serial.print
// but only one character can be written at a time.
}
void useInterrupt(boolean v) {
if (v) {
// Timer0 is already used for millis() - we'll just interrupt somewhere
// in the middle and call the "Compare A" function above
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
usingInterrupt = true;
} else {
// do not call the interrupt function COMPA anymore
TIMSK0 &= ~_BV(OCIE0A);
usingInterrupt = false;
}
}
void loop() // run over and over again
{
// do nothing! all reading and printing is done in the interrupt
if (mySerial.available()) {
Serial.print((char)mySerial.read());
}
if (Serial.available()) {
mySerial.print((char)Serial.read());
}
}SIGNAL(TIMER0_COMPA_vect) {
while(mySerial.available()) {
char c = GPS.read();
// if you want to debug, this is a good time to do it!
if (GPSECHO)
if (c) UDR0 = c;
// writing direct to UDR0 is much much faster than Serial.print
// but only one character can be written at a time.
}
}#if (RAMEND < 1000)
#define SERIAL_BUFFER_SIZE 24
#else
#define SERIAL_BUFFER_SIZE 96
#endif // if buffer full, set the overflow flag and return
if ((_receive_buffer_tail + 1) % _SS_MAX_RX_BUFF != _receive_buffer_head)
{
// save new data in buffer: tail points to where byte goes
_receive_buffer[_receive_buffer_tail] = d; // save new byte
_receive_buffer_tail = (_receive_buffer_tail + 1) % _SS_MAX_RX_BUFF;
} _receive_buffer_tail = (_receive_buffer_tail + 1) & (_SS_MAX_RX_BUFF-1);Return to Other Adafruit products
Users browsing this forum: theserge and 4 guests