Node-RED programming¶
Industrial Shields Raspberry Pi-based devices can also be programmed using Node-RED, a flow-based programming environment.
This is achieved through the node-red-librpiplc library, a set of Node-RED nodes wrapping the C library librpiplc, which provides access to the inputs/outputs of the device from the Node-RED flows.
Node-RED
You can learn more about Node-RED in its documentation page.
Library Install¶
Default OS image
The C library is already preinstalled in the default OS images
provided by Industrial Shields, but Node-RED is not. The images
include an install-node-red.sh script in the home directory of
the user, which can be used to install it.
Requirements
Before installing the library, ensure that:
- You are using a Raspberry Piābased Industrial Shields device.
- The device is running Raspberry Pi OS.
- You have internet access on the PLC.
The Node-RED library is a wrapper of the C one, so both of them must be installed.
-
Install Node-RED on the device. On the default OS images provided by Industrial Shields, the
install-node-red.shincluded script can be used: -
Install the C library, if it is not already installed, following the instructions of the C/C++ programming section:
-
Install the Node-RED library from the Node-RED editor, using the menu ( > Manage palette > Install) and searching for
@industrial-shields/node-red-librpiplc.
Installing the library from the terminal
The library can also be installed with npm, from the Node-RED user
directory (typically ~/.node-red):
After the installation, Node-RED must be restarted.
Usage¶
Configuration¶
The nodes of the library cannot access the inputs/outputs until the
characteristics of the target device are known. They are set in the
rpiplc-config configuration node, which is shared by all the nodes of
the flows.
When using one of the library nodes, use the PLC Option on its
configuration menu to create and select a configuration node for the
device model being used. This configuration node can then be used for
all the other nodes of the library.
The available options are:
- Version:
RPIPLC_V3(deprecated)RPIPLC_V4RPIPLC_V6UPSAFEPI_V6GATEBERRY_V9TOUCHBERRY_PI_V1
- Model:
RPIPLC_CPURPIPLC_19RRPIPLC_21RPIPLC_38ARRPIPLC_38RRPIPLC_42RPIPLC_50RRARPIPLC_53ARRRPIPLC_54ARARPIPLC_57AARRPIPLC_57RRPIPLC_58UPSAFEPIGATEBERRYTOUCHBERRY_PI
Example
-
Double click on a node from the library to open its menu configuration. In this case, we are using a
digital writenode.
-
Click on the button and select the device version and model.

-
On the top right corner, click on the Update and Done to save the changes.
The version and the model can also be selected while the flows are
running. To do so, check the Select through "plc set config" node
option of the configuration node, and send a message with the
msg.version and msg.model attributes to a PLC set config node.
Only one configuration node
There must be only one rpiplc-config node in the whole Node-RED
instance, since several of them interfere with each other when
configuring the library.
Basic Examples¶
Besides the configuration ones, the library provides four nodes to access the inputs/outputs of the device:
digital read: gets the value of a digital input.digital write: sets the value of a digital output or a relay.analog read: gets the value of an analog input.analog write: sets the value of an analog output.
Each pin is identified by the name printed on the device (I0.0,
Q0.0, A0.5, ...), which is selected in the node itself or passed in
the msg.pin attribute. All these nodes return the result of the
operation in the msg.rc attribute.
The following examples can be imported into Node-RED using the menu ( > Import > Clipboard). After being imported, the changes can be deployed by pressing the Deploy button located on the top right corner.
Writing a digital output
Flow that sets the digital output Q0.0 to HIGH or LOW when the corresponding inject node is clicked:
inject (HIGH) / inject (LOW) → Digital Write (Q0.0)
→ debug

[
{
"id": "inject-high",
"type": "inject",
"z": "dacb7168b9819136",
"name": "Q0.0 HIGH",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": "",
"topic": "",
"payload": "HIGH",
"payloadType": "str",
"x": 180,
"y": 120,
"wires": [
[
"digital-write"
]
]
},
{
"id": "inject-low",
"type": "inject",
"z": "dacb7168b9819136",
"name": "Q0.0 LOW",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": "",
"topic": "",
"payload": "LOW",
"payloadType": "str",
"x": 180,
"y": 180,
"wires": [
[
"digital-write"
]
]
},
{
"id": "digital-write",
"type": "rpiplc-digital-write",
"z": "dacb7168b9819136",
"rpiplc": "plc-config",
"pin": "Q0.0",
"value": "",
"name": "",
"x": 420,
"y": 150,
"wires": [
[
"result"
]
]
},
{
"id": "result",
"type": "debug",
"z": "dacb7168b9819136",
"name": "digital write result",
"complete": "true",
"x": 660,
"y": 150,
"wires": []
},
{
"id": "plc-config",
"type": "rpiplc-config",
"isCustom": false,
"version": "RPIPLC_V6",
"model": "RPIPLC_38AR",
"name": ""
}
]
Reading an analog input and writing an analog output
Flow that reads the analog input I0.7 every second and mirrors the value on the analog output A0.5:
inject (every second) → Analog Read (I0.7) →
Analog Write (A0.5)

[
{
"id": "every-second",
"type": "inject",
"z": "dacb7168b9819136",
"name": "every second",
"repeat": "1",
"once": true,
"x": 200,
"y": 340,
"wires": [
[
"analog-read"
]
]
},
{
"id": "analog-read",
"type": "rpiplc-analog-read",
"z": "dacb7168b9819136",
"rpiplc": "plc-config",
"pin": "I0.7",
"name": "",
"x": 410,
"y": 340,
"wires": [
[
"analog-write",
"value"
]
]
},
{
"id": "analog-write",
"type": "rpiplc-analog-write",
"z": "dacb7168b9819136",
"rpiplc": "plc-config",
"pin": "A0.5",
"value": "",
"name": "",
"x": 620,
"y": 340,
"wires": [
[]
]
},
{
"id": "value",
"type": "debug",
"z": "dacb7168b9819136",
"name": "I0.7 value",
"complete": "payload",
"x": 620,
"y": 410,
"wires": []
},
{
"id": "plc-config",
"type": "rpiplc-config",
"isCustom": false,
"version": "RPIPLC_V6",
"model": "RPIPLC_38AR",
"name": ""
}
]
Notes and Best Practices¶
- Ensure the configuration node is set with the correct PLC version and model.
- Use only one
rpiplc-confignode, since several of them interfere with each other. - You can check the
msg.rcattribute returned by the nodes to detect I/O errors. - Run only one program controlling the I/O of the device at a time, so the flows do not interfere with other programs. For example, Node-RED and a C program both running at the same time and trying to interact with the IO.
References¶
-
Source code, node-red-librpiplc: https://github.com/Industrial-Shields/node-red-librpiplc
The Node-RED library: it wraps the C library and provides the nodes used in the flows.
-
npm package, @industrial-shields/node-red-librpiplc: https://www.npmjs.com/package/@industrial-shields/node-red-librpiplc
The published package, which is the one installed from the Node-RED palette manager.
-
Source code, librpiplc: https://github.com/Industrial-Shields/librpiplc
The C library used underneath, which defines the pin names of every device and performs the actual reads and writes.