12

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)

Manishearth
  • 2,882
  • 2
  • 22
  • 32
  • @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). – Manishearth Apr 11 '13 at 06:50
  • @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. – Manishearth Apr 11 '13 at 13:44
  • @Polar: Of course, there will be a compiler in between. When you normally code an Arduino, it is via UART (Rx/Tx) because the bootloader lets you do this. On the other hand, if you use an external programmer, you don't need the Arduino bootloader (you can write your own), as you program it via IRS (MISO/MOSI/SCK), – Manishearth Apr 11 '13 at 13:52
  • @Polar: I could load a program directly on the initial bits of program memory if I wanted. The Arduino bootloader basically first checks if there's any data being sent via UART (if there is, it reprograms itself with the program being sent). If there isn't, it runs the last loaded program. It's not necessary. I can just write a simple bootloader that says "go to memory location X and start executing". Or, I could just write the program where the bootloader was. – Manishearth Apr 11 '13 at 14:01
  • @JamesC4S: Yep, that. Btw, like I mentioned, if the tutorial would be too long, some links and a general idea of the situation would be nice. – Manishearth Apr 11 '13 at 14:06
  • @Robert: Yeah, that's because my original intention was that part 1 and 2 were in this question. I'm still fixing them up, I split them after I got the answer. – Manishearth Apr 11 '13 at 16:19
  • @Robert: Clarified :) – Manishearth Apr 11 '13 at 16:20
  • @Manishearth I think it would be helpful to clarify that the question (as it has evolved) is to use the Arduino IDE but with an external programmer. It took me a minute to understand the question as it stands now. –  Apr 11 '13 at 16:18
  • @Manishearth What do you mean by 'without a bootloader'? – Polar Apr 11 '13 at 13:39
  • @Manishearth So you're looking for just 1's and 0's provided by you (i.e. to get the most out of the available memory)? – Polar Apr 11 '13 at 13:45
  • @Manishearth EDIT: I think I may have just found a method with Google :) If I can make sense of it I'll post it as an answer. – Polar Apr 11 '13 at 13:50
  • @Manishearth Don't worry, I knew you'd need a compiler. I just wanted to clarify what you meant by without a bootloader - there's a part on the Arduino site [here](http://arduino.cc/en/Hacking/Programmer) with instructions. What purpose does the bootloader actually serve then? Is it exactly the same as its mainstream (i.e. computer) equivalent? – Polar Apr 11 '13 at 13:56
  • @Manishearth Did the mini-tutorial I provided help at all? – Polar Apr 11 '13 at 15:22
  • 2
    +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. – Anindo Ghosh Apr 11 '13 at 06:38
  • 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. – asheeshr Apr 11 '13 at 06:41
  • To what extent do you want the tutorial? Would it be compiling the hex file with the IDE, finding the hex file, and then using a programmer like the USBtiny? I think the question could be a little more generalized and useful if it were "How do I use an external programmer with an Arduino board?" It sounds to me that's what you're going after and I know others do the same thing (I'm one of them.) – baldengineer Apr 11 '13 at 14:05

1 Answers1

6

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.

Polar
  • 551
  • 3
  • 9
  • 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. – Manishearth Apr 11 '13 at 15:33
  • I'll ask another one, this will get too broad if I stuff that in. – Manishearth Apr 11 '13 at 15:51
  • Here: http://arduino.stackexchange.com/questions/221/how-do-i-transition-from-using-the-arduino-ide-to-plain-avrdude-make – Manishearth Apr 11 '13 at 16:04
  • @Manishearth Ah, I'll edit it to reflect that if you want. Then again, we _could_ do with more questions... – Polar Apr 11 '13 at 15:43
  • @Manishearth Ok :) – Polar Apr 11 '13 at 15:52