Using ESP32 PLC, M-Duino and Ardbox with OpenPLC

September 6, 2024 by
Boot & Work Corp. S.L., Arnau Tena

With Industrial Shields' Arduino and ESP32 based PLCs integrated into OpenPLC, we can now program them more easily than ever, without any necessary workarounds.

Previous blogs

This blog is part of a series of blogs about OpenPLC on Arduino and M-Duino. If you still have not familiarized yourself with the software, we recommend you go through the previous blogs first:

First steps with OpenPLC

Modbus on Arduino with OpenPLC

OpenPLC on M-Duino 42+

Mapping any M-Duino on OpenPLC

MQTT on M-Duino with OpenPLC

HTTP on M-Duino with OpenPLC

MQTT on M-Duino with OpenPLC and Raspberry PLC

Live debugging with OpenPLC

Hardware used

For this blog, we used an M-Duino 42+, but you can use any M-Duino PLC, Ardbox or ESP32 PLC as long as you select the correct model in OpenPLC.

Software

To implement Industrial Shields' PLCs into OpenPLC we need to install a mod, which you can download from here:

To install it, drag the contents of the zip into "OpenPLC_Editor\editor\arduino" and replace all files. The "OpenPLC_Editor" folder can usualy be found in your user folder.

This mod works with the current version of OpenPLC as of 23/09/2024.

IOs addressing

As explained in the First steps with OpenPLC and Arduino blog, OpenPLC uses the IEC 61131-3 addressing for all of its inputs and outputs. Digital IOs use two numbers for indexing, while analog IOs use onlly one. This is further explained here. This is how we've mapped the IOs by default:

  • Digital inputs: Since they use two numbers for indexing digital IOs, we've mapped them so that they match the indexing of the PLC, meaning that IX1.4 will correspond to I1_4. To achieve this we've used padding pins that are ignored by OpenPLC.
  • Digital outputs: Same as with the digital inputs, we've used padding to make them match the indexing of the PLC. Relays are mapped as digital outputs.
  • Analog inputs: OpenPLC only uses one number to index analog IOs, so we can't use any padding.
  • Analog outputs: Same as with the analog inputs, no padding. Outputs that can be switched between digital and analog are, by default, defined as analog. Further below we explain how to switch them correctly.

You can check the exact addressing by going into the "Transfer Program to PLC" menu, selecting the correct board and then going into the "I/O Config".

Switching analog outputs

To switch an analog output to digital we have to go to the "I/O Config" menu. If we want to switch the A0_5 output of the first analog zone of the M-Duino 58+ to digital, we have to replace A0_5 with 99, and then, in the Digital outputs, replace the first 99 with Q0_5. This way its IEC address, QX0.5, will still match the real PLC address, Q0_5.


To do the same with a relay zone is slightly different. If we want to switch the A0_0 output of the first relay zone of the M-Duino 57R+ to digital, we have to replace A0_0 with 99 and then, since the relay outputs fill every digital output layer, we add Q0_0 at the end of the digital outputs. This means the IEC address, QX3.0, will not perfectly match the real PLC address, Q0_0, it will have an offset in the first index.

In any case, you'll also have to make sure the physical switch is configured correctly, ON is for digital, OFF is for analog:

Arduino extensions

The ESP32 PLCs, M-Duinos and Ardbox PLCs have been implemented to make use of Industrial Shields' libraries. This allows us to program the PLCs with Arduino extensions like if we were using Industrial Shields' libraries in Arduino IDE. Make sure your OpenPLC Editor is up to date to be able to use Arduino extensions.

To create an Arduino extension, with a project already opened, click on the grey plus icon and select "Arduino extension".

Here's an example code you can use to try to write on a digital output:

void sketch_setup()
{
    pinMode(Q0_0, OUTPUT);
}

void sketch_loop()
{
    digitalWrite(Q0_0, HIGH);
    delay(500);
    digitalWrite(Q0_0, LOW);
    delay(500);
}

Interacting with the variables of the ladder diagram from the Arduino extension will be explained in the next blog:

Creating external variables in OpenPLC to interact with an Arduino extension

​Search in our Blog

Boot & Work Corp. S.L., Arnau Tena September 6, 2024
Share this post

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>