1. Introduction
- LattePanda Alpha&Delta RS485 expansion board is a light industrial-grade interface expansion board which specially designed for LattePanda Alpha&Delta, it converts USB pins into RS485 interfaces.
- Use FTDI's FT232RL chip for USB signal conversion, which is stable and reliable.
- Use Jinshengyang's serial port transfer to RS485 module, it ensures power isolation and signal isolation.
- Two parallel RS485 output signals, in the form of industrial wiring terminals, can be conveniently connected to various RS485 interface devices.
- Immersion gold technology, not only for aesthetic, but also guarantees PCB quality.
- The onboard 120 Ω terminal matching resistance, control access to pick up by the switch.
- A nylon column is included with the product package, ensure the stability of the connection between the product and the LattePanda.
2. Specification
- Module operating power: +5V
- Comply with EIA/TIA-232-F standard
- Communication baud rate up to 1M bps
- Maximum 12V power output
- Isolation voltage 3000 VDC
- 1/8 unit load, bus load capacity up to 256 nodes
- Bus fail-safe and bus drive short circuit protection
- Operating temperature range: -40℃ to +105℃
NOTE: hot plug is not supported.
3. Application
The RS232 interface can be easily used in the Windows environment. (Compatible with Linux environment)
4. Board Overview
LattePanda Alpha&Delta pin function description (recommended to refer to LattePanda Alpha official wiki & LattePanda Delta official wiki)
5. Introduction to RS485 Communication Protocol
One of the typical serial communication standards.
The RS485 interface has the advantages of good resistance to noise interference, long transmission distance, multi-station capability and simple wiring, so it is widely used in industry.
The RS485 communication protocol only defines the transmission voltage, impedance and other electrical characteristics, but does not define the software protocol. The data signal adopts the finite difference transmission mode, so it has the ability to suppress common mode interference. The bus transceiver has high sensitivity, it can detect voltages down to 200mV. RS-485 is very convenient when used for multi-point interconnection, it can save a lot of signal lines. It uses a pair of twisted pairs, one of the conductors is defined as A and the other is defined as B. Normally, the positive level between the transmitting driver A and B is +2 ~ +6V, which is in the logic 1 state, and the negative level is between -2V ~ 6V, which is in the logic 0 state. The maximum transmission distance is about 1200 meters, the transmission rate is depending on the transmission distance. The shorter the distance rate, the faster the transmission speed. RS485 requires 2 terminal resistors, and its resistance value must be equal to the characteristic impedance of the transmission cable (usually 120Ω). In short-distance transmission, there is no need for terminal resistors. The terminal resistor is connected to both ends of the transmission bus.
6. Introduction to ModBus communication protocol
The Modbus protocol is a master/slave architecture protocol. Only one node of all nodes is the master node, and the other nodes that use Modbus protocol to participate in communication are slave nodes. Each slave device has a unique address. A ModBus command contains the Modbus address of the device which to be executed. All devices will receive the command, but only the device at the specified location will execute and respond to the command (except for address 0, the command at address 0 is a broadcast command, and all devices that receive the command will run, but will not respond to the command). All Modbus commands include a check code to ensure that the command arrived has not been corrupted. Basic Modbus commands can instruct an RTU to change a value in one of its registers, control or read an I/O port, and command the device to send back data in one or more of its registers.
There are many variants of the Modbus protocol:
- Modbus RTU - Used in serial communication and uses compact binary representation of data for protocol communication. The RTU format follows the command/data, and has a cyclic redundancy check checksum as an error check mechanism to ensure the reliability of the data. Modbus RTU is the most common implementation available for Modbus. Modbus RTU messages must be sent continuously, and there is no hesitation between characters. Modbus messages are framed (separated) according to idle (silent) time periods.
- Modbus ASCII - Used in serial communication, and uses ASCII characters for protocol communication. The ASCII format uses a longitudinal redundancy checksum. Modbus ASCII message consists of colon (":") and line feed character(CR / LF).
- Modbus TCP/IP or Modbus TCP - This is a Modbus variant, it is used for communication on TCP/IP network which is connected by port 502. It doesn't need checksum calculation, because the lower layer already provides checksum protection.
7. Tutorial
Here is a demonstration that LattePanda Alpha & Delta controls the DFR0290 8-channel relay through the RS485 interface.
Driver Installtion
Note: the driver needs to be installed when using on Windows for the first time. There is no need to install driver in Linux system.
Windows supports the automatic search and installation for FTDI chips. Plug the expansion board into the LattePanda board and wait for a few minutes to complete the installation. (please keep LattePanda connected with network when installing the driver automatically).
Under Windows environment, you can check whether the driver is installed successfully in device manager. After the driver is installed, the COM name will be USB serial port.
Click the link to install manually:
Requirements
- Hardware
7.1 Plug the shield into LattePanda Alpha & Delta
You need to use nylon columns and nylon screws to fix the expansion board and LattePanda.
7.2 Connection Diagram
7.3 Use host computer software
- After connecting Lattepanda Alpha & Delta and RS485 interface extension board, boot up
- Power on RLY-8-PoE-RS485 8-channel network control relay module
- Open the host computer software produced by DFRobot on LattePanda Alpha & Delta, select COM1 serial port, and set the baud rate to 115200
- Use the host computer software to operate the relay module
7.4 Use serial port debugging assistant
- Repeat the above steps
- According to the custom communication rules of the 8-channel network control relay module, use the serial port debugging tool to send the correct instructions, then control the relay module.
As shown in the picture below, control the switch of relay No. 1
7.5 Use ModBus debugging assistant
- Repeat the above steps
- According to the ModBus protocol rules of the 8-channel network control relay module, use the ModBus debugging assistant to send the correct instructions, then control the relay module.
As shown in the picture below, get the device name and control the switch of relay
图片 英文
7.6 Use the ModBus library of Python
At present, the mainstream third-party libraries for Modbus protocol in Python is shown below:
- Modbus_tk
- Pymodbus
- Minimalmodbus
- Umodbus
Library name | Source code | 3rd party dependency | Main functions |
---|---|---|---|
modbus_tk | https://github.com/ljean/modbus-tk | pyserial | Support modbus TCP and RTU, both master and slave. Don't support modbus ASCII. Heavyweight. |
pymodbus | https://github.com/riptideio/pymodbus/ | pyserial | Support modbus TCP/RTU/ASCII, master and slave. Heavyweight. |
minimalmodbus | https://github.com/pyhys/minimalmodbus | pyserial | Only support Modbus RTU and ASCII, and only work in master(clinet). Very lightweight. |
uModbus | https://github.com/AdvancedClimateSystems/uModbus/ | pyserial | Support both Modbus client amd server (both TCP and RTU). Don't support Modbus ASCII. Lightweight. |
Here we take the use of modbus_tk as an example.
- Repeat the above steps
- Install the Python environment, modbus_tk, and other dependent packages on LattePanda Alpha & Delta
- According to the ModBus protocol rules of the 8-channel network control relay module, write python code, then control the relay module.
As shown in the figure below, run the Python script on the command line, obtain the device name and control the device turn on and off all the relays in turn
Click to download the Python3 Script.
FAQ
For any questions, advice or cool ideas to share, please visit the DFRobot Forum.