Programming Tiny AVRs Via Arduino
by unikeyic in Circuits > Arduino
28 Views, 0 Favorites, 0 Comments
Programming Tiny AVRs Via Arduino

Arduino is great, but it can't program tiny AVRs natively. Here's how to do it with the Tiny AVR Programmer for ATtiny45/85.
First, install Arduino. If you're new, check out our measure light intensity photoresistor Arduino first. Then add the ATtiny add-on—manually by placing files in your sketchbook's hardware folder, or automatically via the boards manager.
Open Arduino, select your ATtiny model and clock (avoid 20MHz without an external clock!). Choose "USBtinyISP" as programmer.
Plug in the ATtiny, aligning its etched circle with the programmer's notch. Upload the Blink sketch (LED on pin 0) to test. If you get a USBtiny device error, check connections or drivers. For more control, see the Pocket AVR Programmer tutorial.
Supplies
Everyone loves Arduino! The simplified language makes programming AVRs and more complicated microcontrollers incredibly easy. Unfortunately, Arduino doesn't have any built-in functionality to program tiny AVRs, but that doesn't mean we can't add it!
On this page we'll go over all of the steps necessary to enable ATtiny45/85 programming in Arduino, using the Tiny AVR Programmer.
Install Arduino and Installing the ATtiny Add-On

If you've never used Arduino before (where have you been?!), make sure you follow our Arduino light intensity sensor tutorials before continuing on.
What is this 'Arduino' thing anyway? This tutorials dives into what an Arduino is and along with Arduino projects and widgets.
A step-by-step guide to installing and testing the Arduino software on Windows, Mac, and Linux.
The next step is to install the Attiny addon. The following steps in 1a and 1b will explain how to manually install the ATtiny board files for Arduino.
Tip: For beginners, you can automatically install using the Arduino boards manager by following the directions in "Installing the ATtiny Support in Arduino v1.6.4+."
Step 1a: Download the ATtiny Addon
To manually add ATtiny's to the standard Arduino IDE Board menu, you'll need to add a few files that help define the hardware. The latest ATtiny hardware definitions are kept in a repository on GitHub.
You can download them from there, or simply click on the archived links below (note: There are different files depending on which version of Arduino you are using):
- ATtiny for Arduino 1.0.x
- ATtiny for Arduino 1.6.x
Extract the ZIP folder, and don't forget where you put it!
Step 1b: Move the attiny Folder
There should be an attiny folder living within the attiny-ide-1.x.x.zip file you downloaded. Copy that folder and paste it into a folder called hardware within your Arduino Sketchbook directory.
If you're not sure where your Arduino sketchbook is, open Arduino and go to File > Preferences. The Sketchbook location should be the topmost entry in the Preferences dialog. By default, the sketchbook is usually an Arduino folder within your home folder (e.g. C:\Users\userName\Arduino on Windows, or /Users/userName/Documents/Arduino on Mac).
If there's not a hardware folder already in your Sketchbook make one. After placing the attiny folder in there, your directory structure should look a little something like this:
Open and Configure Arduino



Almost to the fun part! Open Arduino. If you opened Arduino in the last step, close it and restart it.
Under the Tools > Board menu, you'll find the effects of the attiny folder. There should be twelve new entires in the board list, which allow you to program ATtiny45's, 85's, 44's and 84's. Each microcontroller can be set to a variety of clock speeds -- internal 1MHz or 8MHz or external 20MHz.
If you're using a bare, previously untouched ATtiny85 select ATtiny85 (internal 1 MHz clock). Be careful selecting here, selecting the 8 MHZ option will only make your sketch run slow, but selecting the 20 MHz option can "brick" your ATtiny. Do not select the 20 MHz option unless you have an external clock attached!
Note: Depending on your Arduino IDE version, you may need to individually select the attiny's Processor (i.e. ATtiny85) and Clock (i.e. 8MHz (internal)).
Unlike other Arduino boards, you don't have to select a Serial Port when using the Tiny AVR Programmer. But you do need to select a Programmer. Under the Tools > Programmer menu, select USBtinyISP.
Plug in the ATtiny

Getting close to blinking! When you plug the ATtiny into your Programmer, make sure you get the polarity correct. The small, etched circle on the IC should line up with the "notch" on the Programmer's socket and silkscreen.
To get the IC into the socket, you may need to bend the legs on each side inwards a tad.
Upload Code




Time for the Blink sketch! The Tiny AVR Programmer has an on-board LED, connected to the ATtiny, which we can use to verify that code on the IC is running. The LED is connected to pin 0 in the Arduino environment. Copy/paste this code into your Arduino window:
int blinkPin = 0;
void setup()
{
pinMode(blinkPin, OUTPUT);
}
void loop()
{
digitalWrite(blinkPin, HIGH);
delay(500);
digitalWrite(blinkPin, LOW);
delay(500);
}
Then click the Upload button just as you would with any Arduino board. The code will compile, and then it should upload insanely fast. That's the wonders of direct in-system programming for you. If successful, the on-board amber LED should start blinking.
Note: You can also upload using the Arduino IDE menu. Depending on your Arduino IDE version, you can select either Sketch > Upload Using Programmer or Sketch > Upload Using Programmer.
Troubleshooting Tip: If you receive the following Arduino error, this might be due to the connection or an issue with the drivers.
avrdude: Error: Could not find USBtiny device (0x1781/0xc9f)
You should see this at the bottom of the Arduino IDE in the text console.
If the issue is related to the connection, try unplugging/replugging the AVR programmer back into your USB cable or USB port. You also want to try a different USB cable.
Otherwise, the issue may be due to the drivers. This may be caused by the driver not being installed correctly, or there is a driver conflict. Open up your device manager to view the device. The image on the left shows the device showing up as the libusb-win32 devices > FabISP. The image on the right shows the device showing up as Other devices > FabISP.
Uploading Code the Hard Way
If you’re looking for more control over your Tiny AVR Programmer – and the AVR it’s connected to – follow along the tutorial for the Pocket AVR Programmer. While the tutorial was written for the Pocket AVR Programmer, it is functionally the same for the Tiny AVR Programmer. Just make sure to connect to the respective ICSP pins on the target AVR chip.