Hello all
I decided to post here as i cannot seem to find a proper solution for my issue.
I am working on a personal project to create a laptimer for tracks with GPS. My hardware is:
Arduino mega 2560
Sparkfun venus gps (20hz capable) with external active 3V antenna
Digole serial display 320x240 I2C interface
So here it is:
The GPS sends data succesfully at 20Hz through serial. Only with a mega, as the softserial of arduino uno had issues. I use a serial passthrough program like this:
void setup() {
// initialize both serial ports:
Serial.begin(115200);
Serial1.begin(115200);
}
void loop() {
// read from port 1, send to port 0:
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
}
// read from port 0, send to port 1:
if (Serial.available()) {
int inByte = Serial.read();
Serial1.write(inByte);
}
}
to read the serial data and send commands to the GPS module. The module works only at 115200 at that speed, 38400 for 10Hz, 9600 for below.
The problems start when i try to parse the data AND do something else on the program, like millis() processing for laptimes or writing stuff on the I2C display. If i just parse the data with this code:
void loop() {
if (Serial1.available())
{
char ch = Serial1.read();
Serial.write(ch);
if (ch != '\n')
{
sentence[i] = ch;
i++;
}
else
{
i = 0;
nmea++;
}
}
}
i can properly see the data on a terminal from serial0 of arduino mega. The data is this per sentence:
$GPRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*70
With a \n character for new line.
Now:
-
If i perform any calculations under the else{} of the serial parsing, and by using something like %20 to display things on the screen with a small delay (sentences come every 50msec,i refresh the screen every 500msec as it is slow) everything is good. but then all my processing is limited in 50ms steps of the GPS speed (which is not that bad for the laptimer as it has 50ms resolution anyway limited from the gps - but its not nice to have)
-
If i put my code outside the serial parsing, the terminal then gets very slow or full of errors. I tried timing the rest of the code without delay() (with millis like the blink without delay example), no luck. If i use 1ms delay() on the loop{} void, the serial is messy again (it gets messy even without any more code like this).
It seems i cannot do anything here and i don't understand why. How are simple math calculations messing with the Serial.read() loop? Any ideas welcome.