I have an Sensor board that outputs a serial stream (currently at 9600baud).
My arduino ProMicro receives the stream and adds one more piece of data to it and then just sends it out Serial0 (USB).
My data looks good with a simple Sketch but when I try combining data I am getting an abnormality and I cant figure out why.
Hope one of you more experienced with serial communications can help me out...
Here is the data as received by the arduino using this Sketch:
void setup()
{
Serial.begin(9600);
Serial1.begin(9600);
}
void loop()
{
if (Serial1.available()){
char ch=Serial1.read();
Serial.print(ch);
}
}
Data:
0,-379,-15969,
#,-7079,-379,-15971,
#,-7080,-376,-15972,
#,-7081,-376,-15972,
#,-7081,-376,-15971,
#,-7080,-376,-15971,
#,-7079,-378,-15972,
#,-7079,-381,-15972,
#,-7081,-380,-15971,
#,-7080,-382,-15972,
#,-7080,-382,-15970,
#,-7080,-383,-15969,
#,-7079,-385,-15969,
....etc
Now with the modified sketch to insert a new piece of data after the "#," I get this:
char ch;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
Serial1.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
}
void loop() // run over and over
{
while(ch!='#'){//look for start of data (#)
if (Serial1.available()){
ch=Serial1.read();
}
}
Serial.print(ch); //print the "#"
if (Serial1.available()){
ch=Serial1.read();
Serial.print(ch); //print the ","
}
Serial.print("DATA"); //space where I want to insert my additional sensor data
while (!Serial1.available()){
}
while (ch >= ',') { //If we are not at start of next stream keep printing data (only /n, /l , and # are below "," in ascii)
if (Serial1.available()){
Serial.print(ch);
ch = Serial1.read();
}
}
Serial.println(); // if ch > ',' then it read a end of line or a "#" so it is done with that line.... Print a line end
}
Data:
#,DATA,-7103,-385,-15978,
#,DATA,-7104,-384,-15978,
#,DATA,-7104,-386,-15975,-378,-15975,
#DATA
#,DATA,-7105,-378,-15975,
#DATA
#,DATA,-7105,-380,-15975,
#DATA
#,DATA,-7104,-382,-15976,
#DATA
#,DATA,-7105,-384,-15974,
#DATA
#,DATA,-7104,-383,-15977,
#DATA
#,DATA,-7104,-382,-15978,
#DATA
#,DATA,-7104,-382,-15977,
#DATA
#,DATA,-7105,-383,-15977,
#DATA
#,DATA,-7106,-382,-15978,
#DATA
#,DATA,-7106,-384,-15978,
#DATA
#,DATA,-7107,-383,-15976,
#DATA
....etc
Im guessing its some sort of buffer issue???? I'm very new to this so any help will be a lifesaver!