I'm trying to get into serial communication and doing some tutorials (this one by Jeremy Blum). I cannot explain my results however: I keep getting a extra character when reading serial communication from the arduino (duemilanove):
This is the most basic code to return values send from my serial monitor:
void setup()
{
Serial.begin(9600);
//pinMode(ledpin, OUTPUT);
}
void loop()
{
//wait for serial
while (Serial.available() == 0);
int val = Serial.read() - '0';
//echo
Serial.println(val);
}
my result when I enter "0" is:
0
-38
The arduino always returns a extra -38! I'm hoping I did not break anything because in the past Ive used it to rewrite the bootloader of a arduino mini.