Hello everyone,
I'm currently trying to wrap my head around an issue I'm experiencing with the Arduino Nano 33 BLE I'm working on.
My goal is to receive quite long strings from Serial and store them into array but I'm currently having some problem with the reading part of my program.
For now I'm using the Receiving several characters from the Serial Monitor example from this topic
https://forum.arduino.cc/index.php?topic=288234.0
I'm sending this type of data to the serial monitor (either 40 different values or 20) :
<0,0,0,1,0,2,0,2,0,0,2,2,0,1,55,134,169,188,202,213,217,215,228,238,234,223,238,238,240,239,241,241,241,241,233,241,243,240,255,249>
When trying with an Arduino Uno WIFI I have absolutely no issues and the string is perfectly printed to the serial monitor but with the Arduino Nano 33 BLE I'm getting either two possible output : the full one or an incomplete version (as seen in the picture attached)
Here is the code :
const byte numChars = 200;
char receivedChars[numChars];
boolean newData = false;
void setup() {
Serial.begin(9600);
Serial.println("<Arduino is ready>");
}
void loop() {
recvWithStartEndMarkers();
showNewData();
}
void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
// if (Serial.available() > 0) {
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
}
}
}
void showNewData() {
if (newData == true) {
Serial.print("This just in ... ");
Serial.println(receivedChars);
newData = false;
}
}
Do you have any suggestions on things to change in the code to make sure I'm receiving the complete line each time ?
Thanks for your help !!