I am using the serial monitor to send a value (1-9) to the Arduino and then have the Arduino send back a response stating what it received. For example I send value 1 then returns the value 1, I send value 2 then returns value 2, and so on.
For some reason Arduino returns value 1 and next line value -38. I have followed the code from two examples, but my results are different.
Any suggestions and advice would be much appreciated!
Hardware and Software Setup:
Arduino Uno
Arduino v1.0.1
MacBook Pro Mid 2010
OSx 10.8
Code:
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// Have the arduino wait to receive serial input:
while (Serial.available() == 0);
// Read the serial input:
int val = Serial.read() - '0';
Thanks for the quick response! I spent some time to research your advice, but I still do not understand. I assume your advice applies to the Serial.println and how it was implemented in the loop? I am a complete "noob" with programing, could you please clarify "don't send it or filter it out"?
Thanks for the quick response! I have tried using just the Serial.print(), but this displays the values 1 and -38 on the same line. I read through your example but I am not trying to do the same thing as you. Meaning I want send the value 1 to the Arduino and receive 1 response back.
I want:
type the number 1 into serial monitor and press send button.
serial monitor returns 1
Instead I get:
type the number 1 into serial monitor and press send button.
serial monitor returns 1
serial monitor returns -38
Maybe a computer issue, software issue, or older Arduino board? I'll keep trying!