Note: this blog was made before M-Duino was officially implemented into OpenPLC. For an updated guide on how to use M-Duino with OpenPLC, visit this blog:
Using ESP32 PLC, M-Duino and Ardbox with OpenPLC
Tutoriales de OpenPLC imprescindibles para programar un PLC Arduino
Before we begin looking into how to incorporate M-Duino 42+, puede que quieras echar un vistazo a dos blogs anteriores que publicamos sobre OpenPLC, especialmente si aún no te has familiarizado con el software.
This blog will get you started on how to use OpenPLC to program PLCs:
First steps with OpenPLC
This other one builds upon the last one, it will show you how to use Modbus with OpenPLC:
Modbus on Arduino with OpenPLC
Cómo mapear los pines I/O del M-Duino 42+ en OpenPLC
The M-Duino 42+ uses an Arduino Mega, like the one we used for our previous two blogs, but we can't just plug it to a laptop and upload code to it with OpenPLC, it will not work. This is because the way OpenPLC maps the IOs does not match with the IO configuration of the M-Duino 42+. For example, by defaut OpenPLC maps all the even-numbered pins from 22 to 53 as digital inputs and the odd ones as digital outputs, but M-Duino 42+ uses all pins from 22 to 31 as digital inputs, both odd and even pins.
What we have to do is to change OpenPLC's mapping of the Arduino Mega to match the configuration of the M-Duino 42+. Para ello, abre el ejemplo de parpadeo en OpenPLC Editor como hicimos en los dos blogs anteriores. Luego abre el menú "Transfer Program to PLC" y haz clic en "I/O Config". Aquí puedes configurar todas las IOs digitales y analógicas. Borra todos los números e introduce los siguientes:
- Digital Inputs: 22, 23, 24, 25, 26, 2, 3, 99, 27, 28, 29, 30, 31, 18, 19
- Digital Outputs: 36, 37, 38, 39, 40, 99, 99, 99, 41, 42, 43, 44, 45, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 14, 15, 16, 17, 18, 19, 20, 21
- Analog Inputs: A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11
- Analog Outputs: 4, 5, 6, 8, 9, 7
Given the configuration above, this table describes how OpenPLC will do the addressing:
| Digital Inputs | M-Duino 42+ | IEC 61131-3 | Modbus input |
| 22, 23, 24, 25, 26, 2, 3, 99, | I0.0-I0.6 | %IX0.0-%IX0.6 | 0-6 |
| 27, 28, 29, 30, 31, 18, 19 | I1.0-I1.6 | %IX1.0-%IX1.6 | 8-14 |
| Digital Outputs | M-Duino 42+ | IEC 61131-3 | Modbus coil |
| 36, 37, 38, 39, 40, 99, 99, 99, | Q0.0-Q0.4 | %QX0.0-%QX0.4 | 0-4 |
| 41, 42, 43, 44, 45, 99, 99, 99, | Q1.0-Q1.4 | %QX1.0-%QX1.4 | 8-12 |
| 99, 99, 99, 99, 99, 99, 99, 99, | |||
| 14, 15, 16, 17, 18, 19, 20, 21 | TX3-SCL | %QX3.0-%QX3.7 | 24-31 |
| Analog Inputs | M-Duino 42+ | IEC 61131-3 | Modbus input R |
| A0, A1, A2, A3, A4, A5, | I0.7-I0.12 | %IW0-%IW5 | 0-5 |
| A6, A7, A8, A9, A10, A11, | I1.7-I1.12 | %IW6-%IW11 | 6-11 |
| Analog Outputs | M-Duino 42+ | IEC 61131-3 | Modbus holding R |
| 4, 5, 6, | A0.5-A0.7 | %QW0-%QW2 | 0-2 |
| 8, 9, 7 | A1.5-A1.7 | %QW3-%QW5 | 3-5 |
Do note that the pins 4, 5, 6, 8, 9, 7 are present as both analog outputs and digital outputs. This is because the M-Duino 42+ features switches to swap between using those pins as analogic or digital outputs. You can ignore the 99, it's there to prevent diferent layers from overlapping.
Validación del mapa de direcciones del M-Duino 42+ con una prueba de parpadeo
We will use the blink example to test if the new addressing works properly. The only changes we will make are in the variables table. Bind "blink_led" to the digital output %QX0.0, then create a new bool variable and bind it to the digital input %IX0.0.
Ahora debemos realizar el cableado en el M-Duino. Si consultamos la tabla de mapeo, vemos que la dirección %QX0.0 corresponde al pin de salida Q0.0 del M-Duino, y %IX0.0 corresponde al pin de entrada I0.0. Conecta un cable de Q0.0 a I0.0 y aliméntalo a través de QVdc; no olvides conectar los cables de GND donde sea necesario.
Now everything is ready to do the test. Compile the code and send it to the PLC. On the topside of the M-Duino, you should see the Q0.0 and I0.0 lights blinking together every 500ms. If so, the new address mapping is correct.
Como hemos añadido una variable para %IX0.0, también podrás ver los cambios a través de "Live debug remote PLC". Si no, siempre puedes verificar todas las bobinas de entrada mediante Modbus.
Para aprender a mapear cualquier PLC M-Duino para OpenPLC, consulta el siguiente blog:
Mapping any M-Duino for OpenPLC