0

When I send data using

Serial.println()

in what format does it go? I want to observe the data using the software 'Terminal'. When I observe there, if I've sent 255 using Serial.println(), I get a series of numbers 0 0 224 on the terminal. I've kept the baud rate same in both places(9600), Stop Bits as 1 in Terminal.

0

On the Arduino Serial.print() method web page it says:

Prints data to the serial port as human-readable ASCII text.

...which is suitable for most terminal programs. ASCII or American Standard Code for Information Interchange is (usually) an 8 bit code for printing characters. It is not a code which you can do normal math with. That is the integer 1 (which is, in binary, b00000001) is not the same as the character '1' (which is, in binary, b00110001).

  • Example: If you want to print "123" on most terminals you can use the Serial class method print:

    Serial.print(123);

Now, you have to understand that the Arduino paradigm is to make programming simple. So the print method in the Serial class will assume you want to see the characters "123" on the terminal. So, guessing, the print method will convert each decimal number into an ASCII character and print them out as 3 values to the terminal. That is, the ASCII value for 1, followed by the ASCII value for 2 finally followed by the ASCII value for 3.

If this is not what you want there are other variations for the print method in the Arduino Serial class. But all tend to print using ASCII codes.

If you want to print out the binary values, see the Serial.write() method. This method will send the value of the argument to the terminal with out converting into ASCII code.

  • Example: If you want to print "1" on most terminals you can use the Serial class method write:

    Serial.write(49);

...as 49 is the decimal equivalent of the ASCII code for the character '1'.

0

Try using terminal program on PC side. NOT Arduino Serial port monitor built into Arduino IDE.

For example try http://docklight.de/

With this or some other similar terminal program, you can see each byte not only as ASCII representation, but also in HEX or binary format.

So you will easily in no time understand difference between ASCII "224" string and single byte 224 value.

With binary format you can have much much faster PC communication especially when sending float numbers. 4 bytes vs 3.7348823457458743 for example :)

On docklight you even have possibility to define macros for sending back to Arduino i ASCII or in binary format. Or even adjustable macros to send most of the string fixed, but change one byte inside string every time when sending.

But even basic ASCII or binary representation of data is enough for now to help you understand this problematic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.