Introduction: RS485 Between Arduino and Raspberry Pi
For school I need to make a project. I choose to make a smart greenhouse controller completely controlled by a raspberry pi. The sensors will be powered by an arduino uno. During the months that follow I will post the making of this project step by step on instructables so you too can make it.
I needed serial communication that can be used for longer distances. RS485 is perfect for this. RS485 supports speeds upto 10 Mbit/s and 1200 meter distance. Depending on the cable length you need to lower the speed you're sending. Look at this table to know the maximum speed per distance. To read and set the values on the RS485 slave I will use the python language.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Needed
Step 2: Installing the Needed Software Onto the Raspbian
I won't discuss howto install raspbian onto your raspberry. There are already some instructables describing this.
Instead I'm going to describe howto install the needed software.
First update your raspberry:
Then install pip:
apt-get install python3-pip
Click enter for Yes
Then install minimalmodbus:
pip3 install -U minimalmodbus
Step 3: Wiring the Arduino
In the image above you can see how to wire the arduino to the RS485 interface. The second RS485 represents a USB to RS485 adapter.
Step 4: Coding the Arduino
First import this library via sketch, use library and add zip library.
Then upload the sketch that I included as an attachment. This is the code for the arduino slave node that makes it possible to control the onboard led on pin 13 of the arduino.
Step 5: Programming RS485 on the Raspberry
Now we are going to code the raspberry pi as a master.
- Open a terminal on your raspberry pi.
- Create a new file modbus.py
- type i for insert
- paste in the code in the file
- press the escape key
- type :wq
- press the enter key
Step 6: Testing the Script
Type in the command:
python3 modbus.py Now give in 1 or 0 and you will see the led on the arduino go on and off.
Step 7: Conclusion
This was the first step in order to make my complete greenhouse controller. Via RS485 I can turn on my valves and read the sensorvalues. I hope you enjoy this instructable.
This is an entry in the
Raspberry Pi Contest 2020