wenhui
Posts: 10
Joined: Thu Aug 11, 2016 8:26 am

User Guide of RS485 Shield for Raspberry Pi

Thu Sep 01, 2016 9:16 am

RS485 Shield for Raspberry Pi is a level converter module that interfaces TTL signal level to RS485 level easily.
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
2 . Install python-pip

Code: Select all

$ 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. :

Code: Select all

$ sudo pip install wiringpi
4. Installed the associated library files of serial ports :

Code: Select all

$ sudo apt-get install python-serial
5.Test whether the GPIO library and the serial library is installed or not:

Code: Select all

$ python

Code: Select all

$ import RPi.GPIO

Code: Select all

$ import serial
If there is no error , then the two libraries are installed correctly.
[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
You can see the following information:

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
7. Disable log in from the serial port:

Code: Select all

$ sudo nano / etc / inittab
and comment out ” T0: 23: respawn :/ sbin / getty-L ​​ttyAMA0 115200 vt100″

8 Restart Raspberry Pi:

Code: Select all

$ sudo reboot
Now you can use / dev/ttyAMA0 like the regular COM port.

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”)
Part List
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]

shyamsandeep
Posts: 1
Joined: Mon Sep 26, 2016 5:09 pm

Re: User Guide of RS485 Shield for Raspberry Pi

Mon Sep 26, 2016 5:18 pm

Hi
i have bought these units and i am trying to communicate to a refrigeration unit over RS485 Modbus- http://www.ascontecnologic.com/index.ph ... series/x34 ,

After the setup, i tried to run the python program, but i do not see any data,

could you give more details on how to set register of the unit and keep reading periodically, Also should i enable the handshake for Rx and Tx, please confirm

Thanks
Sandeep

Return to “Beginners”