RS485 Connector Expansion Shield for LattePanda V1 WiKi - DFRobot

Introduction

Specification

1

Application

The RS485 interface can be easily used in the Windows environment. (Compatible with Linux environment)

Board Overview

Pinout

For LattePanda V1 Pin Definition, please refer to the Official WiKi.

RS485 Communication Protocol

RS485 communication is one of the typical serial communication standards.

RS485 interface is widely used in industry because of its good noise immunity, long transmission distance, multi-station capability and simple wiring.

RS485 communication protocol only defines the voltage, impedance and other electrical characteristics of transmission, but does not define the software protocol. The data signal adopts differential transmission mode, so it has the ability to suppress common mode interference. The bus transceiver has high sensitivity and can detect voltage as low as 200mV. RS-485 is very convenient for multi-point interconnection and can save many signal wires. It uses a pair of twisted pairs, one of which is defined as A and the other as B. Generally, the positive level between A and B is + 2 ~ + 6V, which is in the logic 1 state, and the negative level is - 2V ~ 6V, which is in the logic 0 state. The maximum transmission distance is about 1200 meters, and the transmission rate is inversely proportional to the transmission distance. Only in a very short distance can the highest transmission rate be obtained. RS485 needs two terminal resistors whose resistance value should be equal to the characteristic impedance of the transmission cable (generally 120Ω). In short distance transmission, there is no need for terminal resistance. Terminal resistors should be connected at both ends of the transmission bus.

ModBus Communication Protocol

Modbus protocol is a master/slave architecture protocol. It has one master node and the other nodes using Modbus protocol are slave nodes, each with a unique address. A MODBUS command contains the Modbus address of the device to be executed. All devices will receive commands, but only the device at the specified location will execute and respond to the commands (except for address 0, which is a broadcast command. All devices that receive the commands will run, but will not respond to the commands). All MODBUS commands include check code to make sure that the arrived command is not damaged. The basic MODBUS command can instruct an RTU to change a value of its register, control or read an I/O port, and ask the device to send back one or more data in its registers.

There are many variants of Modbus protocols:

Tutorial

This tutorial will demonstrate how to use LattePanda to control the DFR0290 8 Channel IoT Ethernet Relay Controller by RS485 shield.

Requirements

Connect the Shield and LattePanda V1

Connection

Use the Copper Columns and screws to fix the shield on LattePanda Board.

Connection Diagram

1. Using Upper-computer Software

  1. Connect the LattePanda with RS485 connector shield, turn it on.
  2. Power on the 8 Channel IoT Ethernet Relay Controller.
  3. Open the DFRobot Upper-computer software on LattePanda, select COM1, and set baud rate to 115200.
  4. The relay module can be controlled by the uppper-computer software.

Upper-computer Software

Result

2. Using Serial Debugger

  1. Repeat the steps above.
  2. Use the serial debugger to send the related commands to control the relay module according to the user-defined communication principle of the 8 channel relay controller.

Serial Debugger

Turn on/off the relay No.1, shown as below.

3. Using Python ModBus Library

The following are the popular ModBus thrid-party Python libraries at present.

Name Source Code Third-party Dependencies Main Function
modbus_tk https://github.com/ljean/modbus-tk Pyserial Support modbus TCP and RTU, both master and slave. Not 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). Not support Modbus ASCII. Lightweight

Here we will take modbus_tk as an example.

  1. Repeat the steps above.
  2. Install Python and modbus_tk and other dependency packages on LattePanda.
  3. Write Python codes to control the relay modudle according to the ModBus protocol principle of the 8 channel relay controller.

Run Python script to get device name and control device to turn on/off all relays in order, shown as below:

7

8

Click to download the Python3 Script Sample.

FAQ

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

More Documents