Using Node-RED on MCUs
Could Node-RED generate code for MCUs? I asked backed in March 2020. As you may know, I am a big fan of Node-RED. It provides an elegant low-code/no-code solution for IoT but requires a single-board computer to run, like a Raspberry Pi 4B.
My question received an answer at the Node-RED Con 2022 with the Moddable presentation. The Moddable SDK implements JavaScript on MCUs and thus allows to run a Node-RED flow on them. Supported hardware includes ESP32, Raspberry Pi Pico W, among other options, and proprietary boards like the Moddable Two, built around an ESP32 and a 320x240 touch display, which I ordered. The project relies on different components:
|
Configure
Installation includes four parts: the required tools; the Moddable SDK; the tool-chain for the targeted board; and the Node-RED MCU plug-in.
As I am using a non-production PC, I opted for a MacBook.
Although I faced some issues during the installation, support from Moddable was great and the process ultimately succeeded. |
Given the complexity of the project, a container would have been really great to get everything configured at once. Alas, there is no official container, but a user is sharing his own configuration. I haven't tested it yet.
|
Use
First test
WiFi and MQTT
The flow connects to a MQTT broker, subscribes to the test/in thread, extracts the value from the message, performs some calculations and publishes the result to the test/out thread.
The first question was: How to connect to a WiFi network? The Options pane include dedicated fields to enter the SSID and password. They could also be mentioned on the Arguments field. I wanted to use JSONata to perform the calculation, but Moddable doesn't support it. I had to use the function node instead. |
Arguments
|
GPIO
The built-in LED on the Raspberry Pi Pico W is not attached to a GPIO of the RP2040 but instead to the WiFi CYW43439 radio on WL_GPIO0. Suggested answer was to specify 32 as GPIO.
I also attached an LED to GPIO15. Selecting GPIO15 on the Raspberry Pi GPIO node displays 10, but the LED does blink. On the Moddable 2 board, built-in LED is available on pin GPIO2 and backlight PWM is on pin GPIO18. |
SPI and I²C buses
I haven't tested SPI and I²C buses yet.
Pre-configured sensors are available and can be installed with the following command. |
Code Editor
Dashboard on MCU
One of the greatest and possibly most popular features of Node-RED is the dashboard. The video from the Node-RED Con 2022 shows at 2:19:41 a Node-RED dashboard running on an MCU.
I ordered the recommended Moddable Two board to test this feature. The board is built around an ESP32 and features a 2.4" displays with capacitive touch. The versions of the dashboard displayed on the Moddable 2 screen, the browser and the similator look very similar. The Moddable 2 board takes default GMT as timezone, while the browser uses the correct locale format. |
|
The UI Support should be Enabled and Screen Pixel Format set to rgb565le. Optional Screen rotation can be set to 90°, 180° or 270°.
Specific parameters need to be mentioned on the Arguments field, otherwise a stack overflow occurs. |
|
Conclusion
Yes, Node-RED now generates code for MCUs!
I really like the new ability to use the same dashboards on a MCU-powered board. The Node-RED MCU implementation already supports a long list of nodes and new ones are added. Targeting MCUs with Node-RED might not be the most optimised solution, especially when displaying a dashboard, but this approach speeds up the development on interfaces for MQTT and GUI. |
Links
Posted: 31 Oct 2022 Updated: 02 Nov 2022, 12 Jan 2023, 08 Feb 2023, 19 Mar 2023 |