Kennen Sie EIA-485 und DMX-512? - Teil 3

In the First part of this blog series For the RS485 interface, I had a circuit with the microcontroller with Atmega 328, the ZIHATEC RS485 Shield and 6 Potis, a button and a LED connected to a PC to use a Modbus test program on the PC the analog values ​​of the POTATIs and the digital value To read the button or send the on or off signal for the LED to the microcontroller. The sample sketch thus sends the six analog signals and the digital signal of the button via the RS-485 connection to the PC and receives the information from there whether an LED should be switched on or off.

In this part I would like to show how easy it is to make this experimental arrangement to a Raspberry Pi with the ZIHATEC RS485 has to connect and to realize the functionality of the test program with a Python program. To clarify again the declaration of terminology: The term "shield" comes from the "Arduino world" and refers to a component that is put directly on the microcontroller, mostly in the UN design design. In the "Raspberry Pi World" one calls the comparable component for HArdware ATtached on-TOp or Phat for the smaller Pi Zeros, which yes have the same 40-pin PIN strip (J6 header).

As a reminder, I had connected to the microcontroller, as well as the following circuit with six potentiometers on the analog inputs A0 to A5, an LED with series resistor on the digital pin 12 and a button (buttons) connected to PULDown resistance to pin 7 .

Image 1

circuit diagram

The DIP switches, both on the RS-485 shield, as well as on the RS-485-Hat, are set as in the following picture:

Dip switch

The most important microswitch is the first to SW 3: This is enabled by the termination resistor.

Here the explanation of all DIP switches, often referred to as mouse lavier, according to Datasheet of the company ZIHATEC:

S1 - DIP Switch Configuration - Send / Receive Control:




Receiver Always on


Transmitter Connected to Receiver


Automatic DE / RE Control



S2 - DIP Switch Configuration - RS422 / 485 Mode:




Connect y to terminal K2


Connect z to terminal K2


Connect internally y to a


Connect internally z to B

S3 - DIP Switch Configuration - Termination Resistors:



Terminating Resistor On


Not used


4K7 pull-down resistor on b


4K7 pull-up resistor on a

The above switch settings mean:

SW1 is configured to automatically switch between transmitting and receive mode. The software does not have to worry about it.

SW2 is configured for the operating mode RS485. Internally connected to the switches 3 and 4 transceivers and receivers of the RS422 chip.

At SW3 Is only the termination resistor switched on. With the switches 3 and 4 additional resistors can be activated, which drag the lines to defined levels.

Next, has a picture of the Raspberry Pi with the RS485. There is also an embodiment in which the 40-pin connector strip is equipped with a so-called stacking header. Then the pins as on the Raspberry Pi are freely accessible and can be included in the project. In addition to the power supply (3,3V and 5V and GND), only TX (GPIO14), RX (GPIO15) and possibly GPIO18 are used.

The following note applies only to Raspberry Pi 4 with which has modified since October 2021:

Alternatively, in the current version of the has in combination with a Raspberry Pi 4, the UART3 (TX = GPIO4, RX = GPIO5 and GPIO6 to switch to switching) can be used. The configuration takes place in this case by soldering jumper on the back. Presetting is always UART1.

Pi with

The connection between the shield and the has only of a twisted two-wire line. While the line in the experimental setup is only 20 cm long, it can be like in Part 1 Be described up to 1000 m long, and the number of devices can be up to 32 instead of two. And by the galvanic separation, adverse environmental conditions such as voltage fluctuations or overvoltages may occur without damaging microcontrollers or Raspberry Pi.

You connect the bushings B with B and A with A, the other three connections remain free. If a manufacturer uses the terms R + and R or T + and T-, + is connected to A and - with B.


In the Raspberry Pi configuration, we activate the serial interface and then restart the PI.

Raspberry pi configuration

At this point, it must not be concealed that the old, slipped COM interface on GPIO14 (PIN 8) and GPIO15 (pin 10) can cause problems with very low or very high baud rates as well as for devices that require a very stable baud rate. Who can do without Bluetooth and wireless, should therefore use the LP011 UART. Details can be found e.g. on the website of I myself did not follow this approach.

In order not to reinvent the wheel, we use a program library (Python module) for communication between Raspberry Pi and the microcontroller. Incidentally, the sketch for the MC remains unchanged Part 1.

The recommended Python module for the Modbus is called minimum mode and is installed as follows.

Open the terminal and give you "PIP3 INSTALL -U minimum modea.

Then we open our Python Editor idle3 or Thonny. At the beginning of the program, the modules are imported, then an object for accessing the MODBUS is instantiated and the most important settings made. The methods used from the MiniMalModBus module are Read_register for registers 0 to 5 and 7, the register 6 for the LED is with Write_register described.

 import minimum mode
 from time import sleep
 instrument = minimum mode.instrument('/ dev / serial0', 1)  # Port name, slave ad $
 instrument.serial.baud rate = 9600         # Baud
 instrument.Fashion = minimum mode.Fashion_rtu
 LED = False
 whiler True:
     for I in ratchet(6):
         analogous = instrument.Read_register(I, 0)  # Registererumber, Number of Decim $
         print("Analog Value",I," = ",analogous)
     button = instrument.Read_register(7, 0)
     print("Button Status =",button)
     ## SET ON BOARD LED ON ##
     LED = emergency LED
     instrument.Write_register(6, LED, 0)  # Registererumber, Value, Number of Decima $

The output of the data takes place with one second pause in the shell. With each pass, the LED is turned on or off. During data transmission, the RX and TX LEDs also light up on both devices.

Python Shell

Do not let the term Minimum mode lead to the mistake. The manual comprises 142 pages. So the Python module is more powerful than the name suggests.

Conclusion: With the ZIHATEC RS485-Hat you can connect the Raspberry Pi with Modbus-enabled devices (Industry Control and Building Technology). Due to the galvanic separation between the Pi and the RS485 bus, malfunctions or damage to the Raspberry Pi are avoided. It controls both half-duplex operation (RS485) as well as the RS422 (full duplex) mode. In contrast to the RS232 interface, more than two devices can also be connected to larger distances.

Basically, the ZIHATEC RS485 has not only for Modbus applications, but also for DMX (lighting technology, See part 2 of this series), NMEA0183 (Maritime Applications), Pelco (video surveillance) and much more.

As with the RS485 shield on the microcontroller, I would now also like to serve my DMX LED spotlight with the Raspberry Pi. If that works, theaters and discotheques for lighting technology can change to both the purchase as well as in operation inexpensive Raspberry Pi.

Projects for beginnersRaspberry pi

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN