i have a simple programm which should read the NMEA sentence and simply write it to a micro SD card.
Since the gps is updated with 1Hz i want to put the Arduino to sleep in the meantime. I use the WDT to wake up the Arduio after 1s and this works fine.
Problem:
after the wake up i do not get gps.newNMEAreceived().
I am new to the Arduini world and maybe its a stupid question but i got stucke here.
My Hardware:
+ Arduino Uno R3
+ Adafruit Ultimate GPS Logger Shield
My Shield:
Code: Select all
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include <SD.h>
//--------------------------------------------------------------------------------------------------
// global
//--------------------------------------------------------------------------------------------------
SoftwareSerial softwareSerial(8, 7);
Adafruit_GPS gps(&softwareSerial);
File logfile;
//--------------------------------------------------------------------------------------------------
// setup
//--------------------------------------------------------------------------------------------------
void setup()
{
Serial.begin(115200);
pinMode(13, OUTPUT);
pinMode(10, OUTPUT);
// -> SD card initialization.
if (0 != SD.begin(10))
{
char filename[15];
strcpy(filename, "GPSLOG00.TXT");
for (uint8_t i = 0; i < 100; i++)
{
filename[6] = '0' + i / 10;
filename[7] = '0' + i % 10;
if (0 == SD.exists(filename)) break;
}
if (0 != (logfile = SD.open(filename, FILE_WRITE)))
{
Serial.print("writing to file: ");
Serial.println(filename);
}
else
{
Serial.print("could not open file: ");
Serial.println(filename);
}
}
else
{
Serial.println("SD card initialization failed.");
}
// <-
// -> GPS initialization
gps.begin(9600);
gps.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
gps.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
gps.sendCommand(PGCMD_NOANTENNA);
// <-
// -> watch dog timer
MCUSR &= ~(1<<WDRF); /* Clear the reset flag. */
WDTCSR |= (1<<WDCE) | (1<<WDE);
WDTCSR = 1<<WDP1 | 1<<WDP2 | 0<<WDP3; /* 1.0 seconds */
WDTCSR |= _BV(WDIE);
// <-
Serial.println("setup done.");
delay(5);
}
//--------------------------------------------------------------------------------------------------
// loop
//--------------------------------------------------------------------------------------------------
void loop()
{
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
/* Now enter sleep mode. */
sleep_mode();
/* The program will continue from here after the WDT timeout*/
sleep_disable(); /* First thing to do is disable sleep. */
/* Re-enable the peripherals. */
power_all_enable();
Serial.println("wake up.");
delay(5);
gps.read();
if (0 != gps.newNMEAreceived())
{
if (0 != gps.parse(gps.lastNMEA()))
{
if (0 != gps.fix)
{
const char* pcSentence = gps.lastNMEA();
const uint8_t uiSentenceSize = strlen(pcSentence);
logfile.write((uint8_t *)pcSentence, uiSentenceSize);
logfile.flush();
Serial.println("flush.");
delay(5);
}
}
}
}
//--------------------------------------------------------------------------------------------------
// watch dog timer interrupt
//--------------------------------------------------------------------------------------------------
ISR(WDT_vect)
{
}