Run Arduino Code on an ATtiny

I’ve been in this situation many times: I just finished an Arduino project, I’m happy with it and would love to save it, but I only have 2 Arduino boards.  Do I sacrifice one to keep this project intact or pull everything off the breadboard and move on? For all the Arduino enthusiasts that can relate to this, thankfully that’s not the only 2 choices.

In my last post I mentioned the Arduino-Tiny project that allows you to use ATtiny chips as an alternative to a full Arduino in projects. For smaller projects that only need a couple pins, this is a great solution. It’s pretty simple to do and in most cases you probably have everything you need to do it. To upload the Arduino code to an ATtiny you can use a dedicated hardware programmer or you can use an Arduino as an in-system programmer (ISP). Here is how the whole process works:

Components you’ll need:

  • ATtiny chip (in this example I’m using an ATtiny85 but many others are supported)
  • Arduino (Uno or Duemilanove)
  • Breadboard
  • Jumper wires
  • 10 uF Capacitor (only if using an Arduino Uno)
  • 1 LED with resistor
  • 3 LEDs of different colors with resistor (Optional)

Step 1

UPDATE 5/28/2012: There was a bug in version 1.0 of the Arduino software that broke the ArduinoISP sketch. This bug has been fixed in version 1.0.1 of the Arduino software. Please upgrade before performing this step.

First we need to upload the ArduinoISP sketch so we can use the Arduino to program the ATtiny.

  1. Open up the Arduino software
  2. click File>Examples>ArduinoISP
  3. upload the sketch.

Step 2

Next we have to setup the wiring to allow the Arduino to program the ATtiny.

Here is how the connections need to be made:

ArduinoISP Wiring Diagram

As stated above the LEDs are optional but can help if you run into issues. Here is what they mean:

Pin 9: Heartbeat – shows the programmer is running

Pin 8: Error – Lights up if something goes wrong

Pin 7: Programming – In communication with the slave

You are going to need to setup this wiring every time you want to upload code to an ATtiny chip so I would recommend setting up a breadboard dedicated for this purpose. I had a proto-shield lying around so I decided to use that. Here is a picture of my setup:

ArdunioISP wiring on Protoboard

Step 3

This guide assumes you have Arduino IDE version 1.0, to install support for programming ATtiny chips you need to:

  1. Download the latest Arduino Tiny code: http://code.google.com/p/arduino-tiny/downloads/list
  2. Create a “hardware” folder inside the Arduino Sketch folder
  3. Extract the zip file to the hardware folder you just created.
  4. Open Arduino and check the Tools>Board submenu. You should have ATtiny chips as optionsATtiny Chips in Arduino Boards Menu

Step 4

Now you are ready to upload a test program to your ATtiny:

Here is the pinout for the ATtiny85:ATtiny85 Pinout

For a more complete reference for the pinouts of various ATtiny chips refer to: http://www.akafugu.jp/posts/resources/reference-sheet/

A good test here is to upload the Blink sketch.

  1. First hook up an LED to the D4 pin on the ATtiny
  2. Open File>Examples>Basics>Blink
  3. Change the sketch from using pin 13 to use pin 4
  4. Go to Tools>Board and select the ATtiny chip you are programming
  5. Go to Tools>Programmer and select “Arduino as ISP”
  6. Then click the Upload button
  7. Your LED should start blinking now

This is just a basic example but as you can see you have 6 usable pins on this little chip. If you want to expand the functionality of this there is also an I2C library that works on ATtiny chips and acts as a sender or receiver.

8 thoughts on “Run Arduino Code on an ATtiny

  1. Pingback: Control Relays over I2C with ATtiny running Arduino Code | Fork Robotics

  2. Pingback: How to Build a BlinkM Clone | Fork Robotics

  3. Very goog your pinout picture, it explains very well the intrincate pin operation mode.
    Thanks.

  4. Very nice tutorial. Very helpful. However, I think you have the polarity of your capacitor mixed up. The positive side should be connected to Reset, the negative side (white strip) should be GND.

Leave a Reply