Analog readings to serial data format

I'm trying to read analog inputs and send them serially to Matlab. I understand that the readings will be 10 bits each, I also know that serial communication sends data in 8 bits packets. What's the right way to send the data, I mean what will it's format be? I used to just print the analog value to serial (using serial.print(value)). Is this method correct?


Is this method correct?

It’s one way that works for many cases but if it’s correct depends on what you want to do with it, how fast you need the to parse the value and so on. You can compress the values in many different ways but in most cases it’s not worth the effort. Another often used method is to put the 10 bits into a 16 bit integer and transfer that in two bytes but you have to keep in mind that not every system uses the same order for the two bytes.

I'm trying to send analog input readings to matlab and I know that analog inputs at 10 bits each. How is it sent serially? I don't understand how the readings will look like when sent to the serial port, is it decimal, binary, or what exactly. Please clarify this point to me if you know.


“Serial.println()” the number (as ascii) is one method…

Okay so this ASCII will be transfered as a single unit? I mean when I recieve it on the other side (matlab) do I have to read multiple elements and convert it back to decimal? (The ASCII for 1023 is 049 048 050 051) does this meas that I need to read four elements and then convert to decimal?

Duplicate threads merged.

The actual transmission format depends on many circumstances that you didn't tell us yet. Is it just a single analog value to be transmitted once? Or always exactly 4 values to be transmitted once a minute? Is it a lot of data so data has to be as compact as possible?

Transmitting as ASCII is a simple method that is clearly defined and easy to parse. You don't have to care for endian issues but still you have to define some protocol to know on the other end (MatLab) what to parse in which order.