I am having trouble reading 123,456,789 from the serial and then splitting that data.
Line 54 in my code is the start of it. Can anyone help me out here
I am having trouble reading 123,456,789 from the serial and then splitting that data.
Line 54 in my code is the start of it. Can anyone help me out here
Simple, you need to use arrays, IF/Else statements, and case statements.
Pseudo:
If data is available: look at the chars, if any are ',' then change the case statement. Else, store the data in an array and update the array count.
You can set how many splits you want with the case statements. Once you get the last data into the last case, set the case back to ZERO and start over.
What you do from there is up to you.
If you end each series of numbers with a comma, then the below might be of interest.
//zoomkat 3-5-12 simple delimited ',' string parce
//from serial port input (via serial monitor)
//and print result out serial port
// CR/LF could also be a delimiter
String readString;
void setup() {
Serial.begin(9600);
Serial.println("serial delimit test 1.0"); // so I can keep track of what is loaded
}
void loop() {
//expect a string like wer,qwe rty,123 456,hyre kjhg,
//or like hello world,who are you?,bye!,
if (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
if (c == ',') {
//do stuff
Serial.println(readString); //prints string to serial port out
readString=""; //clears variable for new input
}
else {
readString += c; //makes the string readString
}
}
}
thanks but i don't understand fully.
My values can be -512 through 512... I can separate strings with my code as is... but i get
Invalid conversion from 'int' to 'const char*' on line 54.
zoomkat thanks for your post, i may have to look at it.
If you do a serial print of xbee.read(), what do you get?
same error as my last post.
However i imagine absolutely nothing would be sent since i am not tellign anything to be sent to the serial lines.
Ok, im confused, you are able to successfully split your strings? How? Your split function is returning a String, but your asking it to be put into an INT. The returning String would be the Const char* and "turn" is an INT. Thats the error your getting. Try to convert the string back to an INT, then store it in "turn".
You might want to use ".ToInt()"
Better read this:
char val = xbee.read(); // this will read from the xbee
You can't read a whole string with one read, you read one byte. And a byte can't be split up into smaller things like you are attempting.