just replace them with the 0 character (ASCII 48).
Or the space character (ASCII 32).
just replace them with the 0 character (ASCII 48).
Or the space character (ASCII 32).
when I use your sketch like
void loop() {
recvWithEndMarker();
showNewData();
}
void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = ';';
char rc;
while (mySerial.available() > 0 && newData == false) {
rc = mySerial.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}
void showNewData() {
if (newData == true) {
Serial.print("This just in ... ");
Serial.println(receivedChars);
newData = false;
}
}
I get
This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c,0
This just in ... c:255,191,0
This just in ... c:255,1c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0
You have not posted the complete program so I have no idea what pins you are using or what baud rate etc etc
I am tempted to say there is a problem with the incoming data, but I would like to see the whole program.
...R
I actually eventually got it to work with this
#include <SoftwareSerial.h>
SoftwareSerial mySerial(7,8); // RX, TX
void setup() {
Serial.begin(115200);
mySerial.begin(57600); //required when using the hm-10 with an arduino nano
mySerial.listen();
}
char data[20];
byte indx = 0;
void loop() {
while (mySerial.available () > 0) {
char d = mySerial.read();
data[indx] = d;
indx ++;
if (d == ';') {
Serial.println(data);
data[0] = (char)0;
indx = (byte)0;
}
}
}
I still nee to implement strtok() and more but your link sent me in the right direction. Thank you so much.
I apologize if I was difficult to assist, but I greatly appreciate your help.
Ziayakens:
I actually eventually got it to work with this
That does not seem to be functionally different from my tutorial code.
There is a parse example in the tutorial.
...R