Arduino Forum

Using Arduino => Programming Questions => Topic started by: joxevc on Dec 01, 2012, 11:58 pm

Title: serial caracter not expected
Post by: joxevc on Dec 01, 2012, 11:58 pm
First of all, must say that I'm newbie to electronics and Arduino.
I've spent a lot of time findind a solution to my problem.
It must have an easy explanation but I just cant find it.

It's as simple as this....

I write a number in serial port like this

Serial.write(5);

when I monitor serial port I get "f" caracter.....

Any idea????

Thanks in advance!!
Title: Re: serial caracter not expected
Post by: PaulS on Dec 02, 2012, 12:00 am
Quote
It's as simple as this....

I write a number in serial port like this

Serial.write(5);

when I monitor serial port I get "f" caracter.....

Any idea????

You need to explain why you want to use a method that sends binary data (Serial.write()) to talk to a device that expects ASCII data (the Serial Monitor). You could also explain why you are surprised when the results are not what you expect.
Title: Re: serial caracter not expected
Post by: BetaDelta on Dec 02, 2012, 12:04 am
If you want to have a '5' displayed then you need to use Serial.print(5, DEC) to display it as a decimal.
Title: Re: serial caracter not expected
Post by: PaulS on Dec 02, 2012, 12:10 am
Quote
If you want to have a '5' displayed then you need to use Serial.print

Yes.

Quote
, DEC) to display it as a decimal.

No. The default for integer values is to display the value in base 10. So, the , DEC is not required. If you want to display in base 7 or base 22, then you need to use the second argument to define the base to use.
Title: Re: serial caracter not expected
Post by: joxevc on Dec 02, 2012, 12:35 am
Thank you all,

It works fine now
Serial.write((byte)5);

I was using diferent baudrate speed in code and serial monitor...