# What type of data is sent via TX RX with the Arduino Mega 2560?

Hello,

I am doing various Arduino projects, I am planning to do the math directly with C programming platform. I want to be able to manipulate the data from the arduino in a C program. I am just wondering this question: What type of data is sent from the Arduino Mega 2560 to the USB serial port? Is it: Binary? Hexadecimal? Octal? or Decimal?

Thanks,

Sincerely

Ben Komisar

It is a sequence of ones and zeros. What you do with it is up to you. It is probably best to start off with binary bytes or chars and go from there.

They are just 8-bit numbers. How the receiving program treats them is up to you. Probably easiest to think of the data as 2 hex characters, 0x00 up to 0xFF. 0x48 might be treated as an ASCII character ('0') if going to the serial monitor. 0x48 might be something else if being plotted on a graph, perhaps the 72nd dot above 0 for example. 0x48 might be the 3rd byte in an unsigned long that gets sent out. 0x48 really goes across the line as 01001000 if you were to look at it with an oscilloscope. Not much uses octal these days that I am aware of. Decimal is just a format for humans to read easier. I think most engineers are readily able to work in hex as that's how the data is most readily viewed when looking at an 8-bit register for example. I know I am.

Binary, Hexadecimal, Octal, Decimal are all just ways to represent a number. Like in languages we still mean the same number if we write one, ein, één, une, uno. Only when programming different representations might be handy to make things clear. But we can always interchange them as long as we tell the compiler which representation (language) we use. Without a prefix it's just decimal, when we prefix it with 0b it's binary, 0x for hex and 0 (yeah, just plain stupid 0) for octal.

I want to be able to manipulate the data from the arduino in a C program.

You are already manipulating the data in a C program in the Arduino.

Thanks for the responses,

OK, yes I am aware that the arduino sends ones and zeros, but it has to be in one of the formats listed above...

So, the arduino software on the computer has to know what type of 1s an 0s are being sent (hexadecimal, binary, octal) to interpret the correct value.

So, again I ask, when the arduino mega 2560 sends its data to the rx tx usb serial-port on my laptop. Is it sending the integer values from my sensors in the form of hexadecimal, binary, or octal?

Thanks again,

Ben

binary. one bit at a time. in groups of 8 bits.

:)

Much appreciated, this helps me out on my endeavors quite a bit.

Sincerely

Ben Komisar

It depends on how you send it, too. You could be sending ASCII text. You did not show us the program that is used to send the data.

Have a look at Serial Input Basics. You could use similar code to receive data on a PC. And the general approach can work in any language.

...R

BenKomisar: So, the arduino software on the computer has to know what type of 1s an 0s are being sent (hexadecimal, binary, octal) to interpret the correct value.

No it does not. Did you read my post? It need to know how to store those 1's and 0's and when to read them and in which order etc but that's all part of serial and is done in hardware for you.

BenKomisar: So, again I ask, when the arduino mega 2560 sends its data to the rx tx usb serial-port on my laptop. Is it sending the integer values from my sensors in the form of hexadecimal, binary, or octal?

It's indeed like crossroad says. It sends bytes. But a byte has nothing to do with binairy, hex, octal or whatever. That's just the representation (language) YOU give it.