Shop OBEX P1 Docs P2 Docs Learn Events
Propeller to Codesys revisted — Parallax Forums

Propeller to Codesys revisted

fixmaxfixmax Posts: 91
edited 2015-01-19 15:19 in Propeller 1
Hello Folks,

I've been working on a integrating a Propeller with a Raspberry Pi running Codesys. I've been a big fan of Codesys for years like this I posted a few years ago:

http://forums.parallax.com/showthread.php/124022-Propeller-as-a-target-for-Codesys?highlight=codesys

Well, recent developments have fortunately brought this capability to possibility, and I wanted to share my results.

Codesys, as you may or may not know, is a high-end industrial PLC software package that normally costs several thousand dollars to get up and running.

Recently, they began offering Codesys for the Raspberry Pi for use as a teaching platform. This allows a Raspberry Pi to run basically as a PLC that is programmable with IEC-6-1131 languages such
as structured text, ladder, function block, sequential function charts (SFC), etc.

They have included drivers in the package, to allow access to the onboard Pi hardware. This includes SPI, I2C, and the GPIO, serial port, and the RPi camera, as well as industrial protocols such as Modbus Master/Slave, EtherCat, etc. They have even included network variables, which is the equivalent of producer/consumer tag lists, similar to ROS's producer consumer model, and is way more capable than a simple producer/consumer tag, such as that used with a Rockwell PLC.

These network variables give the capability of easily networking multiple Pis in a system, in addition to using Modbus Master/Slave networking. One project contains all of the nodes in the system and makes for a very nice distributed control system. I paid a pretty good premium 5 or 6 years ago for this capability, and they are doing it with the PI almost free.

The Codesys has a two hour demo limit, upon which it runs the CPU as 100%, requiring a reboot. They will sell a license for the PI at about $50 or so. Yes, I know it's not free. But this is industrial grade PLC software, normally costing $$$, so, for me, $50 is a bargain - I can finally afford it for my home hobby projects, where I couldn't afford the full PLC based version.

Anyhow, to get to my final point, I have integrated the Propeller as an I2C slave, using the standard OBEX I2C object originally written by Chris Gadd. I'm just running a simple slave, at the default of 400 kHz. I modified one of the several device descriptor files that they include for several Adafruit I2C components. I only created 6 bytes IN, and OUT, but it illustrates the method, and can be further adapted. The same method I used could be also applied to the SPI drivers they have, but for me I preferred the I2C bus, due to its simplicity. Further work could include the serial, and SPI if needed, although to be honest serial in IEC is pretty clunky - I prefer using the serial out of a Prop to be honest, and just get the data into the Prop from the Pi over the I2C.

What this opens up in the Codesys / Linux / Pi world for me, is a deterministic IO front end using the propeller. I can run a script from Codesys to perform a firmware update to the Pi as well, using Heater's Pi binaries for that ( I believe it was Heater - but I may be wrong, forgive me if that's so). To me, it basically blows the doors off the Rpi in terms of hardware io. The nice thing is, that this could probably even be adapted quite easily for Bill Henning's Robo Pi as well. By bringing in 2 wires from the PI-I2C header, with some pull-up resistors, back to some available pins on one of the expansion pins, you could easily use that board as well. There is actually some possible synergy here as well, since Bill could add the I2C slave object to a free cog (if there is any), and this would allow Bill's firmware to work as is with the Codesys running in the Pi. Think RC servos / Ping right into the PLC project..

The Codesys has a really good visualization module as well. It can generate a web server that hosts a very nice HMI-style interface, that is accessible via a web page - even using a smart phone browser.

Below is the attached files to do this. I have included a screen shot demonstrating the Pi online with Codesys, and a terminal window with the Pi streaming input and output register info at 115.2K. I'll add the spin file tonight, but its pretty simple. I just wrote some test values to 6 registers with the Prop, starting at 0 to 5, as outputs to the Pi. Register 6 to 11 are used for the outputs from the PI, and inputs to the Prop.

Let me know if there is any other interest, this is a very exciting prospect for me, seeing these come together - its almost a perfect storm for my applications.
Sign In or Register to comment.