The Arduino is a very cool development board where you could create hundreds of projects. But it doesn't mean that for every project you create, you would need an Arduino board dedicated to that project alone. A hundred projects and a hundred Arduinos? That's a waste of money! Depending upon the requirements of your project, you could choose from a wide array of microcontrollers - try AVRs from Atmel (now Microchip, yes the maker of the PIC). One microcontroller which is very tinkerer-friendly is the ATMEGA32, which is offered in a 40-pin PDIP package. This makes it very easy to be incorporated in prototype board and breadboard set-ups. In this 'ible, ATMEGA32 will be used but the same flow applies to other AVRs.
Step 1: Convert Your Arduino Into a Debugger/programmer
There's a sketch that you could load to your Arduino which can transform this development board into a debugger or programmer. This means we can use the Arduino to load a program to another microcontroller - in this case, the ATMEGA32. Programs (yes, sketches) can be created and compiled using the Arduino IDE then flashed to the ATMEGA32. If things go well, you can eliminate the Arduino development board from your project and the ATMEGA32 does all the work from that point on. Go to Examples and find the ArduinoISP sketch. Make sure everything is set up correctly. In my case, I'm using an UNO board and to program the sketch to my UNO board, I'll use the AVRISP mkII (my default). Go to Sketch then click Upload.
Step 2: Install Arduino Core for ATMEGA32
For the ATMEGA32 to work on the Arduino IDE, its specific core files should be installed. First, download the ZIP file from the following link.
Unzip. Inspect the files. The things we need are the "boards.txt" and the contents of the "variants" folder. Open your Arduino folder in Program Files. Go to hardware>arduino>avr. You will see the "board.txt" file. This file lists all boards available for use on your Arduino. We need to add boards for ATMEGA32 into this file. To do this,append the contents of the downloaded board.txt file to the original board.txt file. CAUTION: You need not include the first few lines (see image).
Next, go to hardware>arduino>avr>variants. Copy into this folder the contents of the downloaded "variants" folder. It is named mega32.
Now, check to see that ATMEGA32 boards are now available for use in the Arduino IDE. Go to Tools>Board
Step 3: Connect the ATMEGA32 to the Arduino
Programmers and debuggers make use of various communication interfaces in order to talk to a target microcontroller. Some use JTAG, PDI etc. The Arduino makes use of the SPI interface. So the ATEGA32 pins we will be using apart from the supplies are SCK, MOSI, MISO and RESET. Below are the connections.
- Connect pins 10 and 30 of ATMEGA32 to 5V on Arduino
- Connect pins 11 and 31 of ATMEGA32 to Ground on Arduino
- Connect pin 6 (MOSI) of ATMEGA32 to pin 11 on Arduino
- Connect pin 7 (MISO) of ATMEGA32 to pin 12 on Arduino
-Connect pin 8 (SCK) of ATMEGA32 to pin 13 on Arduino
-Connect pin 9 (RESET) of ATMEGA32 to pin 10 on Arduino
You are now ready to upload sketches to the ATMEGA32!
We won't need an external oscillator or a crystal for this. But if a clock settings (frequency or source) different from ATMEGA32 defaults is required by your application, you need to modify the fuse settings.
For other AVRs supporting SPI, the same flow may be used, just go look for the SPI pins.
Step 4: Your New Arduino Pin-out Is...
The pin number/label of the ATMEGA32 I/O pins are those numbers after the letter "D" on the image above. Remember to align the pin names on your sketch with your actual hardware connections on the ATMEGA32. Note that the SCL and SDA pin numberings also changed. For more details, open the file (with Notepad++ for example) "pins_arduino.h" which is contained on the "mega32" folder. Good thing about ATMEGA32, it supports more ports so you could integrate more functions.
Enjoy creating your projects!