This tutorial is about building a minimal Arduino compatible microcontroller setup without using Arduino bootloader at all! What this means in practice is that you are able to use Arduino IDE and all the libraries but you will not need to upload the code using Arduino bootloader. The reasons you would want to do this are (I’ll probably add more entries to this list later):
- Cost – use only minimal amount of components and save money.
- The project you are working will not need to communicate with computer via serial connection.
This tutorial can be useful even if you wish to learn how to build a minimal Arduino and burn the bootloader to it.
The setup described in this tutorial will consist of Arduino IDE, AVR microcontroller and ISP programmer. To understand why burning Arduino bootloader to the AVR one must first understand what the bootloader actually is. Bootloader is a tiny program that executes every time Arduino is switched on. It is then checking whether someone is trying to upload a sketch using serial connection (rx/tx pins). If not it starts the execution of sketch uploaded to Arduino.
Normally code to be executed is uploaded to AVR using ISP programmer. Also if you wish to burn Arduino bootloader to AVR, you need this tool to do it. Uploading code this way will work in similar fashion but the programmer is connected to different pins. So if you own ISP programmer it is up to you to decide whether you want to upload code using it or burn the Arduino bootloader to the AVR and upload the code using it via pins rx and tx. Naturally if you don’t burn the bootloader you will save some memory and sketches will start a bit faster (depending of the actual AVR you are using).
Lets get started
For the most minimal Nonduino setup you will need following:
- AVR microcontroller, in this tutorial we are using ATMega8
- 100n capacitor (if you are brave, you can also do without this)
- Wires, breadboard etc
- Nonduino definitions, just copy nonduino folder in it to the hardware folder (create if it doesn’t exist) of your sketchbook folder.
- Arduino 0021
AVR chip costs around 3€ and cap costs more or less nothing. In addition you will need an ISP programmer, for connecting the chip to the computer while programming it. One costs ~20€ (bought mine from Stange-Distribution) and naturally no matter how many Nonduino projects you will make, you only need one programmer.
First step is to connect power to the AVR. Just connect pins 7 and 20 to +5V and pins 8 and 22 on ground. Place a capacitor between +5v and ground, preferably physically as close to pins 7 and 8 as possible. This is actually all we need to be able to run the program inside AVR (but you are not yet able to upload the code or actually witness the running as there isn’t any output components yet (which we will be doing in a bit). Also remember to triple check that you are using regulated power supply which actually gives you 5V. Power through USB is good. You may want to check out nice Instructable about building minimal Arduino.
Next step is to connect your ISP to AVR. Smart thing to do here is probably use a 6 pin female header as your ISP probably did ship with 6-pin male header. Connect it like this:
- ISP RESET <=> RESET (pin 1)
- ISP GND 2 <=> GND (pin 22)
- ISP +5V 3 <=> +5V (pin 20) (optional, if you wan’t to power AVR through ISP)
- ISP SCK 4 <=> SCK (pin 19)
- ISP MSIO 5 <=> MSIO (pin 18)
- ISP MOSI 6 <=> MOSI (pin 17)
To make this tutorial a bit more interesting we could add a LED to the circuit. Arduino pins don’t match the pins of AVR so you have to use this chart for figuring out where to connect stuff. Blink sketch that comes with Arduino IDE will have its LED attached to pin 13 so if you would wish to run it you would need to connect it to the pin 19 on AVR (which happens to be the same than we are already using with our programmer but that doesn’t matter).
Next step is to setup the fuses of AVR correctly. Stock AVRs are shipped with fuse settings that usually are not usefull in Arduino applications. The most important fuse bit is the one that sets the clock source and speed of AVR. In minimal setup we are using internal RC oscillator as the clock source of the processor. The cons are that you are running AVR in half speed. Also the clock speed varies according the actual voltage on 5V pins which might cause trouble in data communication protocols (after voltage is 4V or lower). For 8Mhz function set high fuse to D9 and low to E4. You can do this by using avrdude or AVR Studio (also check this site for more info on fuse settings. This fuse calculator will also give you avrdude arguments). You only need to do this once for each chip.
Uploading the sketch
If you copied nonduino definitions to your sketchbook, when you start the IDE you should see two Nonduino boards in your board list in the menus. Pick Nonduino 8Mhz. Then plug in your ISP that is connected to the AVR. You should be able to choose right port on your serial port list. Choose it and hit upload and that should be it! If your uC is not visible on the list, go edit flie boards.txt at nonduino folder by comparing it to boards.txt file that is shipped with Arduino IDE and you should be able to figure settings for uC you are using.