I'm close with this code, but it prints out 2 , 4, 6, 8 , 0 individually. I am wondering how I get this array into just one Integer type like int=24680?
This is taking serial data char string from one arduino through tx/rx lines and sending to another arduino (as "24680") but on the receive arduino it is separating out each value (I see this in the Serial Monitor Printout).
Help would be greatly appreciated!
String inString = "";
int stringToInteger;
char mystr[10]; //Initialized variable to store recieved data
void setup() {
// Begin the Serial at 9600 Baud
Serial.begin(9600);
}
void loop() {
// Serial.readBytes(mystr,5); //Read the serial data and store in var
//Serial.println(Serial.read()); //Print data on Serial Monitor
delay(1000);
int inChar = (Serial.read());
inString += (char)inChar;
if (inChar == '\n') {
stringToInteger = inString.toInt();
}
Serial.print("Value:");
Serial.println(inString.toInt());
Serial.print("String: ");
Serial.println(inString);
// clear the string for new input:
inString = "";
}
Not sure why are converting to/from int if you are just passing through
Can you post the sending Arduino code as well.
Looks like there is a delay() on the send side that causes Serial.readInt() to timeout and just return one char as a number
See my tutorial on Arduino Software Solutions for various ways to read a 'whole' line of text.