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

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 as well as 6 pots, a button, and an LED to a PC to use a Modbus test program on the PC. to read the button or to send the switch-on or switch-off signal for the LED to the microcontroller. The example sketch, therefore, sends the six analog signals and the digital signal of the button via the RS-485 connection to the PC and from there receives the information on whether an LED should be switched on or off.

In this part, I would like to show how easy it is, this test arrangement to a Raspberry Pi with the Zihatec RS485 has to connect and implement the functionality of the test program with a Python program. To clarify the explanation of terminology again: The term "Shield" comes from the "Arduino world" and describes a component that directly on the microcontroller, mostly in the design of the Uno, is put. In the "Raspberry Pi World," the comparable component is called for HArdware Attached on-TOP or Phat for the smaller PI Zeros, which have the same 40-pin PIN bar (J6 header).

As a reminder: I had put the Shield on the microcontroller, as well as the following circuit with six potentiometers at the analog inputs A0 to A5, an LED with resistance to the digital pin 12, and a button (button) with pulldown resistance to pin 7.

Image 1

circuit diagram

The DIP switch, both on the RS-485-Shield and on the RS-485-HAT, is set as in the following picture:

Dip switch

The most important micros switch is the first on SW 3: This activates the final resistance (Termination Resistor).

Here is the explanation of all DIP switches, often referred to as mouse clavier, according to the Zihatec datasheet:

S1 - DIP Switch Configuration - Send/Receive Control:

Channel

Description

1

Receiver Always On

2

Transmitter connected to receiver

3

Automatic de/Re Control

4

De/re control via GPIO18


S2 - DIP Switch Configuration - RS422/485 fashion:

Channel

Description

1

Connect Y to Terminal K2

2

Connect Z to Terminal K2

3

Connect internally y to a

4

Connect internally z to b


S3 - DIP Switch Configuration - Termination Resistors:

Channel

Description

Termination Resistor on

2

Not used

3

4K7 pull-down resistor on b

4

4K7 pull-up resistor on a


The above switch settings mean:

SW1 is configured in such a way that it is automatically switched between transmission and reception modes. The software does not have to worry about it.

SW2 is configured for the operating mode RS485. Internally, switches 3 and 4 transceiver and receivers of the RS422 chips are connected.

At SW3 Only the final resistance is switched on. With switches 3 and 4, additional resistors can be activated that draw the lines to defined levels.

Next has a picture of the Raspberry Pi with the RS485. There is also a version in which the 40-pin connector strip is equipped with a so-called stacking header. Then the pins are freely accessible as on the Raspberry Pi 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, if necessary, GPIO18 are used.

The following note only applies to Raspberry Pi 4 which was modified in October 2021:

Alternatively, the UART3 (TX = GPIO4, RX = GPIO5, and GGF GPIO6 for switching) can also be used in combination with a Raspberry PI 4. In this case, the configuration is carried out by Lötjumper on the back. Presentation is always UART1.

Pi with

The connection between the Shield and that has only a twisted two-core line. While the line in the test setup is only 20 cm long, it can be Part 1 Described as up to 1000 m long, and the number of devices can also be up to 32 instead of two. And the galvanic separation can also occur in adverse environmental conditions such as voltage fluctuations or overvoltages without damaging microcontrollers or Raspberry PI.

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

Construction

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

Raspberry Pi configuration

At this point, it should not be kept silent that the old, slimmed-down COM interface on GPIO14 (PIN 8) and GPIO15 (PIN 10) with very low or very high baud and devices that require a very stable baud rate can cause problems. If you can do without Bluetooth and wireless, you should use PL011. Details can be found on the website of Abelectronics.co.uk. I did not follow this approach myself.

In order not to have 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 in Part 1.

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

Open the terminal and give "PIP3 Install -U MinimalModbus a.

Then we open our Python editor-Idle3 or Thonny. At the beginning of the program, the modules are imported, then an object for access to the Modbus is instantiated and the most important settings are made. The methods used from the Minimal Modbus module are Read_ Register For registers 0 to 5 and 7, the register 6 for the LED is with write_ Register described.

 import minimal modbus
 From time import sleep
 
 instrument = minimal modbus.instrument('/dev/serial0', 1)  # port name, slave ad $
 instrument.serial.baud rate = 9600         # Baud
 instrument.Fashion = minimal modbus.Fashion_rtu
 LED = False
 
 while True:
     ## Read Analog Values ​​and Button Status ##
     for I in range(6):
         analogous = instrument.Read_ Register(I, 0)  # Registersrumber, Number of Decim $
         print("Analog value",I," = ",analogous)
     button = instrument.Read_ Register(7, 0)
     print("Button status =",button)
 
 
     ## Set on Board Led on ##
     LED = need LED
     instrument.write_ Register(6, LED, 0)  # Registration, value, Number of Decima $
     sleep(1)

The data is issued with a one-second break in the Shell. With each round, the LED is switched on or off. During the data transmission, the RX and TX LEDs also shine quasi-synchronous.

Python Shell

Don't let the term Minimal Modbus mislead. The manual for this comprises 142 pages. The Python module is therefore more powerful than the name suggests.

Conclusion: With the Zihatec RS485-HAT you can connect the Raspberry Pi to Modbus-enabled devices (industrial control and building management). Due to the galvanic separation between the PI and the RS485 bus, malfunctions or damage to the Raspberry Pi are avoided. It masters both the half-duplex operation (RS485) and the RS422 (full duplex) mode. In contrast to the RS232 interface, more than two devices can also be connected via larger distances.

Basically, the Zihatec RS485-HAT is not only suitable 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 like to operate my DMX LED spotlight with the Raspberry PI. If this works, theaters and discotheques can change the lighting technology to the inexpensive Raspberry Pi both in the purchase and in operation.

Projekte für anfängerRaspberry pi

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. ESP32 jetzt über den Boardverwalter installieren - AZ-Delivery
  2. Internet-Radio mit dem ESP32 - UPDATE - AZ-Delivery
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1 - AZ-Delivery
  4. ESP32 - das Multitalent - AZ-Delivery