How to send a multidimensional array of bits via serial

Hello,
I would like to send a multidimensional array of bits via serial.
Like this:
1 1 0 0 0 0 0 1 1
1 1 1 0 0 0 1 1 1
1 1 1 1 0 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 0 1 1 1 0 1 1
1 1 0 0 1 0 0 1 1
1 1 0 0 0 0 0 1 1
1 1 0 0 0 0 0 1 1
1 1 0 0 0 0 0 1 1
1 1 0 0 0 0 0 1 1
I have started several attempts before, but only managed to send them very slow and with information losses. I send them from a Raspberry Pi to an Arduino.

Thank you very much for your help

Marco

If you are wanting to send and the sender is a RPi, then what is the "Arduino" question?

Something like this or exactly 9bits in the row?

No like this, they can be even longer. Only the columns are fixed to 10

So you need to organize bits to octets (bytes) and send it just as array of bytes

Did you mean 10 "rows"? You show 9 columns.

No like this, they can be even longer.

Within the same transmission, or different transmissions can have a different fixed number of columns?

No vertical, columns. In different transmissions.

Rows are vertical. Columns are horizontal. The elements of a row are horizontal, the elements of a column are vertical. Hope that clarifies things.

In your scheme, is this 2 columns and 3 rows, or vice versa:

000
000

?

Also, a separate issue... how will the receiving program know the dimensions of the array?

You're right, so sorry yeah I mean row:)

So every row has 9 bits, the number of rows vary?

what langugae on the RPi are you planing to use?
how is the Arduino connected? e.g. to a USB port or to the serial GPIO pins?
where is the data comming from?

Yes.
I thought, that I could handle this problem with a stop character after the entire array

I plan to use Python, because the interface the data comes from is also coded like that.
The Arduino is connected via USB port.

You can pack them into consecutive bytes. You won't achieve maximum efficiency until you send 8*9 = 72 bits = 9 bytes (8 rows).

How do you send a value that is equal to the stop character... ?

Are you constrained in how efficient or fast this transfer must be? It will influence a choice of alphanumeric or binary data encoding.

You can send first 8 bits of row as byte, and last bit combined with stop character as the second byte.
It won't quite efficiently, but make the benefit that the code will be simple and short

Nice. Or, also use the additional bits for a CRC check...

So

bbbb bbbb bSCC CCCC

b = bit
S = stop
C = parity

just import serial and open /dev/ttyACM0
is your data in a BitArray?
you could transmit blocks of 8 bytes which contain the first 8 bits of each 9 bit data and then a ninth byte containing the ninth bit of each data

1 Like

Endless room for creativity on this. I wonder what the bits represent?

The positive bits represent spots where a nozzle is spraying water onto the ground, as in this video.

The data transmission should be replaced by a wireless connection.

Thank you for the answers, I will try this out

1 Like