MIAplc

The editor's interface is available in Italian and English: pick the language from the drop-down in the toolbar.

What is MiaPLC

MiaPLC (Micro Integrated Automation Programmable Logic Controller) is a PLC built on ESP32 microcontrollers. Three pieces work together:

  • the board: an ESP32 with inputs, outputs and usually Ethernet;
  • the firmware: runs the program in a bytecode virtual machine, scan after scan, and handles network, I/O, clock and diagnostics;
  • the web editor: lives inside the PLC. Open it in the browser with the board's IP address and program in ladder.

The workflow is the one of industrial PLCs: write the program, Compile, Download to cpu, Run, then Online to watch it work.

First steps

  1. Choose a board. A reference board is a good start (see Boards).
  2. Build the firmware with MiaConfig. Draw the board (inputs, outputs, Ethernet, clock), then Generate → Build firmware. The first time it downloads the build tools (internet and about 1 GB of disk needed); after that it just builds.
  3. Flash the firmware. For the first install use <board>-completo.bin with the Espressif tools (a single file at address 0x0). Later updates are done from the editor with the .miaplc package.
  4. Open the editor. Connect the PLC to the network and open its IP address in the browser.
  5. Write your first network, then Compile → Download to cpu → Run → Online.

No board yet? Start with the simulator: it's the same editor, with a simulated PLC in your browser.

The simulator

The simulator is the real editor with a simulated PLC instead of the board. Its virtual machine is the same logic as the firmware, rewritten in JavaScript with the same limits, so a program that works in the simulator works on the board too.

  • In the MOCK PLC panel click inputs I0…I5 to switch them on and off; outputs Q0…Q3 light up when active.
  • RUN / STOP / Reboot act like the board's switch and reset; Errore and Offline simulate a fault and a lost connection.
  • The execution time shown is an estimate: the real one is measured on the PLC.
  • Program and state stay saved in your browser; Reset mock clears everything.

The scan cycle

Like every PLC, MiaPLC repeats the same loop forever:

  1. read the inputs;
  2. run the program from start to end (Main and the FCs it calls);
  3. write the outputs.

So the program never “waits”: every network is evaluated again on every scan. Timers measure time between scans, edges remember the previous scan's state. Scan time and CPU load are shown in Diagnostics and in the system DB.

Blocks: Main, StartUp, FC, DB

BlockPurpose
MainThe main program, run on every scan.
StartUpRun once at power-up or after a Download: initial values, resets.
FC (function)A reusable piece of program with its own interface (inputs, outputs, local variables). Called from Main or from other FCs.
DB (data block)Named, typed variables, including structures and arrays. A DB can be retentive: it keeps its values at power-off.
System DBsCreated by the PLC: board data and system values (scan time, free RAM, network status, first scan…), read-only.

Every block is split into networks, each with a title and comment. Blocks can be grouped in folders.

Areas and addresses

AreaAddressesContents
II0 … I1023Digital inputs (read-only)
QQ0 … Q1023Digital outputs
MM0 … M1023Markers: internal memory bits
TT0 … T255Timers: contact T5 is the output of timer 5
SMSM0 … SM5System bits (read-only, see below)
MB / MW / MDe.g. MW3, MW3.5Memory bytes, words and double words; MW3.5 is bit 5 of word 3
DBe.g. "Plant".levelData block variables, by name

System bits

BitMeaning
SM01 on the first scan only
SM1always 1
SM2always 0
SM310 Hz clock
SM42 Hz clock
SM51 Hz clock

Every address can get a symbol (name and comment) in the symbol table: in the ladder you'll see "Start" above I0.

Data types

TypeRange
BOOL0 / 1
BYTE · USINT0 … 255
SINT−128 … 127
WORD · UINT0 … 65535
INT−32768 … 32767
DINT32-bit signed
UDINT32-bit unsigned
REAL32-bit floating point
TIMEtime in ms, written T#5s, T#1m30s, T#250ms
TIMERa timer whose state lives in a DB variable (doesn't use T0…T255)

DBs and FC interfaces can also use arrays and structures (e.g. "Data".motor.speed).

Ladder instructions

GroupInstructions
ContactsNO, NC, positive / negative edge of an operand, power-flow edge P_TRIG / N_TRIG, NOT, comparison (== <> < > <= >=)
Coilscoil, negated coil, SET, RESET, end of FC (RET)
TimersTON on-delay, TOF off-delay, TP pulse
CountersCTU up, CTD down, CTUD up/down
NumbersMOVE, ADD, SUB, MUL, DIV, MOD, NEG, ABS, MIN, MAX, LIMIT, CONV, SQRT, SQR, SCALE (e.g. 0…27648 → 0…100 %)
WordsAND, OR, XOR, INV, SHL, SHR, ROL, ROR, SWAP
FunctionsFC call, with its parameters

Numeric boxes have EN / ENO: an overflow or a division by zero doesn't stop the PLC, it sets ENO to 0.

FCs in ST and C

A function can also be written as text: ST (Structured Text) or C. You get IF, CASE / switch, FOR, WHILE, REPEAT / do-while, EXIT / break, CONTINUE, RETURN, with auto-completion of variable names, DB fields and symbols. Handy for calculations and recipes, while contact logic stays in ladder.

IF #start AND NOT #stop THEN
    #output := TRUE;
ELSIF #stop THEN
    #output := FALSE;
END_IF;

Online and diagnostics

  • Online: closed contacts and energised coils turn green, timers show elapsed / preset time, boxes show their values.
  • Diagnostics: PLC status, versions, event log, scan times, CPU load, RAM analysis, boot checks.
  • An error in one module doesn't stop the board: it becomes a warning in diagnostics and the PLC carries on.

Boards and MiaConfig

MiaConfig is the configurator: describe the board (inputs, outputs, Ethernet, WiFi, clock, I2C/SPI devices) and it picks the firmware modules and builds it. It runs on Windows, Linux and macOS and installs nothing on the system: everything stays in its folder.

ChipExample configurations
ESP32Olimex ESP32-EVB (with or without DS3231 clock)
ESP32-C3with W5100 or W5500 Ethernet, with or without DS3231
ESP32-S3ESP32-S3-DevKitC-1
ESP32-P4PLC and HMI panel

Ethernet chips supported by the firmware: W5100, W5500, LAN8720, IP101.

µLink connects input/output modules to the PLC over wired Ethernet. It works directly on Ethernet frames, without IP addresses: the PLC searches for modules (“Search devices”), pairs them and drives them as if they were its own I/O.

  • A module can be another ESP32 running MiaPLC firmware in the I/O module role.
  • Or an Arduino Uno with a W5100 or W5500 Ethernet shield, using the MiauLink library.
  • Modules can also have analog inputs and outputs.

HMI panel

MiaHmi is the firmware for a 10.1" touch panel on ESP32-P4: it reads and writes PLC data and shows fast trend charts. It is prepared with MiaConfig (HMI project), just like the PLC.

FAQ

Is it a certified PLC?

No. MiaPLC is meant for teaching, prototypes and hobby projects. Do not use it for safety functions (emergency stops, guards, protection of people): those require certified safety components.

Does it need internet?

No. The PLC and its editor work on the local network. MiaConfig needs internet only the first time, to download the build tools.

How much does it cost?

The software is free. The hardware is an ESP32 board: from a few euros for a C3 module up to boards with Ethernet and relays already fitted.

What licence is it under?

Firmware, editor and tools are free software under the GPL-3.0 licence.

Does what I learn here apply to industrial PLCs?

Yes, in the concepts: scan cycle, ladder, networks, functions with interfaces, data blocks, IEC data types, Online view. Every brand has its own environment and details, but once you've got these basics you find your way quickly.