12
\$\begingroup\$

Part two of a three part series on transitioning from Arduino to a plain AVR microcontroller and minimum supporting components (part one, part three)

I've seen a lot of people ask this on the Internet, so here goes:

I already know how to program and use a barebones ATmega328 with an Arduino as a programmer. I now want to start using an external programmer with the Arduino IDE.

How should I proceed in this transition? What should I learn? (It would be nice if a mini-tutorial for some of the portions was provided as part of the answer)

\$\endgroup\$
  • 2
    \$\begingroup\$ +1, an excellent candidate for a reference question, I look forward to some well-structured and detailed answers that are easy to follow for a beginner, and not "etch-a-board" answers. \$\endgroup\$ – Anindo Ghosh Apr 11 '13 at 6:38
  • \$\begingroup\$ I am confused. You want steps to move from one methodology to another. What are you expecting as an answer ? Tutorials for directly using an external programmer are well, the actual tutorials. \$\endgroup\$ – asheeshr Apr 11 '13 at 6:41
  • \$\begingroup\$ @AshRj: Transitioning and starting afresh are two different things. If one knows how to use an Arduino, they would need to know what the differences in the various codes will be (and the basics of using a programmer). \$\endgroup\$ – Manishearth Apr 11 '13 at 6:50
  • \$\begingroup\$ @Manishearth What do you mean by 'without a bootloader'? \$\endgroup\$ – Polar Apr 11 '13 at 13:39
  • \$\begingroup\$ @Polar: Basically, I don't want the Arduino bootloader to be there to help me (which happens if you use an Arduino as a programmer), I just want a bare ATmega on which all the code is my code. \$\endgroup\$ – Manishearth Apr 11 '13 at 13:44
6
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ I guess I wasn't clear, I edited the question to make this apparent: I wanted to more or less discard the IDE altogether (which means you have to learn another programming language. However, since you've already posted an answer, I'll may just ask that as a separate question. \$\endgroup\$ – Manishearth Apr 11 '13 at 15:33
  • \$\begingroup\$ @Manishearth Ah, I'll edit it to reflect that if you want. Then again, we could do with more questions... \$\endgroup\$ – Polar Apr 11 '13 at 15:43
  • \$\begingroup\$ I'll ask another one, this will get too broad if I stuff that in. \$\endgroup\$ – Manishearth Apr 11 '13 at 15:51
  • \$\begingroup\$ @Manishearth Ok :) \$\endgroup\$ – Polar Apr 11 '13 at 15:52
  • \$\begingroup\$ Here: arduino.stackexchange.com/questions/221/… \$\endgroup\$ – Manishearth Apr 11 '13 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.