RS485 Connector Expansion Shield for LattePanda Alpha&Delta Wiki - DFRobot

1. Introduction

2. Specification

warning_yellow.png

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

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:

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

7.1 Plug the shield into LattePanda Alpha & Delta

Connection

You need to use nylon columns and nylon screws to fix the expansion board and LattePanda.

7.2 Connection Diagram

Connection

7.3 Use host computer software

  1. After connecting Lattepanda Alpha & Delta and RS485 interface extension board, boot up
  2. Power on RLY-8-PoE-RS485 8-channel network control relay module
  3. Open the host computer software produced by DFRobot on LattePanda Alpha & Delta, select COM1 serial port, and set the baud rate to 115200
  4. Use the host computer software to operate the relay module

Host PC Software

Result 1

7.4 Use serial port debugging assistant

  1. Repeat the above steps
  2. 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

Result 2

7.5 Use ModBus debugging assistant

  1. Repeat the above steps
  2. 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:

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.

  1. Repeat the above steps
  2. Install the Python environment, modbus_tk, and other dependent packages on LattePanda Alpha & Delta
  3. 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

Result

Result

Click to download the Python3 Script.

FAQ

For any questions, advice or cool ideas to share, please visit the DFRobot Forum.

More Documents