Pages: [1]   Go Down
Author Topic: Serial comunication problem  (Read 190 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm relatively new to Arduino, but I know this isn't supposed to happen... I'm testing my serial because I was getting false inputs when I'd type a serial phrase... I set up this echo script from online sources and any time I type 1 it returns a 1 like it should but also a -38 on the next line immediately after... The -38 becomes 10 if I don't include the subtraction



void setup()
{
 Serial.begin(9600);
}

void loop()
{
 while (Serial.available() == 0);

 int val = Serial.read() - '0';   /*<<<----- this subtraction changes the false value from -38 to 10 if it is not here.  */
 Serial.println(val);
}




Arduino UNO R3
HP touchsmart TM2 running win7 64bit
« Last Edit: November 14, 2012, 02:22:18 pm by D0p3n1nja » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25776
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ASCII "line-feed" (LF) character has the decimal value 10
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: [1]   Go Up
Jump to: