Scripts for using Arduino as a bare microcontroller

Arduino_Uno_-_R3In engineering courses that deal with microcontrollers it comes handy to program the one in the Arduino board -e.g., the ATmega328P– directly (without the Arduino IDE), taking advantage of the bootloader that comes pre-installed in that CPU to upload the programs to the board through the USB port -without a programmer device-, but also writing code that is not polluted with Arduino libraries, interrupts that are stolen for internal affairs, or setup/loop artificial functions.

The following files provide that functionality. They work both in Linux and Windows, and have been tested in Arduino Duemilanove, UNO and Leonardo boards. They require the arduino IDE to be installed in your computer, which is only used (seamlessly) for compiling and uploading.

Installation and usage:

  1. Download an Arduino IDE. For example, the 1.0.5 version for Windows.
  2. Download either the Windows or the Linux-bash versions of the compiling/linking scripts.
  3. Modify the first section of the scripts (it is properly indicated in them) according to the path of the Arduino IDE in your computer. You can also add the S option for compiling in order to produce assembler code, and change the optimization options too.
  4. Download either the Windows or the Linux-bash versions of the uploading scripts.
  5. Modify the first section of the scripts according to the serial port and board of your Arduino device.
  6. Create a folder for your sources and a folder for the building (intermediate files).
  7. Write your code in the sources directory. For instance:
    /* ------------------------------------
    A test program: make the LED blink. 
    Juan-Antonio Fernández-Madrigal, 2014 
    #include <avr/io.h>
    #include <avr/interrupt.h>
    int main(void)
    	unsigned f;
    	unsigned char c;
    	while (1)
    		if (c==0) 
    			PORTB &= ~(1 << 5);
    			PORTB |= (1 << 5);
    		for (f=0; f<40000; f++);
  8. Call the compiling/linking scripts using as arguments the file(s) to compile/link.
  9. Fix any error until no one is raised.
  10. Call the uploading script.