Hi I am working on a project that includes a Teensy 3.2 and GPS unit as part of a LIPO battery powered project. There are other components but they don't have an impact on my problem.
To save power I am using the excellent Snooze library and waking using a digital input button.
The GPS unit works fine when not using the Snooze function.
My problem is,when I try and use Snooze the Teensy goes to sleep fine but on waking I can't read the current GPS location...it appears to be serial printing the location at the time the Teensy went to sleep and not the one upon waking up. I will be using the latitude and longitude values after waking up to make various distance calculations to multiple known coordinates from whatever the current location is. I am hoping there is a simple answer..hope someone can assist me.
I have attached the code which I have tried to modify...it works to a fashion but does give the required current location.
To save power I am using the excellent Snooze library and waking using a digital input button.
The GPS unit works fine when not using the Snooze function.
My problem is,when I try and use Snooze the Teensy goes to sleep fine but on waking I can't read the current GPS location...it appears to be serial printing the location at the time the Teensy went to sleep and not the one upon waking up. I will be using the latitude and longitude values after waking up to make various distance calculations to multiple known coordinates from whatever the current location is. I am hoping there is a simple answer..hope someone can assist me.
I have attached the code which I have tried to modify...it works to a fashion but does give the required current location.
Code:
#include <Snooze.h>//teensy snooze library
//load snooze drivers
SnoozeDigital digital;
SnoozeUSBSerial usb;
//install drivers to SnoozeBlock
SnoozeBlock config(digital);
#include <TinyGPS++.h>
/* This sample code demonstrates the normal use of a TinyGPSPlus object. */
TinyGPSPlus gps;
/* On Teensy, the UART (real serial port) is always best to use. */
/* Unlike Arduino, there's no need to use NewSoftSerial because */
/* the "Serial" object uses the USB port, leaving the UART free. */
HardwareSerial Uart = HardwareSerial();
//void gpsdump(TinyGPSPlus &gps);
//void printFloat(double f, int digits = 2);
const int findholeWake = 16; //pin 16 connected to a button which is held high..low when pressed
void setup()
{
Serial.begin(115200);
Uart.begin(9600);
delay(1000);
Serial.println("by Mikal Hart");
Serial.println();
Serial.print("Sizeof(gpsobject) = "); Serial.println(sizeof(TinyGPSPlus));
Serial.println();
//pin, mode, type
digital.pinMode(findholeWake, INPUT_PULLUP, FALLING);
}
// end of set up
void loop()
{
bool newdata = false;
unsigned long start = millis();
// Every 5 seconds we print an update
while (millis() - start <350) {
if (Uart.available()) {
char c = Uart.read();
//Serial.print(c); // uncomment to see raw GPS data
if (gps.encode(c)) {
newdata = true;
// break; // uncomment to print new data immediately!
}
}
}
if (newdata) {
int who;
//go to sleep and wake up using digital pin 16
who = Snooze.deepSleep(config);
// following code will allow serial mointor to work when button/timer wakes Teensy
elapsedMillis time = 0;
while (!Serial && time < 1000) {
Serial.write(0x00);// print out a bunch of NULLS to serial monitor
digitalWriteFast(LED_BUILTIN, HIGH);
delay(30);
digitalWriteFast(LED_BUILTIN, LOW);
delay(30);
}
// normal delay for Arduino Serial Monitor
delay(500);//200...500 seems to work back to front
// print who woke the teensy up, i.e. timer || digital
Serial.print("Timer Driver number indicator: ");
Serial.println(who);
//delay(200);
if (who == 16) {// pin wakeup source is its pin value
// following code will allow serial mointor to work when button/timer wakes Teensy
delay(400);
Serial.println(gps.time.minute());
Serial.println("Acquired Data");
Serial.println("-------------");
//gpsdump(gps);
Serial.println(gps.location.lat(),6);
Serial.println(gps.location.lng(),6);
Serial.println("-------------");
Serial.println();
}
}
}