Use the Raspberry Pi as a PLC for Automation

If you thought the popular single board computer, the Raspberry Pi (RBPi) is suitable only for children learning to write programs in computer languages, you need to think afresh. Vytas Sinkevicius is using the RBPi as a PLC for applications in automation. Increasingly, others are also using the RBPi as a PLC replacement in automation applications.

Basically, the RBPi replaces the actual PLC, and works as the main controller. The design specifications for the RBPi PLC are:

  • 8 digital Inputs
  • 16 Analog Inputs each supporting 4-20 mA current loops
  • 4 Analog Outputs each supporting 4-20 mA current loops
  • 12 Relay Outputs for control
  • 90-264 VAC Power Supply
  • 24 VDC Power Supply (Field)
  • Real Time Clock
  • Industrial Grade Enclosure

The enclosure has an aluminum back panel with ABS sides and a clear Polycarbonate cover. The cabinet is 14 inches in width, 16 inches in height, and 7 inches in depth. Installation is simple as DIN rail mounting is followed for all modules. While the local wiring employs ribbon cables, for field wiring the center of the panel has been left wide open. The enclosure uses industrial grade terminal blocks with rising clamp screw types.

A Delta Chrome series power supply block powers the unit. The power unit accepts AC voltages from a wide range of 90 to 264 VAC, and supplies an output of 24 VDC, with several safety approvals. While the input 4-20 mA signals are from powered transmitters, all the PI-SPI-DIN modules are supplied by high efficiency switching power supplies.

A PI-SPI-DIN-RTC-RS485 module forms the heart of the system. Apart from supporting the RBPi, the module also supplies power to the RBPi via the GPIO ribbon cable. For external displays and Modbus I/O modules, there is an RS485 interface and a battery backed Real Time Clock. The PI-SPI-DIN modules also have a buffered 16-pin GPIO bus, which also carries power from the 24 VDC to the modules.

The project has software written in the C language. It emulates a gas detection system with 16 points. There are digital inputs for manual control of fans, and analog inputs for controlling fans with variable speed. The software is undergoing testing presently. It will be published after it is found to work without issues.

Although the total number of IO points is substantial, the GPIO loading on the RBPi is not very high. For instance, the SPI bus uses only three GPIO pins, since the SPI routines allow any arbitrary GPIO lines to be used for chip selects. The I2C bus uses 2 GPIO lines, while the two 4-20 mA modules use two GPIO chip selects. While the PI-SPI-DIN-8DI module uses one GPIO for chip select, the relay modules use an MCP23508 GPIO expander with 4 addresses, but uses only one GPIO chip select. Direction control takes up one GPIO pin on the RS485, while it uses GPIO UART Rx and Tx.

The entire setup of enclosure, power supply, all modules, DIN rails, and RBPi3 cost less than $600. This easily rivals any PLC on the market with the same number of IO points.