In 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:
- Download an Arduino IDE. For example, the 1.0.5 version for Windows.
- Download either the Windows or the Linux-bash versions of the compiling/linking scripts.
- 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.
- Download either the Windows or the Linux-bash versions of the uploading scripts.
- Modify the first section of the scripts according to the serial port and board of your Arduino device.
- Create a folder for your sources and a folder for the building (intermediate files).
- 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; c=0; DDRB=(1<<5); while (1) { if (c==0) { PORTB &= ~(1 << 5); c=1; } else { PORTB |= (1 << 5); c=0; } for (f=0; f<40000; f++); } }
- Call the compiling/linking scripts using as arguments the file(s) to compile/link.
- Fix any error until no one is raised.
- Call the uploading script.