Hi all,
newbie here. I'm making a data log for my bike.
For now I'm dealing with GPS via serial with a Teensy 3.2.
I'm using 2 IntervalTimers, one to read the GPS string and one to get the GPS status.
Below is my code. It's a total work in progress but it's functional.
As you can see the GPS read runs every 0.1 seconds while the timer to get the GPS status runs every 5 seconds.
The problem I'm having is that every time the getGPSstatus timer gets triggered the readGPS timer gets interrupted. I tried to set different priorities but nothing changes.
Basically, every 5 seconds I get a partial GPS NMEA string since (I assume) readGPS get's interrupted.
Do you have any suggestion on what I'm doing wrong?
Thank you in advance,
Guido
newbie here. I'm making a data log for my bike.
For now I'm dealing with GPS via serial with a Teensy 3.2.
I'm using 2 IntervalTimers, one to read the GPS string and one to get the GPS status.
Below is my code. It's a total work in progress but it's functional.
As you can see the GPS read runs every 0.1 seconds while the timer to get the GPS status runs every 5 seconds.
The problem I'm having is that every time the getGPSstatus timer gets triggered the readGPS timer gets interrupted. I tried to set different priorities but nothing changes.
Basically, every 5 seconds I get a partial GPS NMEA string since (I assume) readGPS get's interrupted.
Do you have any suggestion on what I'm doing wrong?
Thank you in advance,
Guido
Code:
#include <Wire.h>
// Communications
#define GPSserial Serial1
#define I2C_0 Wire
#define I2C_1 Wire1
// Timer objects
IntervalTimer readGPStimer;
IntervalTimer getGPSstatusTimer;
IntervalTimer readVoltSensors;
IntervalTimer logDataToSD;
// Settings
#define ReadVinFromI2Cs_Freq 200
#define ReadGPS_Freq 50
#define DataLog_Freq 100
// Internal Variables
const int chipSelect = 10;
int currTime;
char GPSlineNOW[200];
char GPSlineNEW[200];
byte incomingByte;
char GPSchar;
char GPSstatus[4];
void setup() {
Serial.begin(9600);
GPSserial.begin(115200);
I2C_0.begin();
I2C_1.begin();
readGPStimer.begin(readGPS, 100000);
readGPStimer.priority(0);
getGPSstatusTimer.begin(getGPSstatus, 5000000);
getGPSstatusTimer.priority(1);
}
void loop() {
Serial.println( String(GPSlineNOW) );
Serial.print("GPS Status: ");
Serial.println(String(GPSstatus));
delay(100);
}
void readGPS() {
int count = 0;
while (GPSserial.available()>0) {
if (count==0){
memset(GPSlineNOW, 0, sizeof(GPSlineNOW));
}
GPSchar = GPSserial.read();
GPSlineNOW[count] = GPSchar;
count++;
}
}
void getGPSstatus() {
char * strtokIndx; // this is used by strtok() as an index
for (int n=1; n<=9; n++){
// code source http://forum.arduino.cc/index.php?topic=288234.0
if (n==1){
strtokIndx = strtok(GPSlineNOW,",");
}
else if (n!=9){
strtokIndx = strtok(NULL, ",");
}
else {
strtokIndx = strtok(NULL, ",");
strcpy(GPSstatus, strtokIndx);
}
}
}
void setupVinOnI2C_0() {
// set calibration for all sensors
I2C_0.beginTransmission(0x40);
I2C_0.write(0);
I2C_0.endTransmission();
}
void setupVinOnI2C_1() {
// set calibration for all sensors
I2C_1.beginTransmission(0x40);
I2C_1.write(0);
I2C_1.endTransmission();
}