Go Down

Topic: Optimal communication between Arduino and Raspberry Pi (Read 7950 times) previous topic - next topic

luxy

I wanna made two-way communication between Arduino and Raspberry Pi. Basicly i know how to do it
since there is a lot of tutorials about that on the web but i wanna choose optimal solution
for my case.

On the Arduino i have connected 4 temperature sensors (2x thermistor, 2x ds18b20) and 2 led diodes.
I wanna send readings of all four sensors to Raspberry, which would decide what to do. If for example
T1>T2, Raspberry should send information to Arduino to turn LED1 on and LED2 off.
All decision logic would be in Raspberry, Arduino would act only as a slave for his demands.

My question is, what would be the best protocol to send data from Arduino to Raspberry and vice versa.
Distance between them would be only a few centimeters so this shouldn't be a problem.

Could i use simple serial Rx-Tx communication, i2c, uart,..? I don't need really fast readings of temperature sensors (if i read
all sensors one time per seconds that's fast enough), the only demand is that communication is reliable. One more thing, Arduino
should send information about temperature to Raspberry all the time (let's say one time per second), he don't need request from Raspberry to do
so (like in modbus protocol).

Any recommendation is appreciated.


fungus

Uart with low baud rate.

For each reading send:
a) 2 'magic' bytes (pick two letters of the alphabet...your choice)
b) The temperature
c) A checksum

Together this makes a packet of data which can be accepted/rejected.
Advanced Arduino

pwillard

This all implies that somehow your data will get corrupted or "bit slipped" in transit.  That is actually something I have not seen for months with my Arduino connected via USB to a HUB on the Raspberry Pi.  In my case, I just "send the data" as an assembled CSV "string".  No preamble, No checksum.    The only check I do is to verify that the CSV string contains the correct number of "fields".

In this same configuration, the arduino can regularly ask for a "time sync" for the software RTC running on the arduino (so I can show time on the arduino LCD.  When the Arduino sends an ASCII "bell" character, the RPI sends back a serialized timstamp used to synchronise the local clock.

In none of these situations have I needed to add any sort of extra packet overhead while running at 9600.  So, while you could get all fancy with a packet approach, I'm here saying... you don't really need it...  so really, you are doing it because... well, because you can.

(deleted)

#4
Feb 11, 2014, 08:17 pm Last Edit: Feb 11, 2014, 08:21 pm by spycatcher2k Reason: 1
(deleted)

fungus

The job specification said: "the only demand is that communication is reliable"

Unfortunately it didn't say how many bytes is a "temperature". If it's only one byte then This is all a waste of time.


Advanced Arduino

luxy

Thank you for such a a comprehensive discussion. I didn't define how many bytes is a "temperature" because i am not sure yet, which approach i will use to do that. That's why i wanted to hear your advices and experiences from the past.

According to upper posts i will start with uart and read more about how to include checksum.

fungus

Basically: If it's more than one byte you need a way to know which is the first byte of a packet.

Advanced Arduino

Go Up