I've set up an Arduino to read a GPS and output part of the NMEA stream to its serial port. I'm trying to read that serial stream on my laptop using processing and although I can now read an NMEA sentence, every time I loop to read the next one its the same sentence (based on the time code). When I restart the program it reads a new sentence but it doesn't update. Should I be flushing the buffer contents before I try to read from the port again?
Appreciate your advice.
Jim Salacain
import processing.serial.*;
Serial myPort; // Create object from Serial class
int val; // Data received from the serial port
PFont font;
int y = 0;
int i=0;
int j = 0;
String valstring;
String timecode;
String lattcode;
String longcode;
String hemiNScode;
String hemiEWcode;
String altcode;
String[] NMEA;
void setup()
{
size(400, 400);
font = loadFont("Helvetica-48.vlw");
textFont(font, 18);
myPort = new Serial(this, "/dev/tty.usbmodemfa131", 38400);
}
void draw()
{
do { // Look for start of NMEA sentence
if ( myPort.available() > 0) { // If port is available,
val = myPort.read(); // read a byte and store it in val
}
} while (val != 36); // While val <> "$"
// Start reading the NMEA sentence
do {
if ( myPort.available() > 0) { // If data is available,
val = myPort.read(); // read it and store it in val
}
valstring = valstring + str(char(val));
} while (val != 13); // Loop until EOL