BRIGADOON

Remote Arduino Programming

Normally, the Arduino is programmed using the Arduino IDE which compiles and uploads the code to the Arduino. This can be a problem when the host computer for the Arduino is a Raspberry Pi as the Arduino IDE often does not function smoothly on the Raspberry Pi.

This project allows the Ardujino IDE to be run on a local, more powerful computer and the program uploaded to the Raspberry Pi where it can easily used to program the Arduino. The following example uses a Linux box running Fedora as the host computer; and a Raspberry Pi 4 as the Remote Computer; and an Arduino Nano

The following example uses a Linux box running Fedora as the host computer; and a Raspberry Pi 4 as the Remote Computer; and an Arduino Nano as the Arduino being programmed.

Install Necessary Software

Computer Node
Required Program
Installation Method
Linux Box
Go to this page and follow the installation instructions for your computer
Raspberry Pi
sudo dnf install avrdude

Arduino IDE Configuration

When the Arduino IDE compiles a program, it creates a HEX File that is passed to the avrdude program for up[loading into the Arduino. This step in normally hidden from the user, but it can be set so that this command is shown in the output bar at the bottom of the IDE.

(1) Select the Preferences Menu from the File Menu (Files->Preferences).
(2) On the "Show verbose output during" line, select the upload check box.

Once this is done, you can use the Arduino IDE as usual. Although you do not need to have an Ardjuino plugged in to the Linux host, you need to set all of the parameters in the Tools Menu such as:

(1) The Board:  <-- In this example an "Arduino Nano"
(2) The Port:     <-- In this example "/dev/ttyUSB0"
(3) Processor:  <-- May be required depending on the bootloader. For this example, it uses "ATmerga328P (Old Bootloader)" which can affect port speed.

Once this has been set, select the "Output" tab on the bottom of the screen and then select the right arrow upload button on the top-let of the display.

On about the third line from the top of the output, there will be a command similar to this, although it will on single line and in a single colour.
"/home/mark/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude"
"-C/home/mark/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf
-v -V
-patmega328p
-carduino
"-P/dev/ttyUSB0" -b57600
-D "-Uflash:w:/home/mark/.var/app/cc.arduino.IDE2/cache/arduino/sketches/27AB073E680413B863FD0369035787EB/groundweather.ino.hex:i"
To be able to use the Raspberry Pi to burn an Arduino connected to it by an USB port, it is necessary to understand what the output from the IDE is telling us.

The first part of the line identifies that the Arduino IDE is using avrdude to program the Arduino. This is why we installed the avrdude package on the Raspberry Pi.

The second part defines the location of the configuration file. We will use a copy of this file later when we go use the avrdude on the Raspberry Pi.

The third part contains a couple of flags for the avrdude program. From the instruction manual, the -v provide verbose output during operation and the -V disables automatic verification check when uploading with -U (more on that soon).

The fourth section defines the type of Arduino that is being programmed. In this case, an Atmega328p.

The firth part contains configuratipn information that lets the avrdude know more about the setup.

The sixth part of the line identifies which USB Port is being used to program the Arduino, and speed at which that port is running. The port may change when using the Raspberry Pi, but the speed should be set to the same speed. NOTE: The old bootloader code using 57600 Baud, but the newer loader use 115200 Baud.

The final part identifies file to be used and that the avrdude will be expected to write code to the Arduino, rather than download its existing code and where the code should be placed internally in the Arduino.

Raspberry Pi AVRDUDE Configuration

Now that the file holding the Arduino program has been identified and the parameters that the Arduino IDE used to upload the program, it is time to make a command that is suitable for the Raspberry Pi.

(1) Since the avrdude program has been installed as a system program, it can be invoked simply by "avrdude"

(2) If a configuration file is not required, the internal default configuration file will be used; and it is.

(3) Since the flags used by the Ardunio IDE works, let's leave them, although the -v can be removed for more concise report from the avrdude program.

(4) We need to identilfy the type of Arduino CPU, so just copy that bit over.

(5) As it is not obvious what the configuration parameter does, we copy it over just to be safe

(6) This is where a parameter needs to be altered. If you do not now which USB port the Arduino will be using, look at the devices by using the command "ls /dev". Now plug in your Arduino to the Raspberry Pi and repeat the command to list the devices. You should now see an extra entry. That should be something like "ttyUSB0". The speed should stay the same as tgeh bootloader in the Arduino will expect a particular speed.

(7) The final part tells avrdude what program hex file to use, that it should be uploaded and where in the Arduino CPU the data should be placed. In this instance, the program file is weatherstation_ino,hex and resides in the directory where avrdude is being run, otherwise, you must used a Fully Qualified File Name (FQFN)

avrdude -v -V -patmega328p -carduino "-P/dev/ttyUSB0" -b57600 -D "-Uflash:w:weatherstation_ino.hex:i"

Convenience Scripts

Now that the basics of using a Raspberry Pi to program an Arduino, it is time to make a couple of convenience command line (bash) scripts that can assist in automating remote programming.

If you use a wide variety of Arduino types, it is probably best to create the avrdude command line as required. At this site, however, the Arduino UNO and Arduino Nano are mostly used for controlling individual sensors with a USB connection back to a Raspberry Pie. This means that a simple script can be used to set up the command line.

The primary objective for these scripts is to keep them simple so they will primarily only deal with file to up[loaded, whether the item is an UNO or Nano, the USB port whether to use the slower or faster boot loader speeds.

The first step is to take the general command and highlight the items that will need to be changed for different Arduinos:

avrdude -v -V -patmega328p -carduino "-P/dev/ttyUSB0" -b57600 -D "-Uflash:w:weatherstation_ino.hex:i"

Licenced under Creative Commons Attribution Share Alike 4.0 International or better by Mark Little (2022 - 2024)