Arduino Uno Makefile for direct development in C 1

Here I am publishing an adapted Makefile for Arduino Uno (with the atmega328 controller) code development directly in C (not using the Arduino IDE – I preferr to be IDE idependent). The Makefile allows you to compile your C code using

make

and to upload the program via USB utilizing avrdude (an program for code upload for Atmel Microcontrollers) using

make program

First make sure you have all necessary tools (the compiler avr-gcc and standard libs avr-libc as well as avrdude, the program for downloading the code in form of hex files onto the Atmega on your Arduino Uno) installed in our ubuntu:

sudo apt-get install gcc-avr avr-libc avrdude binutils-avr

Then, after downloading the Makefile, all you have to do is to adapt the first few lines of the Makefile to reflect your target file name and additional source files you want to compile into the project as well. Without modification the part of the file looks as follows:

# Target file name (without extension).
TARGET = main

# List C source files here. 
SRC = $(TARGET).c
#SRC += otherFile1.c
#SRC += otherFile2.c
#...

Hence compiling the project will only look for a main.c and compile it. Uncomment and addapt the SRC += lines if you have additional source files.

The Makefile assumes, that the Arduino Uno registeres as a serial connection at /dev/ttyACM0. If that is not the case change the following line in the Makefile:

# programmer connected to serial device
AVRDUDE_PORT = /dev/ttyACM0

Read udev rules for arduino uno to learn how to setup the serial interface such that the Arduino Uno registers correctly and you have read and write permissions for the serial interface such that you can successfully program the Arduino.

One comment on “Arduino Uno Makefile for direct development in C

  1. Pingback: Udev rules for Arduino Uno ← j-robotics

Leave a Reply