How to upload a sketch to an Arduino PLC using the Command Line

Learn how to upload a sketch to an M-Duino or Ardbox with the avrdude command of Windows
December 10, 2018 by
How to upload a sketch to an Arduino PLC using the Command Line
Alejandro Jabalquinto


In this post, it will be seen how to upload a sketch using the command line instead of using the Arduino IDE. We will show how to upload remotely a sketch using the command line. Without further delay, we will see how this process can be achieved.



First of all we need to know that for uploading a sketch using the command line it is necessary to use the program Avrdude. This program is part of the Arduino IDE tools, as it is the tool that uses Arduino IDE to upload the sketch. This avrdude is found inside the Arduino directory

For run an executable in the terminal prompt, it is necessary to be in that directory, or call all the path to tell to the terminal that the program you want to execute is found in that directory. A better solution in order to run a program without being in that directory is to add to the variable path, the path where the program is. The path is actually a variable, this variable contains all the paths that the system specifies. So if we want to execute avrdude being in another directory, it is needed to have the avrdude.exe path on the variable path. This way it will automatically search for the program.

So the first step will be to add the avrdude to the variable path. To get into the Variable Path, you need to search the word “variable” on the start button. This will get you directly to the correct window, jumping some little steps to get into there.

The second thing is to select the Environment variables, where it actually is the variable path.

The third step is to edit the Path variable, adding the path of the Avrdude.

In our case, avrdude is in: C:\Program Files (x86)\Arduino\hardware\tools\avr\bin. The avrdude in our computer is found inside the bin directory.

Variable path - How to upload a sketch to an Arduino PLC using the shell/Command Line - Windows

Once it is added, the last thing to do to set the path is to reboot the computer in order to save the changes. Maybe it is already added to the path, but in our case we have needed to do that, so for ensuring the process better do a reboot.

Once it is in the path, we are ready to send the sketch to the PLC. Avrdude works with files with the extensions of .hex. So, a file with the extension .ino (typical sketch) can’t be sent directly to the PLC. So we actually need to have the .hex file. This file is created by the time we compile using the Arduino IDE software. In the future, we will post how to compile a sketch .ino into a .hex to use the terminal for all the process. By now we will focus on just the avrdude. In order to search the .hex, take a look at this post, where we explain how to take the binary file from an .hex file:

Upload an sketch to a PLC using Ethernet Step 2 - Binary File 

In this post, it is shown how to convert an .hex file into a .bin file, and also it is explained how to find the .hex file.