RS485 Shield for Raspberry Pi is a level converter module that interfaces TTL signal level to RS485 level easily.
The following material is copied from: http://www.radio-electronics.com/info/telecommunications_networks/rs485/rs-485-tutorial-basics.php
RS485 is a standard for the transmission of serial data long a hard wired cable. The system is defined under EIA/TIA-485 and RS-485 provides the ability for multi-drop cabling and for speeds of up to 10 Mbps over short runs of up to 50 feet and slower communications at speeds of 100 kbps at distances of 4000 feet. Although not widely used in domestic environments, it is widely used for data acquisition applications.
Often RS-485 links are used for simple networks, and they may be connected in a 2 or 4 wire mode. In a typical applications several address able devices may be linked to a single controlled (PC), and in this way a single line may be used for communication. It is also possible to convert between RS485 and RS232 using simple interface converters that may include optical isolation between the two circuits as well as surge suppression for any electrical ‘spikes’ that may be picked up.
Using RS-485, it is possible to construct a multi-point data communications network. The standard specifies that up to 32 drivers or transmitters along with 32 receivers can be used on a system. This means that there can be 32 nodes capable to both transmit and receive. This can be extended further by using “automatic” repeaters and high-impedance drivers / receivers. In this way it is possible to have hundreds of nodes on a network. In addition to this, RS485 extends the common mode range for both drivers and receivers in the “tri-state” mode and with power off. Also, RS-485 drivers are able to withstand “data collisions” (bus contention) problems and bus fault conditions.
As RS485 networks become larger, the problem of data collisions becomes greater. This can be solved, at least in part by ensuring the hardware units (converters, repeaters, micro-processor controls) are designed to remain in a receive mode until they are ready to transmit data.
Another approach is to design a ‘single master’ system. Here the master initiates a communications request to a “slave node” by addressing that unit. The hardware detects the start-bit of the transmission and thereby enables the transmitter. Once a requested data is sent the hardware reverts back into a receive mode.
RS485 specification overview
|Number of devices||32 transmitters
|Communications modes||half duplex|
|Maximum distance||4000 feet @ 100 kbps|
|Maximum data rate||10 Mbps @ 50 feet|
|Mark (data = 1)
|1.5 V to 5 V (B greater than A)|
|Space (data = 0)
|1.5 V to 5 V (A greater than B>|
|Driver output current capability||250 mA|
1. Update source list
$ sudo apt-get update
2 . Install python-pip
$ sudo apt-get install python-pip
3.Use pip to install WiringPi (WiringPi is designed for raspberry pi to behave similarly to that of the wiring library under Arduino. After this library is installed,c or shell or python can use the function to configure and control GPIOs directly. :
$ sudo pip install wiringpi
4. Installed the associated library files of serial ports :
$ sudo apt-get install python-serial
5.Test whether the GPIO library and the serial library is installed or not:
$ import RPi.GPIO
$ import serial
If there is no error , then the two libraries are installed correctly.
6. We need to configure file ‘/boot/cmdline.txt’ to remove the kernel booting information and debug message:
$ sudo nano / boot / cmdline.txt
You can see the following information:
dwc_otg.lpm_enable = 0 console = ttyAMA0, 115200 kgdboc = ttyAMA0, 115200 console = tty1 root = / dev/mmcblk0p2 rootfstype = ext4 elevator = deadline rootwait
Remove “console = ttyAMA0, 115200 kgdboc = ttyAMA0, 115200” so that the information becomes:
dwc_otg.lpm_enable = 0 console = tty1 root = / dev/mmcblk0p2 rootfstype = ext4 elevator = deadline rootwait
7. Disable log in from the serial port:
$ sudo nano / etc / inittab
and comment out ” T0: 23: respawn :/ sbin / getty-L ttyAMA0 115200 vt100″
8 Restart Raspberry Pi:
$ sudo reboot
Now you can use / dev/ttyAMA0 like the regular COM port.
Test code(serial_test.py) :
import serial port = ”/dev/ttyAMA0″ usart = serial.Serial(port,9600) usart.flushInput() print (“serial test: BaudRate = 9600″) usart.write(“please enter the character:\r”) while True: if( usart.inWaiting()>0 ) : receive = usart.read(1) print ”receive: ”,receive usart.write(“ send: ’”) usart.write(receive) usart.write(“‘\r”)
RS485 Shield ‘A’-> RS232-RS485 converter ‘ T/R + ‘
RS485 Shield ‘B’-> RS232-RS485 converter ‘ T/R- ‘
RS485 Shield ‘GND’ -> RS232-RS485 converter’ GND ‘
After the wiring is done, launch a serial terminal. We use X-CTU in our case, and set the baud rate to 9600:
After running serial_test.py, enter the characters in the X-CTU: