0

Serial link send and recieves Bytes. Serial monitor at Arduino IDE reads it's input as character.

So if I type '0' in serial monitor, then FW will read byte 48 - I don't want to implement some silly translation from character value to int - I want to input NUMBER as byte into serial monitor - how do I do that?

byte inByte = Serial.read(); // read the incoming byte
if(inByte == 1) // do stuff
  • 1
    use a serial terminal program, such as PuTTY ... or write a terminal sketch in Processing that does what you want – jsotola Jun 2 at 7:20
  • 1
    The Serial monitor of the Arduino IDE handles only characters, there is no way to send any byte you like. – the busybee Jun 2 at 7:39
  • 4
    It doesn't really matter what you want. You are under the mistaken impression that when you send a string (for example: 3.14159265358) you are sending a number. But you're wrong. Consequently, you will have to "implement some silly translation from character value to int", or learn how to use your available tools to do this for you. – Seamus Jun 2 at 8:39
  • On Linux you may xxd -r -p > /dev/ttyACM0 and then just type hex in the terminal. – Edgar Bonet Jun 2 at 9:18
  • 1
    instead of finding out the ascii code 49 you can simply write if(inByte == '1') // do stuff – DataFiddler Jun 2 at 12:02
2

I think the comments on your question are quite clear. The important point: any asynchronuous protocoll must include the info either how many bytes are transmitted or which byte is the last one. In "raw data", where each value (0-255) can be a legit data value, there is no way to use bytes for meta data. That's why typically only encoded data is transmitted: you have a small range of byte values that can contain the actual info (alphabet and digits) and you have a bunch of values that are free to be used as meta data. E.g. the commonly used \n as endbyte has the int value 10. How would you transmit the int value 10 in that case?

"I don't want to implement some silly translation from character value to int" - it's not silly, that's the way to go! What about float, boolean or negative values (8-bit, 16-bit, etc.)? You may even want to transmit structured data like python dictionaries. The only way the achieve this is using some kind of parser which knows the protocol.

| improve this answer | |
  • Another weird but common "protocol" is a timeout, e.g. used in Arduino's Stream::readString(). – DataFiddler Jun 4 at 11:01
  • I think you completely miss my point - I don't care about character transmission. I am creating my on communication protocol with commands, data transfer, responses and such. And if for any reason I want in some place to interpret the byte value as character there is no problem to implement it in my protocol. I just want to debug part of my protocol and inject the raw command. I store my commands as Enumeration, I just begun and have already more than 10 - so treating them as characters is certainly not the way to go. – Tomáš Viks Pilný Jun 4 at 16:13
1

Based on comments under question no one seems to really know the answer.

So the short answer is: IT'S IMPOSSIBLE - to use Arduino IDE serial monitor to send raw data.

@Edgar_Bonet submitted hint for linux users

@jsotola suggested to use PuTTY, but no additional info on how to do that. Short glance at settings and I couldn't find the way to achieve raw input.

After some additional googling i found some reading where I found program called RealTerm which does the job.

Simply setup your port on Port card and then hit Change button.

On card Display change Display As From ASCII to your prefered format, such as Hex(space)

Then swich on card Send - type your number into input box left to button Send Numbers and press that button

Thats all

The input box accepts decimal value from 0 to 255, or a hexadecimal value, which are prefixed with either a "0x" or a '$'. Each value is separated by space.

Following line is correctly accepted: "255 0xff 0xFF $ff $FF"

Yet another useful tool is Serial Port Monitor. With this you can observe what is really transmitted on line without relying on the interpretation of you application.

Usage is really simple: click white file icon, or Session > New session or press Ctrl+N

Choose port and vizualizer and click Start monitoring... that's it.

I found most useful mode "Dump view"

| improve this answer | |

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.