Go Down

SunnyBoy

May 13, 2012, 05:28 pm
Hello everyone,

I'm getting this problem that's driving me crazy, tried everything and googled for hours, now my last hope is this forum.

Here is the code:
Quote

int incomingByte = 0;   // for incoming serial data

void setup() {
Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
}

void loop() {

// send data only when you receive data:
while ( Serial.available( ) > 0 ) {

// say what you got:
Serial.println(incomingByte);

}
delay(500);

}

When I enter an integer, I should get it back right?

Here is what I get when I enter "4" instead:

Serial monitor:

Here is "0":

Serial monitor:

What am I missing?

Thanks

AWOL

#1
May 13, 2012, 05:34 pm
You're missing the difference between the ASCII representation of a digit, and the digit itself.
Comes up about once a month here.
"Pete, it's a fool (who) 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.
I speak for myself, not Arduino.

SunnyBoy

#2
May 13, 2012, 05:35 pm
I get that one, but it doesn't explain the systematic second line = 10.
It is the ASCII symbol for a new line and I don't know how to get rid of it.

Any ideas?

Nishant_Sood

#3
May 13, 2012, 05:36 pm
You are going to get ASCII representation codes on Key stroke inputs , You will understand more on reading about ASCII values on respective Key Strokes, Google for it.
"Real Men can Accomplish  Anything"

- skype : nishants5
ਫ਼ਤੇਹ ਕਰੁਂ!
www.winacro.com

AWOL

#4
May 13, 2012, 05:38 pm
Carriage return / line feed,
13 / 10
"Pete, it's a fool (who) 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.
I speak for myself, not Arduino.

SunnyBoy

#5
May 13, 2012, 05:40 pm
and how can I fix this?

AWOL

#6
May 13, 2012, 05:42 pm
What do you mean "fix"?
"Pete, it's a fool (who) 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.
I speak for myself, not Arduino.

dxw00d

#7
May 13, 2012, 05:43 pm
Use something different to input your data, that doesn't send CR/LF.

SunnyBoy

#8
May 13, 2012, 05:46 pm

what you wrote is like chinese to me. could you please explain further? I'd be grateful to you

Thanks

dxw00d

#9
May 13, 2012, 05:56 pm
How are you entering your "4"? Are you using the serial monitor?

#10
Yes

dkl65

#11
May 13, 2012, 06:09 pm
Maybe you can try Serial.write for incomingByte, and use if instead of while if you only need 1 byte. I might try it later.

dxw00d

#12
May 13, 2012, 06:11 pm
There are two drop-downs at the bottom of the serial monitor. One of them selects what is sent at the end of whatever you type. It might say 'Newline', or 'Carriage return' currently. Try changing it to 'No line ending'.

If that doesn't work, you'll need a different terminal program.

SunnyBoy

#13
May 13, 2012, 06:18 pm
Works great! with: 'No line ending'

but now it reads only one digit. So if I type 10, I get :

what should I change?

PS: Thanks dxw00d

AWOL

#14
May 13, 2012, 06:36 pm
Why not read the terminator....and ignore it?
"Pete, it's a fool (who) 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.
I speak for myself, not Arduino.

Go Up