i am a newbie and i want to send a simple integer to arduino via serial communication, i get the value but there is also garbage valuse i don’t understand to reslove it… a little help will be appreciated.
void setup()
{
Serial.begin(9600);
}
void loop()
{
while (Serial.available() == 0);
int val = Serial.read() - '0';
Serial.flush();
Serial.println(val);
}
When you send the number '7' for instance, you are actually sending the string "7\n", which is characters 55 and 10. '0' is character 48, so 55 - 48 yeilds 7. However, 10 - 48 yields -38.