Tuesday 28 January 2014

Uploading Arduino sketch from Raspberry Pi (command line)

First of all we will need to download some packages (instructions assume the use of Raspbian) to allow us to compile Arduino compatible code (arduino-mk) and upload it (avrdude) to the Arduino.

sudo apt-get install arduino-core arduino-mk

Then add yourself to the dialout group to allow you to upload code to the Arduino board

sudo usermod -a -G dialout pi (Change pi to be your username if different)

Logout and then log back in again to ensure you are recognised as a member of the dialout group.

To compile an Arduino program it is neccessary to create a file called Makefile that is used to specify parameters for the compilation.

touch Makefile

Open the file for editing:

nano Makefile

And paste in the following text:

ARDUINO_DIR = /usr/share/arduino
BOARD_TAG    = uno
ARDUINO_PORT = /dev/ttyACM*
ARDUINO_LIBS =
include /usr/share/arduino/Arduino.mk


You may need to change the BOARD_TAG to reflect the version of the Arduino you are using

You can test that your sketch compiles by running make and ensuring that there are no errors.

To upload your compiled sketch to the Arduino:

make upload

This process allows for programming the Arduino without using a graphical user interface, and also allows updates to Arduino code to be propagated to devices using scripts (assuming the Arduino is connected to the Pi via USB).

ShareThis

Copyright