This is a hello world AVR programming project. A simple way to get started programming an inexpensive AVR chip for anyone who has an Arduino board. I am going to use an Arduino Mega 2560 as an ISP AVR programmer but you can also do this with an Arduino UNO or any board with a SPI interface if you know how.
If you have been working with some developer boards like the Arduino UNO or the Arduino Mega 2560, and you are comfortable soldering your own projects, then you might have realized that the chips alone usually cost from $1-$3 and take up a lot less space than the breakout boards do. The good news is, you can easily get started programming these chips using the developer board that you have on hand!
For this example, I am going to use my Arduino Mega 2560 as an ISP AVR programmer to program an ATTINY84A-PU chip to do a simple LED blink. There are other ways to program this chip, but if you happen to already have an Arduino board on hand and don't want to spend the extra money to buy a programmer, this is a quick and easy way to get started.
- 10mm Ultra-High Brightness Blue LED - any LED will work
- An Arduino Mega 2560 or UNO
- A 10uF capacitor
- An ATTINY84A-PU ($1.41)
- Small Breadboard
- Connection Wires
The first thing you need to do is be able to program your chip using the Arduino Mega. To do that with the Arduino IDE you will need to install the Tiny bootloader and supporting libraries into the Arduino IDE. Then you will need to set up the circuit for the programmer, upload a blink sketch to the chip, and finally, setup the chip circuit to work with the blink circuit.
Using the Arduino Mega as an AVR programmer
Step 1: Prepare the Arduino IDE environment to program the ATTINY84AYou need to be able to compile code into a hex file to load onto the ATTINY84A and upload that code from the Arduino IDE but the functionality to do that requires some additional software components that are not included by default.
- Click here to download the "Tiny" archive
- Create a new directory named tiny under your ..\Arduino\hardware directory.
For newer versions of the Arduino IDE, this may be located in:
"C:\Program Files (x86)\Arduino\hardware"
- Copy and paste the contents of the tiny/avr directory of the archive to the ..\Arduino\hardware\tiny directory you created.
- In the ..\Arduino\hardware\tiny directory, rename the Prospective Boards.txt file to boards.txt.
- Open the Arduino IDE. You should see the ATTINY84 under the Tools->Boards menu.
Step 2: Program the Arduino Mega 2560 to be an AVR ISPTo turn the Arduino Mega into an AVR ISP you need to upload the ArduinoISP sketch to your Arduino board.
- Using the USB cable, connect your Arduino Mega 2560 or Arduino Uno to your computer.
- Open the the Arduino IDE.
- Under Tools -> Boards select the "Arduino Mega 2560" (or select "Arduino Uno" if you are using that instead) as the board.
- Under Tools -> Programmer select "AVR ISP"
- Select File -> Examples -> ArduinoISP to open the Arduino ISP sketch.
- Compile the sketch and upload it to your Arduino Board.
Your Arduino is now ready to use as an in system programmer!
Step 3: Hardware Setup to use the Arduino ISP (for the ATtiny84)
Next we need to make the connections between the Arduino Mega (or Uno) and your ATTINY84A chip.
The Arduino Mega has a hardware SPI interface on pins 50 - 53 that can be used to program other chips like the ATTINY84A as shown in the picture below. (If you are using the Uno, pins 50, 51, 52, and 53 on the Mega should be mapped to pins 12, 11, 13, and 10 on the Uno).
|Arduino Mega 2560 Hardware SPI Pins|
(note: we also use pin 53 - the SS pin to reset to ATtiny84)
We need to connect the SPI pins from our Arduino to the SPI pins on the ATTINY84A. I am using the ATTINY84A-PU because the PU extension chips are breadboard friendly. The pins needed for this on the ATTINY84A are shown below.
Unplug the Arduino Board and make the following connections:
|ATTINY84A SPI / ISP Pins|
(note: the RESET Pin 4 will also be needed)
Curcuit setup for the ISP AVR programmer
|Arduino Mega/ Uno Pins||to||ATTINY84A Pins|
|MISO pin 50/ pin 12||->||pin 8|
|MOSI pin 51/ pin 11||->||pin 7|
|CLK pin 52/ pin 13||->||pin 9|
|SS pin 53/ pin 10||->||pin 4|
|5V||->||pin 1 VCC|
|GND||->||pin 14 GND|
|RESET to Capacitor to||->||GND|
- Plug in the USB connection for Arduino board to your computer.
- Open the Arduino IDE.
- Open the Arduino Blink sketch by selecting
File -> Examples -> Basics -> Blink.
- Change the led pin in the blink sketch by changing
"int led = 13;" to "int led = 1;"
- Select the ATtiny84 @ 8 MHz Internal Oscillator by selecting
Tools -> Boards -> ATtiny84 @ 8 MHz Internal Oscillator
(Caution: Do not select the External oscillator unless you have added an external oscillator; this can cause issues if selected by mistake).
- Choose the Arduino as an ISP programmer by selecting
Tools-> Programmer-> "Arduino as ISP"
- Upload the sketch to the chip by selecting
File-> "Upload Using Programmer" or pressing Ctrl +Shift + U.
Step 5: ATTINY84A-PU LED Blink Hardware Setup
Make the connections:
ATtiny84 Vcc Pin 1 -> 3.5V to 5V source voltage
ATtiny84 GND Pin 14 -> Ground
ATtiny84 Pin 3 /PB1 -> LED +
LED- -> Ground
Here is another useful link with more details for doing this with the UNO.
Using the Arduino Uno to program ATTINY84-20PU