3

So I have 2 sensors connected to my Arduino and am sending the data through serial. I want the Pi to use both values differently. I am trying to make a gui where the values are displayed as such " First sensor data = value 1....Second Sensor data = value 2". I have seen other threads but they don't cover values from two different source. Do help!

1

I suggest you format each serial message as follows.

0x00 length_byte type_byte data_bytes checksum_byte 0xff

and assign a different type_byte value for each type of message you wish to send.

The header (0x00) and trailer (0xff) bytes will let you re-sync if the Arduino and Pi get out of sync. The checksum_byte may be used to ensure message integrity. The length_byte will let you send messages of varying length.

  • 1
    The point is: it doesn't really matter. You are the one to decide how you want to distinguish the messages. joans' protocol is pretty advanced and requires some additional logic to parse packets. It may be enough to simply cut out the LSB, for example, and use that to identify your value's destination. – mystery Apr 17 '17 at 0:03
  • on another side note; make sure the arduino you are using had 3.3v logic; otherwise (without a voltage divider) the serial communications between the arduino (uno is 5 volts) and the pi could damage the pi. – linuxgnuru Apr 18 '17 at 18:13
0

Don't reinvent the wheel by making your own protocol. You can do this buy putting the Firmata firmware on the Arduino (part of the arduino examples collection) then using a firmata client.

I recommend node-red (nodered.org), which is already present in Raspbian, as a solution for both the firmata client and the dashboard.

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.