What is RS485
The following material is copied from: http://www.radio-electronics.com/info/t ... 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.
RS-485 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
Attribute Specification
Cabling Multi-drop
Number of devices 32 transmitters
32 receivers
Communications modes half duplex
Maximum distance 4000 feet @ 100 kbps
Maximum data rate 10 Mbps @ 50 feet
Signalling Balanced
Mark (data = 1)
condition 1.5 V to 5 V (B greater than A)
Space (data = 0)
condition 1.5 V to 5 V (A greater than B>
Driver output current 250 mA
Install Dedendecy Libraries
1. Update source list
Code: Select all
$ sudo apt-get update
Code: Select all
$ sudo apt-get install python-pip
Code: Select all
$ sudo pip install wiringpi
Code: Select all
$ sudo apt-get install python-serial
Code: Select all
$ python
Code: Select all
$ import RPi.GPIO
Code: Select all
$ import serial
[img]http://cnlearn.linksprite.com/wp-conten ... 0/图片16.png[/img]
6. We need to configure file ‘/boot/cmdline.txt’ to remove the kernel booting information and debug message:
Code: Select all
$ sudo nano / boot / cmdline.txt
Code: Select all
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
Code: Select all
$ sudo nano / etc / inittab
8 Restart Raspberry Pi:
Code: Select all
$ sudo reboot
Python
Test code(serial_test.py) :
Code: Select all
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”)
1 x Raspberry Pi
1 x RS485 shield for Raspberry Pi
[img]http://learn.linksprite.com/wp-content/ ... 00x169.jpg[/img]
3 x Male to male jumper wires
1 x RS232-RS485 converter
[img]http://learn.linksprite.com/wp-content/ ... 00x169.jpg[/img]
1 x 9DB male of serial-to-USB cable:
[img]http://learn.linksprite.com/wp-content/ ... 00x169.jpg[/img]
Wire Diagram and Test
Wiring:
RS485 Shield ‘A’-> RS232-RS485 converter ‘ T/R + ‘
RS485 Shield ‘B’-> RS232-RS485 converter ‘ T/R- ‘
RS485 Shield ‘GND’ -> RS232-RS485 converter’ GND ‘
[img]http://learn.linksprite.com/wp-content/ ... 00x169.jpg[/img]
After the wiring is done, launch a serial terminal. We use X-CTU in our case, and set the baud rate to 9600:
[img]http://learn.linksprite.com/wp-content/ ... 00x187.png[/img]
After running serial_test.py, enter the characters in the X-CTU:
[img]http://learn.linksprite.com/wp-content/ ... 300x97.png[/img]
[img]http://learn.linksprite.com/wp-content/ ... 00x162.png[/img]