Browse our Blog. You will find multiple applications, solutions, code examples. Navigate using the tag cloud or search using specific criteris
How to upload a sketch to a M-Duino/Ardbox using the Shell/Command Line - Linux
In this post it will be seen how to upload a sketch using the command line instead of using Arduino IDE interface. This is an introduction for a newer post in which 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.
Computer with Linux.
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.
Avrdude is found inside the Arduino directory. If we want to install we can use the following command on the shell terminal:
$ sudo add-apt-repository ppa:pmjdebruijn/avrdude-release $ sudo apt-get update $ sudo apt-get install avrdude
In Windows it is necessary to modify the Path variable in order to use the avrdude from any directory. In Linux it is set automatically, so this steps for changing the path variable are omitted.
Before setting the command we need to know which port the PLC is using. For knowing that we need to search using one of the following commands:
$ cd /dev/ $ sudo ls ttyACM* $ sudo ls ttyUSB*
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 an 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 on this post where we explain how to take the binary file from an .hex file:
Once we know the port that is connected to the Arduino we just need to write the following command line and the sketch will be updated.
Now it is time to upload the sketch using the avrdude command. The command is:
For M-Duino boards:
avrdude -p atmega2560 -c wiring -P /dev/ttyACM0 -b 115200 -U flash:w:t1.hex:i -D
For Ardbox boards:
avrdude -p atmega32u4 -c avr109 -P /dev/ttyACM0 -b 57600 -U flash:w:t1.hex:i -D
To end with this post we will explain a bit this command. All this options can be displayed if we just write avrdude on the command line and we press enter. It will automatically show what does it do this options.
-p -> board. In this case I am uploading the sketch to an MDuino, which has an Arduino Mega 2560. For Ardbox it is the atmega32U4 -c -> type connection. Wiring or avr109. We actually do this uploading using the USB wire. Other options are the USBtiny or the avrasp. -P -> Port. It actually tells to the avrdude where it has to send the .hex file -b -> Baudrate. Transmission speed. -U -> :r|w|v:[:format]. As tipycal the memory type used is the flash memory, we want to write(w) and we will write the .hex file -D -> Disables the auto erase for flash memory.