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 supports TTL (5V-0V) serial communication through the D37 connector. MAX485 and MAX232 components are required to adapt to RS232/RS485 protocols.
|Any GPIOS (for the example 25)||Control/chip||Rs485|
Table 2. Raspberry PI 2B GPIOS –> ToucBerry PI D37 Connctor
|GPIOS||D37 CONNECTOR pin|
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.
- Open Touchberry PI console:
- 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
*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.
- Open minicom on Touchberry PI.
- 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
*TX and RX cables connection is not cross between D37 to MAX232.