Newly minted program.
And this time I read ALL the notes on the program and got past my compile issue caused by println (changed println(recievedBytes) to println((char*)recievedBytes).
const byte numBytes = 32;
byte receivedBytes[numBytes];
boolean newData = false;
void setup() { // Put your setup code here, to run once
Serial.begin(19200); // Start serial connection
while (!Serial); // Not really sure what this is for, but examples have it...
}
void loop() { // put your main code here, to run repeatedly
recvWithStartEndBytes(); // ...
showNewData(); // ...
}
void recvWithStartEndBytes() {
static boolean recvInProgress = false;
static byte ndx = 0; //
byte startByte = 10000000; // <- start byte
byte endByte = 01000000; // <- stop byte
byte rb; //
while (Serial.available() > 0 && newData == false) {
rb = Serial.read();
if (recvInProgress == true) {
if (rb != endByte) {
receivedBytes[ndx] = rb;
ndx++;
if (ndx >= numBytes) {
ndx = numBytes - 1;
}
}
else {
receivedBytes[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rb == startByte) {
recvInProgress = true;
}
}
}
void showNewData() {
if (newData == true) {
Serial.print ("This just in ...");
Serial.println((char*)receivedBytes);
newData = false;
}
}
Ran it off of the serial transmission from my sensors and on the serial monitor all I got was line after line of:
This just in...
When I unplugged the serial Rx, the arduino would stop sending "This just in...", but with it plugged in, I didn't seem to get the additional "recievedBytes" packet printed as I expected to.