I am very new to Arduino.
Now I am trying to send the sensor data to Computer.
The sensor data will be stored as bytes into arrays. To build a robust transmission I'll pack the data with own defined protocol. e.g. has Header, length, Checksum ...
My question is, how to combine the sensor data with protocol frames and send it with serial in a better way.
Now I have written something like below, it works, but very simple and dirty :)
#define SOF_1 0x55
#define SOF_2 0xAA
uint8_t SensorDataByteArrA[4] = {0xc1, 0xc2, 0xc3, 0xC4};
uint8_t SensorDataByteArrB[4] = {0xe1, 0xe2, 0xe3, 0xe4};
void send_sensor_data()
{
Serial.write(SOF_1);
Serial.write(SOF_2);
Serial.write(SensorDataByteArrA, 4);
Serial.write(SensorDataByteArrB, 4);
// ...
}
So I'd like to know how will you handle my case?
sendHeader
... Perhaps that helps developing the reading side in sync. Somewhere, more or less deep down, there will be a series ofwrite
calls. – DataFiddler Sep 13 '20 at 21:28