Wednesday, 19 April 2017

hardware - How should one switch from using an Arduino as a programmer to an external programmer?



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)



Answer



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\\Application Data\Arduino\preferences.txt (Windows)

  • /Users//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 .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 .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.


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...