Aug 20, 2014

Programming an ATtiny85 with an Arduino

How to Wire the ATtiny85

The ATtiny85 is a cheap, low functioning microcontroller perfect for small applications, like an automatic fish-feeder. They're small, have low power consumption, and are cheap ($1-2). The ATtinys are made by Atmel, just like the microcontroller that powers an Arduino. What does this mean? It means the ATtinys are programmable with the Arduino software by using an Arduino as a programmer.

When I searched for tutorials on how to wire the Arduino Mega to the ATtiny for programming, it took me very long to find something. Most of the tutorials used an Arduino Uno, which I don't have. When I found out how to do it, I used a breadboard to wire the Tiny to the Mega. Here is an illustration of where to connect the wires:


How to Program the Chip

Now that I had the Arduino wired to ATtiny, I just had to program it. The pins that are indicated in the datasheets are not the same as in the program. For example, pin 3 on the ATtiny is not pin 3 in the sketch, it's actually pin 4. This is an equivalency illustration.




To program the ATtiny, you must first upload the "Arduino as ISP" sketch to the Arduino you use as a programmer. You can find in the Arduino IDE under Files>Examples>ArduinoISP. Once that is completed, you have to download the ATtiny library here. Unzip the file and copy the folder "attiny" into the Arduino folder "hardware". Check the "attiny" folder and make sure that it's contents are "boards.txt" and a folder labeled "variants". Open the Arduino IDE, or restart it if it's open, and there should be more options in Tools>Board the start with "attiny". You can upload a sketch to the board right away under the board "ATtiny85 (internal 1 MHz clock)" or you can easily configure the board to run at 8 MHz. This takes one extra step. Under Tools>Board select "ATtiny85 (internal 8 MHz clock)". Then select "Burn bootloader" under Tools. This makes the chip 
run at 8 MHz.

This is my blink sketch. I used the Arduino to power the ATtiny.


3 comments:

  1. Your article helped me a lot. Thank you very much my friend.

    ReplyDelete
  2. u r awasome i really like the way ur led blink.. may u blink always

    ReplyDelete
  3. the pinout of attiny85 is wrong
    --\/--
    1----8
    2----7
    3----6
    4----5
    ------

    ReplyDelete

What do you think?