Integers over serial

Greetings and salutations, arduino gurus. :)

I am working on a project where I will have to send quite a lot of numerical data in the form of integers to my arduino. What is the most painless way of doing it? Do I have to split the data into words and bytes to transmit over the serial port or can I just straight send the integer data without manipulating it too much first?

Thank you T.

I will have to send quite a lot of numerical data in the form of integers

"quite a lot" is not a very accurate definition of the quantity of data. The actual number of integers per second would be a much more useful quantity to know.

What is the most painless way of doing it?

The most painless way and the best way are not necessarily the same way. Whether the most painless way will be satisfactory is not known, since the quantity of data is not known. Nor is the application that is to receive the data.

Do I have to split the data into words and bytes

Only Microsoft has a data unit called a word. No one else (in their right mind) does. So, no, you don't have a break a 2 byte integer into a two byte word before you split it into bytes.

You may not need to split it into bytes. You may be able to send the data as strings. It all depends on the quantity of data being sent, and the receiving application.

Paul > Points well made :slight_smile: I could have been more clear… Sending them as string is an interesting thought I had not, I admit, considered before.

The way this device will work is that it will start in a standby mode waiting for data. I upload around 50 “frames” into the device (a sort of camera dolly) which include a few properties each. The speed of transmission isnt all that important. I have a c# based gui on my pc doing the sending and the arduino reads the serial port.

Make sure that the data being sent has recognizable separators between the values, and a recognizable marker at the end of a packet. One at the start would be good, too.

Read the serial data until a start of packet marker arrives. Then, record the data until an end of packet marker arrives or until there is no more data.

Only when the end of packet marker arrives should you parse the data and make use of it.

Using start and end markers allows you to perform at least rudimentary checking of the integrity of the data being send. Bits and bytes do get lost/corrupt occasionally.

I will do what you said :) (or a variation thereof). Thank you for your time :)

PaulS: Only Microsoft has a data unit called a word. No one else (in their right mind) does. So, no, you don't have a break a 2 byte integer into a two byte word before you split it into bytes.

"In any case, each unit, often called a word, is individually addressable; that is, in the course of executing a given instruction, the computer..."

Sorry Paul, that was taken from "A Fortran IV Primer" by Organick published in 1966, which I picked up on a free book shelf. Unless this author knows McFly personally very well, he was just reiterating what's standard in computer terms in the 60's :)