---------------Getting along in the 21st Century with half the baggage you carried in the last.------------ /*************************Low cost electronic solutions for a low impact lifestyle.************************/
Sunday, September 05, 2010
Bootloading Arduinos
What I really love about the Arduino is that it is so accessible and comes with all the utilities to make it work. For example, it takes just minutes for a Newcomer to connect up an Arduino and flash a LED. I think this accessability and ease of use across all the main platforms is one of it's key attractions - and something that other vendors of microcontroller kit have failed to appeciate or capitalise upon.
Once you gain more experience of programming, you can choose to move away from the "safety net" offered by the Arduino IDE, and use the GCC compiler and AVRdude tools directly. However for most simple applications there is no problem just using the Arduino flavour of the C language - provided you don't want to do anything too fast or clever.
One of the nice features is the ability to use an Arduino to program the bootloader into a new IC. Whilst pre-loaded chips are available from a number of suppliers - they charge a premium for these - and if you are making a lot of Arduino based devices - it's much cheaper to program your own - using the easy to use "Burn Bootloader" tool that comes as standard with the Arduino IDE. We used this for the first time on the Snowdonia Mega-Hack Session and found it to be quick and reliable.
Using this utility, I programmed up 10 ATmega328 ICs with the Arduino bootloader in under 30 minutes, and for a cost of about £3.30 per chip (includes VAT and postage from CoolComponents). This saved me approximately £2.90 per chip! CoolComponents are located near Clapham Junction Station and have keen prices on ATmega328s and have a very quick turnaround - 24hrs.
To make use of this Arduino ISP facility, you either have to have 2 Arduino boards, or 1 Arduino and a small breadboard. I used the breadboard method as described in the Arduino Tutorial: Using the Arduino as an ISP
In order to make this device, you need to make up a clock crystal and reset circuit for a ATmega328 on a small breadboard and connect up the Vcc and Gnd pins. Then you use the existing Arduino board and connect Digitals 10 - 13 across to your target '328. This brings across MOSI, MISO, SCK and Digital 10 which is used to reset the target processor. You also need a feed of +5V and 0V from the Arduino board to power your target.
David A. Mellis's programming application also uses 3 other port lines for driving LED indicators. Digital 7 flashes to show that programming is underway, Digital 8 will light up an LED if there is an error and Digital 9 is a Heartbeat to show that the ISP application is running. You don't have to fit these LEDs - but if you are doing this for the first time, it's a good confidence booster that all is well.
During programming the Rx and Tx LEDs on the Arduino board flash rapidly as the serial data is sent from the PC. The LED on digital 13 also flashes quite quickly. At the end of the programming session, the target microcontroller is reset and starts to execute a LED flashing routine on digital 13 - which shows up as a faint slow flash on the programming Arduino LED. This confirms that the bootloader has been programmed and that it is running code. This is a neat feature, as when it comes to use these bootloaded ICs in DIY Arduinos, the LED flashing code will still be present to tell you that the processor is running.
The picture above shows my bootloading breadboard - not the tidiest of layouts, but works fine. There are just 6 wires to connect across from the Arduino, or 7 if you want the Error LED. The breadboard has a 16MHz crystal, two 22pF loading capacitors and a 10K resistor on the reset line. If you are actively building DIY Arduino hardware, you will have all these components to hand anyway!
Now that I'm boodloading my own mega328 chips I think that the cost of a DIY Arduino Slave has dropped to about £4.50 a unit.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment