Skip to Content

← All functionalities

Industrial mixing (touch HMI)TouchBerry PiGPIOControl

Switching output Q0 from the dashboard, with interlocks

The shortest path from a touchscreen button to a contactor is the rpiplc-digital-write node: it drives the PLC's digital output Q0 directly from Node-RED, no external controller involved. But a raw button wired to a relay is a liability, so this example puts an interlock function in between — materials ready, admin session active, safety auto-off. It reproduces a real deployment on an industrial mixing line, where Q0 commands the machine contactor.

Native I/O nodes instead of GPIO hacks

Industrial Shields ships a Node-RED node set (rpiplc) that exposes the PLC's real industrial I/O — relay and transistor outputs, opto-isolated inputs, analog channels — by their panel names, like Q0.0. The dashboard button just needs to deliver msg.payload as 1 or 0 and the node handles the hardware layer. No sysfs paths, no Python helper scripts, no pin-number guessing: the flow reads like the electrical drawing.

The interlock function in front of the relay

Stop is always obeyed, unconditionally and without any checks. Start, on the other hand, has to pass two of them: the latest "materials ready" value memorised from MQTT must be true, and an admin session (shared global context with the login flow) must still be active. A rejected order routes to an on-screen notification explaining exactly which condition blocked it, so the operator is never left guessing.

Auto-off as a last line of software defence

When Q0 switches on, the function arms a 30-minute timer with setTimeout and clears it on every stop. If a stop command never arrives — a lost message, a closed browser tab — the timer drops the output and logs a warning. Hardware protections (thermal relay, emergency stop) still sit downstream; this timer just keeps software faults from outlasting them.

A snippet from the implementation

Straight from the example as deployed on the TouchBerry Pi — copy it freely:

global.set("materialsOk", msg.payload == "1");
return msg;                            // continues to the dashboard LED


// ============================================================
// function 2: interlockQ0
// ------------------------------------------------------------
// Input: msg.payload = "ON" | "OFF" (dashboard buttons)
// Output 1 -> rpiplc-digital-write (msg.payload = 1 | 0)
// Output 2 -> ui-notification (command rejected)
//
// Interlock rules to switch on:
//   1. Materials OK (MQTT ready topic == "1")
//   2. Active administrator session for the manual override
// Stop (OFF) is ALWAYS accepted, unconditionally.
// ============================================================
const MAX_RUN_TIME_MS = 30 * 60 * 1000;   // safety shutdown: 30 min

if (msg.payload === "OFF") {
    // Stop is never blocked
    const t = context.get("shutdownTimer");
    if (t) { clearTimeout(t); context.set("shutdownTimer", null); }
    global.set("q0State", false);
    msg.payload = 0;                       // rpiplc-digital-write: Q0.0 = 0
    return [msg, null];
}

if (msg.payload === "ON") {
    // Interlock 1: materials ready
    if (!global.get("materialsOk")) {

The full example is a complete program — wiring header, setup and main loop — ready to adapt to your application.

Frequently asked questions

How do I control Industrial Shields PLC outputs from Node-RED?

Install the rpiplc node collection, drop an rpiplc-digital-write node, select the output (for example Q0.0) and send msg.payload 1 or 0 to it.

Is it safe to drive a machine contactor from a dashboard?

Only with layered protection. Keep hardware safeties (emergency stop, thermal relay) in the circuit and add software interlocks and an auto-off timer like this example.

Why does stop bypass all the interlocks?

Stopping must never depend on sessions or process conditions. Any interlock that could block a stop command is a design fault.

Related functionalities