Note: This mini-tutorial is based off of the official information here on the Arduino site. It also involves using the official Arduino IDE.
Note 2: The links provided to products may be either Farnell links (as they contain data sheets) or the actual product pages on the manufacturer's website.
Step 1: Get an external programmer
The first thing to note is that you need an external programmer to avoid the bootloader and reclaim the 1K or 2K of memory which it takes up (12.5% of the total memory). You could use an AVR-ISP, a STK-500, or a parallel-port programmer - the official Arduino site has instructions for this here. Note that you can't communicate with the board through the parallel programmer - the advice is to use a serial cable for that. The main benefit of using a parallel programmer is that they're much cheaper than the others if you're willing to do some soldering - you only need a few (3) resistors and a few connectors, whereas an ISP can set you back up to £30/$50 (conversion rate is approximate).
Step 2: Edit the Arduino preferences file
Next you'll need to configure the Arduino IDE to allow you to circumvent the bootloader. Make sure you do NOT have the Arduino IDE open! The preferences file preferences.txt
can be found at the following locations, depending on your operating system:
C:\Documents and Settings\<Username>\Application Data\Arduino\preferences.txt
(Windows)
/Users/<Username>/Library/Arduino/preferences.txt
(Mac)
~/.arduino/preferences.txt
(Linux)
To get to the preferences file in Windows, go to the start menu and then go to %appdata%
(NB: I don't use Windows regularly, feel free to correct me). Then navigate to Arduino and then to preferences.txt
On Mac, either use Terminal, and do:
cd ~/Library/Arduino
open .
Or in Finder use Goto (Cmd-Shift-G) and enter ~/Library/Arduino
. These both take you to a Finder window with preferences.txt
in.
On Unix systems, folders starting with a '.' (such as .cache
, .git
) are by default hidden, so in Linux you'll need to use the Terminal and enter:
cd ~/.arduino
nautilus .
Note: You can replace nautilus with gnome-open
if you wish. I know that these both work on the common flavours of Linux, but you may have issues on some of the more 'exotic' flavours.
Once you have found the preferences.txt
file, open it and change the upload.using
from bootloader
to the name of one of the programmers in the ./hardware/programmers.txt
subdirectory. If you only want to remove the bootloader from one board, in ./hardware/boards.txt
you can change the <board>.upload.using
parameter and all of the other boards will still use the bootloader. Then just save the relevant file and close it down (my Arduino just crashed and I almost lost the answer, possibly because I forgot to do this).
Step 3: Upload the sketch
Once you've edited the relevant file, open up the Arduino IDE again and upload the sketch as normal. If you just edited ./hardware/boards.txt
, then only that particular board will not have the bootloader, but if you edited preferences.txt
then all of the boards won't have the bootloader.
Step 4: Replace the bootloader
If you want to have the bootloader on your boards again (for whatever reason), then first remove either the <board>.upload.using
parameter or set upload.using
back to bootloader
. Then you'll need to burn the bootloader back on to the affected boards - this answer explains reasonably well one method of doing it, and there's an easier method to upload the Arduino bootloader only with just an ISP (which you should have from earlier) on the official site here.
Here are some instructions. If you just want to know what goes where in your perfboard, read on.
Here's the pinout for the ATmega328:
Firstly, you'll need a LM7805 or something similar to get a 5V. If you don't know how these work, refer to this image.
Power
Now, connect the + end of your 12V battery to the IN of 7805, and - to the COM. Hereafter, I shall refer to any connection from COM as "GND" and any connection from OUT as "Vcc".
Reset
Connect Vcc to Pin 7 and 20 of the ATmega328, and GND to pin 8 and 22. Connect Vcc to a ~10 kiloohm resistor, and connect the other end of that to the RST pin (pin 1). Also, connect GND to a reset switch, and the other terminal of the reset switch to pin 1. When the reset switch is on, the Arduino will restart. If you don't want a reset switch, just connect Vcc directly to pin 1.
Clock
Connect GND to the negative terminals of two 22 picofarad capacitors. Connect one capacitor to pin 9, and the other capacitor to pin 10.
Now, connect a 16MHz clock between pins 9 and 10:
Analog reference
If you use the AREF pin, just connect your AREF to pin 21.
Rest of the pins
These are labelled in the diagram above. Pins 23-28 are A0-A5. Pins 2-6 are digital 1-4, 11-19 are digital 5-13. Use these normally. Note that digital pin 13 (pin 19 on the microcontroller) won't have an LED anymore, but if you wish to connect one, connect it to an LED, followed by a 200-300 ohm resistor, followed by ground:
Programming
If your Arduino is a DIP Arduino (the ATmega is removable), then just program it using the IDE, remove the ATmega, and place it in your perfboard circuit (I assume you're using an IC holder). If the Arduino has a surface mount ATmega, see How can I use my SMD Arduino to program a separate DIP ATmega328?.
That's it! Now you can easily take an Arduino project to a perfboard!
Here's the final schematic:
Best Answer
The tool I would use in this case is Cduino. Cduino is a tool designed to give greater control over the actions of the ATmega and doesn't require a bootloader.
You will need a USB programming cable, and a Duemilanove or an Uno as it uses the Mega328p chip. Of course, Uno's and Duemilanove's seem to be the most common, so this shouldn't be an issue. You will also want an ISP (examples given in the first part of the question) for in-system programming (i.e. to avoid the bootloader).
Cduino itself is a command line tool which allows you to write directly to the Arduino. You will need a few packages installed, including
make
,avrdude
andscreen
. To make it run without the bootloader, connect the Arduino as I explained in the previous question, and in thegeneric.mk
file changeUPLOAD_METHOD
fromarduino_bl
toAVRISPmkII
.Uploading the file itself is a simple command line sequence:
Then, to communicate with the board serially, use:
There is a series of 'lessons' to write code for Cduino here. It is basically C, but with a few library functions specific to the ATMega328p chip - note that it is C, NOT C++.