How can I compile and upload a .ino sketch file with Node-RED on a Raspberry PI to an Arduino

Hi I saw this topic a few times passing by, but they are rather old and had not really a clear answer. So I am asking again and have some additions. I have an Arduino controlling a simple robot (4 servo's) connect with a cable to the USB port of a Raspberry Pi which runs Node-RED. It would really help me if I can upload sketches to the Arduino from Node-RED. I can execute this command from the command-line: arduino-cli compile --upload Blink.ino --port /dev/ttyACM0 --fqbn arduino:avr:uno where it compiles and uploads the blink.ino. To do this with Node-RED I was thinking of using the exec-node, but the problem is where/how to get the file. Maybe you know to work with this. Another solution might be uploading it via the serial port, but the file needs to be compiled first. So my question in other words: How can I compile and upload a .ino sketch file with Node-RED on a Raspberry PI to an Arduino

Hi @hansb001 !
Welcome to this forum & to the Node-RED community.
I don't have a straight answer to your question, but rather a proposal...

Do you need to do this via an Arduino? Ever considered to go the "all Node-RED" way?
Anticipating that your Arduino is an ESP device: We've created a suite to program ESP devices with Node-RED (called Node-RED MCU Edition) & integrated this fully - in the sense of: Click one button, done! - into the Node-RED editor by the node-red-mcu-plugin.

Being the author of this plugin, I could offer to support you on your way to change over to Node-RED MCU Edition ... if you are interested.

Assuming the Arduino source-code is on a local dev machine and node-red is running on a server, you will need to upload the file to the server to a location where Node-RED can access it.

There are all sorts of ways to do that, both manually and automatically depending on your dev device, your workflow and what tools you use.

If you are developing directly on a Pi, then it is easier of course (though likely slow!).

Thanks Ralph, I will have a look!

thanks @TotallyInformation. The node-red is on the raspberry. I can access the .ino files, but how do I upload it to the attached Arduino? Using the exec node with the command above, gives me this message { _msgid: '50cdaefe23b0fe5f', topic: '', payload: '', rc: { code: 127, message: 'Command failed: arduino-cli compile --upload /home/tedge-child/arduino-1.8.19/examples/01.Basics/Blink/Blink.ino --port /dev/ttyACM0 --fqbn arduino:avr:uno\n' + '/bin/bash: line 1: arduino-cli: command not found\n' } } 20 Jan 13:32:01 - [info] [debug:debug 2] {

OK, so it can't find the arduino-cli executable. Most likely because of how you are running Node-RED. There probably isn't a path environment variable set.

All you need to do is run whereis arduino-cli on a command line on the Pi and put in the full path to the executable which you get back from that command.

that worked! I had the path before, but I made a typo. Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.