Connecting PLCs to IoT devices like the Raspberry Pi in order to read and write data to a PLC generally requires the programming knowledge needed to develop communication drivers.
But in today's article I'll show you how you can connect and communicate with a PLC without any programming knowledge.
The case for IoT to PLC communications
Those not familiar with industrial automation applications and Programmable Controllers might be wondering why you wouldn't just connect your Raspberry Pi directly to sensors and eliminate the PLC?
While it's technically possible to do this, in most applications sensors are already installed and connected to a PLC that is also controlling the system.
In those situations, there's typically no provisions built into the equipment that would allow you to install additional sensors for a second device.
And while some might suggest connecting the Microcomputer to the same sensors the PLC is wired to, since most sensors only have a single output this would often require adding additional devices like signal splitters or converters.
In practice, the most convenient way to collect all the data coming from existing sensors that are already wired into a controlling PLC is to collect that data from the PLC itself.
Pros and Cons of IoT to PLC Communications
There are definitely advantages to setting up communications with a system's PLC, as apposed to reading the system's sensors directly.
The most obvious of which is that you also gain the option to write data back to the PLC. This means the data your analytics provide can actually be sent to the PLC to effect the control of the process.
One disadvantage of communicating with the PLC is that you'll typically need to purchase the specific PLC's communications driver software. And since most PLC vendors use their own unique communications protocols (Ethernet/IP, ProfiNet, etc.) you may find you need to purchase multiple drivers from multiple vendors.
But in this article I'll walk you through how to avoid the cost of commercial driver packages by showing you how to setup communications from your Raspberry Pi to an Allen-Bradley PLC using a free PLC driver.
How our journey began…
When we started our journey to connect the plant floor to our ERP systems, our team didn't really have any PLC knowledge as our team was comprised of several mechanical and software engineers.
In fact, most of us hadn’t even seen an actual PLC before starting on this journey.
What we did have was a requirement that we connect our ERP system with the PLC's in our facility, and with that in mind we started searching for solutions.
After trying several different solutions, we settled on the Rasberry Pi micro-computer as our IoT device, with Node-RED as our development environment, and the PCCC-Contrib driver for our IoT to PLC communications.
In the rest of the article, I'll explain how we setup our Raspberry Pi to communicate with our first PLC, which happened to be an Allen-Bradley ControlLogix.
Raspberry Pi IoT Communication Setup for A-B ControlLogix PAC
As I stated above, our system used a Raspberry Pi as our IoT device, and on it we installed Node-RED, a visual development environment.
Node-RED was originally developed by IBM as a programming tool for connecting hardware devices together, and provides a “web browser based” flow editor where you can just drag and drop different components and then wire then together.
- Tip: Use this link to get started using Node-RED for Windows
- Tip: Use this link to get started using Node-RED on Raspberry Pi
While there are several drivers you can use to connect to an Allen Bradley PLC, after trying many of them we found the node-red-contrib-pccc to be the best because of its simple structure and efficient functionality.
- Tip: Use this link to learn more about node-red-contrib-pccc
To add node-red-contrib-pccc nodes to your Node-RED workstation, first install Node-RED onto your Raspberry Pi computer.
Next, run the Node-RED server and go to http://localhost:1880 to access your Node-RED Flow Editor from your browser.
From here select “Options” (found on the top right of the page,) then go to “Manage Palette.” Then on the “Install” tab search for PCCC. Now find node-red-contrib-pccc in the search results and install it:
Note: Contrib-pccc gives you two nodes: One is “pccc-in” to read the values, and the other is “pccc-out” to write the values.
Next, in your “Input Nodes” find the pccc input node, and drag and drop it into your project's work-space where you'll be prompted to enter in the details like the IP Address of the PLC, and Variables Details whose values you want to read or write:
Note: The pccc input node also has a feature where it only provides an output when the value of PLC’s variable changes. This greatly reduces unnecessary server calls for the same value, improving the efficiency of the system.
Now physically connect your Raspberry Pi to your A-B PLC via Ethernet, and then connect the pccc communication node to a debugger in Node-RED to see the PLC values:
With that done, we've proven the communications from our PLC to our IoT device are working using Node-RED and pccc nodes.
In future articles I plan to cover the details of how you use this setup to transfer real-time data from the PLC to the Server so you can run analytics on it with AWS IoT.
Written by Nilesh Soni
Provider of custom ERP solutions and Freelance Writer
Edited by Shawn Tierney
Have a news tip? Share it with us here.
Have a question on this topic? Click here to scroll down to the comment link
Enjoy the benifits of membership! Insider news, rewards, & more: Patreon.com/automation
- How To Register A Thing In AWS IoT - June 4, 2020
- IoT Architecture: Allen-Bradley PLCs to Amazon AWS - April 30, 2020
- Getting A-B PLC Data Into A Raspberry Pi - October 23, 2019
Click HERE to scroll down to view or leave comments