PLC- Touchberry PI RS485/RS232

PLC- Touchberry PI RS485/RS232

In this post we are going to learn how to send data between Industrial Shields PLCs and TouchBerry PI PanelPc. In order to apply or implement the functionalities and examples described, the TouchBerry PI is assumed to include the suitable preloaded image. All PanelPC acquired as of 21-08-2015 will include the required image. For those PanelPC  acquired before 21-08-2015 the procedure to install the new compatible image will be provided via email.

Touchberry  PI

Touchberry PI supports TTL (5V-0V) serial communication through the D37 connector. MAX485 and  MAX232 components are required to adapt to RS232/RS485 protocols.

Table 1.

Pin D37 Function Protocol
22 GND RS2323/485
23 TX RS2323/485
34 RX RS2323/485
Any GPIOS (for the example 25) Control/chip Rs485

Table 2. Raspberry PI 2B  GPIOS –> ToucBerry PI D37 Connctor

24 28
23 27
17 6
18 25
27 7
22 8
25 30
14 4


Industrial Shields PLCs provide the A B connection for RS485 protocol. Raspberry PI 2B requires to configure the control/chip pin (any GPIOS) to connect to the MAX485 component. For this example we take pin 25 from the TouchBerry PI D37 connector (GPIOS 18)  as chip/control pin. Steps to configure the 25 PIN as chip/control on Raspberry Pi.

  1. Open Touchberry PI console:
  2. User:pi
  3. Pass:raspberry
  4.  Write the following instructions
sudo su                                            //acquire superadmin rights

echo “18” >/sys/class/gpio/export

echo out>/sys/class/gpio/gpio18/direction // define GPIOS18 (pin 25 D37) as control/chip

echo 1 >/sys/class/gpio/gpio18/value         // set control/chip pin to transmit state (HIGH) 1

exit //

With the code above the Raspberry PI RS485  protocol is set-up and configured to transmit state.

Table 3. Touchberry PI to MAX485 connection reference

D37 connector   MAX485
22 (GND) –> RE
23 (TX) –> DI
24  (RX) –> RO
25  (CS) –> DE

*TX and RX cables connection is not cross between D37 to MAX485 Now to test that the communication between PLC and Rasberrry PI is enabled we are going to send some sentences through RS485 and RS232.

  1. Open minicom on Touchberry PI.
  2. Type the following:
 sudo minicom -D /dev/ttyAMA0 -b 4800

Any code written on the console should be send  through RS485 to the PLC. With the Serial Monitor on the PLC we  can see the code typed on the Touchberry PI console. The Arduino code to read messages on the RS48 Bus is here. Another example shows the  Arduino code to send data to the Touchberry PI through the RS485 bus.


For RS232 there is no control pin, compared to RS485, so  no configuration instructions are required.  To connect the PanelPC to the  MAX232 the pins 22 (GND), 23 (TX), 24 (RX) (Table 4) are to be linked to to the  MAX232 pins GND, TX, RX Table.4

D37 connector   MAX232
22 (GND) –> GND
23(TX) –> TX
24(RX) –> RX

*TX and RX cables connection is not cross between D37 to MAX232.

Los comentarios están cerrados