Last updated: 18 May 2022
The ATtiny is a family of microcontrollers that have been around since 1999 (first produced by Atmel Corporation, now owned by Microchip Technology Inc). The ATtiny85 DIPDual inline package: chip with two rows of parallel pins - perfect for setting up on a breadboard :) chip was released in 2005. It's very popular because of its low price, reliability and consumption-to-speed performance.
The drawbacks are that the ATtiny has less memory, less pins, less architectural possibilities and is (using the default configuration) slower than the Arduino or ATMega328. Also there is no serial communication so you'll need to code and debug your Arduino project on an Arduino and, when you're sure it's working, tweak the pin-numbering and upload it to the ATtiny.
The following pin-out diagram shows how you've only got 5 pins for connecting other components. You might be tempted to say "Hold on - I can clearly see eight pins", and you'd be right; but we need to bear in mind that one is needed for the power supply (VCC), one to go to earth (GND) and one is the reset pin (reset). That's three pins that we can't use for digital input/output. Eight minus three leaves us five pins to play with.
Having said that, for simple projects the ATtiny is more than adequate; and, as we'll see, it's quite easy to port an Arduino project to the ATtiny.
A fun (and educational) way to do this is by using the Arduino as a programmer. In other words we use the Arduino as a bridge from our PC to the ATtiny to upload our code; then we run the code on the ATtiny completely independently from the Arduino.
Our flame effect project is a perfect example. As we only need four digital output pins, we even have one pin left over :)
(includes paid links)
With the Arduino connected to your PC via the USB cable, mount the ATtiny on the breadboard and connect both devices pins in the following way:
Arduino UNO pin | ATtiny pinThese are the names shown in the pin-out above. The physical pin number is shown in parentheses. |
---|---|
+5v | VCC+ (8) |
GND | GND (4) |
10 | RESET (1) |
11 | pin 0 (5) |
12 | pin 1 (6) |
13 | pin 2 (7) |
Your set-up should look like this:
Tools > Boards
menu that ATtiny25/45/85 is present.file > preferences > additional
boards manager URLs
and add: https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
to the list.
Tools > board > board manager >
select attiny board by amellis (which should now appear in the list) > install
.
File > Examples > select ArduinoISP
.Sketch > Upload
or Ctrl + U
it to the Arduino board.Tools > Programmer > select Arduino as ISP
(not arduinoISP!!!!!).Tools > Burn bootloader
.long r; void setup(){ pinMode(0, OUTPUT); pinMode(1, OUTPUT); pinMode(2, OUTPUT); pinMode(3, OUTPUT); } void flicker(int x){ r = random(100L); digitalWrite(x, r < 90); } void loop(){ flicker(0); flicker(1); flicker(2); flicker(3); delay(100); }
Tools > Board > ATtiny 25/45/85
Tools > Processor > ATtiny85
Tools > Clock > Internal 8 MHz
Sketch > Upload
or Ctrl + U
.This is exactly the same set-up as the flame effect project except we're using ATtiny pins 0, 1, 2 and 3 instead of Arduino pins 2, 3, 4 and 5; and instead of using power from the USB cable, we're using batteries (the diagram shows 4 AAA batteries because I couldn't find a fritzing part for 3 AA batteries :( ). Don't forget that if you haven't got batteries and holder at hand, you can always power the ATtiny chip from your Arduino's VCC and GND pins; but it won't look so impressive (bearing in mind it's supposed to be a stand-alone device ;) ).
Here's the same thing with 2 LEDs connected to a mini-breadboard with no Arduino.