PLC Starter Kit Demo Application
The PLCD Starter Kit consists of an 8 channel analog input module, a 4 channel relay output module and the Raspbery Pi control module. The control module provides a solid 5.14 VDC for the Raspberry Pi, RS485, a Real Time Clock and buffered I/O for chip selects and the I2C buss.
Here is a picture of the demo application.

The module used from left to right are:
• PI-SPI-DIN-8AI 8 channel analog input module
• PI-SPI-DIN-4KO 4 channel relay output module
• PI-SPI-DIN-RTC-RS485 Raspberry Pi control module and RPi 4
• VP-EC-RDU Modbus RTU LCD Display
• FLUKE 787 Process Meter for generating the 4-20 mA signal
For the demo application, a simple control algorithm is used in the Python program.
• Read all 8 analog inputs (each input is 4 - 20 mA)
• If any of the analog inputs is greater or equal to a relay setpoint, that relay is turned on.
In the demo, the 4 relays are set to K1 = 8 mA, K2 = 12 mA, K3 = 16 mA, K4 = 20 mA.
This basic kind of algorithm is used in all kinds of applications such as gas detection, level control, ventilation control, temperature control, etc.
Here is the demo application Python program. Ensure the latest version of libwidgetlords is installed and the latest version of modbusd is installed. Refer to the application notes:
https://widgetlords.com/pages/getting-started-with-pi-spi-libraries
https://widgetlords.com/pages/rs485
Here is the Python program:
#!/usr/bin/python3
from time import sleep
from widgetlords.pi_spi_din import *
from widgetlords import *
import minimalmodbus
display = minimalmodbus.Instrument('/tmp/modbus', 100) # port name, slave address (in decimal)
display.serial.baudrate = 19200
inputs = Mod8AI(ChipEnable.CE1)
relays = Mod4KO(ChipEnable.CE3)
ad = [0]*8
ma = [0]*8
spk1 = 8.0
spk2 = 12.0
spk3 = 16.0
spk4 = 20.0
k1 = 0x01
k2 = 0x02
k3 = 0x04
k4 = 0x08
while True:
for i in range(8):
ad[i] = inputs.read_single(i)
for i in range(8):
ma[i] = counts_to_value(ad[i], 745, 3718, 4, 20 )
# Get peak mA value from all 8 channels
mapeak = 0
for i in range(8):
if ma[i] > mapeak:
mapeak = ma[i]
relay_status = 0
if mapeak >= spk1:
relay_status += k1
if mapeak >= spk2:
relay_status += k2
if mapeak >= spk3:
relay_status += k3
if mapeak >= spk4:
relay_status += k4
lcd1 = ("A1= %5.2f A2= %5.2f " % (ma[0], ma[1]))
lcd2 = ("A3= %5.2f A4= %5.2f " % (ma[2], ma[3]))
lcd3 = ("A5= %5.2f A6= %5.2f " % (ma[4], ma[5]))
lcd4 = ("A7= %5.2f A8= %5.2f " % (ma[6], ma[7]))
try:
display.write_string(0, lcd1, 10)
display.write_string(10, lcd2, 10)
display.write_string(20, lcd3, 10)
display.write_string(30, lcd4, 10)
except Exception as e:
print(e)
relays.write(relay_status)
print("")
sleep(0.5)