Hi All,
Using the Serial input basics guide
I have a dummy UNO sending a long string:
// Dummy Tx
String stringa = "7E00AA900013A200412723B4FFFEC1CC392C4335314D7025A2000100010030008ACC818730000005A7F67694D8874620ABD4237FF98BDBB0F1AF6B932FC8177382A0483773839D42C1059C3481FCFC6F1C1945D7D2C7372A676EDA361960A18376AD31129536DF0237FA627C04FD59A4DD42E4021A02598D59B633DBCF902B9F4759335B8EA63AA336B32A6D898739093D450495FCA603854B9D3EA53C4AB1369FCE08C61192A882158D33000146";
void setup() {
Serial.begin(9600);
Serial.println(stringa);
}
void loop() {
delay(5000);
}
Then there is another UNO that receives and splits the packet to send onto a radio at a different baud rate. Note the radio is limited to 32 ASCII char per packet but splits into different packets if \r received:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2); // RX, TX
const byte numChars = 32;
char receivedChars[numChars]; // array to store received data
boolean newData = false;
int charCount = 0;
void setup() {
Serial.begin(9600);
mySerial.begin(115200);
mySerial.println("...");
}
void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = '\n';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
if (charCount == 32){
mySerial.print("\r\n");
charCount = 0;
}
charCount ++;
}
}
}
void showNewData() {
if (newData == true) {
mySerial.print(receivedChars);
newData = false;
}
}
void loop() {
recvWithEndMarker();
showNewData();
}
What I am finding is that the received string should be:
7E00AA900013A200412723B4FFFEC1CC392C4335314D7025A2000100010030008ACC818730000005A7F67694D8874620ABD4237FF98BDBB0F1AF6B932FC8177382A0483773839D42C1059C3481FCFC6F1C1945D7D2C7372A676EDA361960A18376AD31129536DF0237FA627C04FD59A4DD42E4021A02598D59B633DBCF902B9F4759335B8EA63AA336B32A6D898739093D450495FCA603854B9D3EA53C4AB1369FCE08C61192A882158D33000146
But I am getting some '?' in place of some characters (different each time):
?RX 14:25:18.694: ?E00AA900013A200412
RX 14:25:18.726: 723B4FFFEC1CC392C4335314D7025A20
RX 14:25:18.758: 00100010030008ACC818730000005A7F
RX 14:25:18.790: 67694D8874620ABD4237FF98BDBB0F1A
RX 14:25:18.822: F6B932FC8177382A0483773839D42C10
RX 14:25:18.869: 59C3481FCFC6F1C1945D7D2C7372A676
RX 14:25:18.901: ED?361960?18376AD3?129536DF0237F
RX 14:25:18.933: A627C?4FD59A4DD42E4021A02598D59B
RX 14:25:18.965: 633DBCF902B9F4759335B8EA63AA336B
RX 14:25:18.997: 32A6D898739093?450495FCA603854B9
RX 14:25:19.030: D3EA5?C4AB1369FCE08C61192A882?58
RX 14:25:19.050: D33000146
Can you see anything that I have missed or can try to get this more reliable?
Thanks,
Ben.