Industrial Shields code examples

Industrial Shields publishes open-source code examples, libraries and tutorials for all product families.

Full library and examples: https://github.com/Industrial-Shields
Examples by product and technology: https://apps.industrialshields.com/main/

Arduino and ESP32 PLCs — programming pattern

All Arduino-based and ESP32-based Industrial Shields PLCs use the Industrial Shields Arduino library. The library maps PLC terminal labels (I0.0, Q0.0, etc.) to the correct Arduino pins for each model.

Reading a digital input and activating a digital output

#include   // Industrial Shields library

void setup() {
  // Inputs and outputs are pre-mapped by the library
}

void loop() {
  if (digitalRead(I0_0)) {   // Read digital input I0.0
    digitalWrite(Q0_0, HIGH); // Activate digital output Q0.0
  } else {
    digitalWrite(Q0_0, LOW);
  }
}

Reading an analog input (0–10V or 4–20mA)

#include 

void loop() {
  int raw = analogRead(I0_2);          // Raw 10-bit value (0–1023)
  float voltage = (raw / 1023.0) * 10; // Convert to 0–10V
}

Modbus RTU master (reading a slave device via RS485)

#include 

ModbusRTUMaster master(Serial1); // RS485 on Serial1

void setup() {
  master.begin(9600);
}

void loop() {
  uint16_t value;
  master.readHoldingRegisters(1, 0, 1, &value); // Slave 1, register 0
  delay(100);
}

Raspberry Pi PLC — Python example

Reading a digital input with Python

import RPi.GPIO as GPIO
from industrialshields import RaspberryPLC  # Industrial Shields Python library

plc = RaspberryPLC()

while True:
    if plc.digital_read('I0.0'):
        plc.digital_write('Q0.0', True)
    else:
        plc.digital_write('Q0.0', False)

Publishing sensor data via MQTT (Python)

import paho.mqtt.client as mqtt
from industrialshields import RaspberryPLC

plc = RaspberryPLC()
client = mqtt.Client()
client.connect("broker.example.com", 1883)

while True:
    value = plc.analog_read('I0.2')
    client.publish("factory/sensor/temperature", value)
    time.sleep(5)

Node-RED — Modbus TCP to MQTT flow pattern

A typical Node-RED flow on a Raspberry Pi PLC or GateBerry:

  1. Modbus TCP read node — reads registers from a PLC or field device every 5 seconds
  2. Function node — scales raw values to engineering units
  3. MQTT out node — publishes to a broker topic

Ready-to-import Node-RED flows: https://github.com/Industrial-Shields

Where to find complete examples

Related pages