Thiyraash
Posts: 8
Joined: Thu Feb 23, 2017 9:14 pm

Communication between Raspberry pi and Arduino

Sat Feb 25, 2017 9:57 am

Hi. I'm Raash and I'm currently doing aquarium monitoring system using Raspberry pi 3(master) and arduino uno(slave). I'm using 5 sensors [ turbidity sensor, temperature sensor(DS18B20), ultrasonic sensor(water level sensor), LDR sensor, and water leak sensor(couple of wires)] to control stepper motor, led ligth,rgb light, 2 dc motor and water heater. I even include RTC to raspberry pi. I connected the raspberry pi and arduino using USB(serial communication).
My question is:

1.How do I control arduino from raspberry pi through this serial communication. I know that you have to send a data from arduino to raspberry pi thru serial.write() and raspberry pi will read it but I have plenty of sensors connected to arduino. How the raspberry pi know which this value are from which sensor? I really confuse about that. I saw plenty of guide from internet where they just show 1 value send from arduino and the raspberry pi read that value. But what about plenty of values?

EULERPI
Posts: 51
Joined: Sun May 15, 2016 2:44 pm

Re: Communication between Raspberry pi and Arduino

Sat Feb 25, 2017 10:11 am

Hi,

On the Arduino you could attached a bit of text in front of the sensor data to identify which sensor it is. You could for example use a capital A for the first sensor through to E for the sixth sensor or you could give them unique names.

Then on the Raspberry Pi write a bit of code to separate out the sensor information based on the Capital letter or name.

Regards

Nick

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: Communication between Raspberry pi and Arduino

Sat Feb 25, 2017 3:07 pm

EULERPI wrote:you could give them unique names
yes, you could give / send over USB interface
/ "tagname", real - value, engineering units / " A1pressure ", 586.45678, "kilopoundpersqarefoot"
in CSV /JSON syntax style.
but that's too much overhead on the communication.
from industrial systems PLC / process control systems / visualization systems / historic-trending..
there is used a identification system like a address: device-card-channel and a real value ( for analog ) as 0.0 100.00% ( or -5.00 .. 105.00 to detect over-range / broken wire... )
also for control like PID ( math) ( like inside controller / PLC / arduino will also only be in 100.00 (%) range / PV / SP / OUTPUT.
linked data acquistion systems modbus profibus wired sensors or TCP/IP devices are treated same
( as emulated hardware I/O device card channel )
only in the visualization computers ( PC screens... ) the address will be associated with a TAG-name
and a UNIT and ranged to that's sensor range.
so if a sensor is a pressure with 300 bara range or flow with 1200 L/h the "controllers" never know.
but for the operator interface meaningful names are required / but not so much the hardware connection..
here a python operator screen example
Image
on USB arduino controller

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: Communication between Raspberry pi and Arduino

Sat Feb 25, 2017 6:47 pm

Thiyraash wrote:I saw plenty of guide from internet where they just show 1 value send from arduino and the raspberry pi read that value. But what about plenty of values?
When you say plenty of values, I'm wondering what order you are talking about, fewer than 10, a 100, a 1000? The arduino would start to run into trouble getting the data before problems transmitting it came up, I'm thinking.

You could certainly send the data with IDs that informed the pi what they referred to, e.g. wally=5,jimmy=12 and that sort of thing. If this doesn't affect your system, it doesn't really matter if it is seems like mostly control data and little real data. But you could also send all the data values each time you send data values. Then the pi would know based on where in the stream of values each data point was sent. Perhaps null values could represent unknown or invalid data.

mfa298
Posts: 1386
Joined: Tue Apr 22, 2014 11:18 am

Re: Communication between Raspberry pi and Arduino

Sun Feb 26, 2017 7:41 am

The other option you can use is have the arduino listen to the serial port and have the pi request the data it wants or be able to control the data rate.

I'm not sure how easy that is to do in the arduino framework, but it's certainly possible within the underlying hardware (I've used the ATMega 328 chips in a few other projects.)

Return to “Beginners”