Introduction to the ATtiny85

What is the ATtiny85?

The ATtiny85 is a microcontroller in a similar vein to the Arduino, but with much less IO pins, smaller memory and a smaller form factor. In fact, when we talk about the ATtiny85 we refer to the IC itself rather than the board. The ATtiny85 can be used as a bare chip on a breadboard, as long as you can supply the correct power for the device. 

But most commonly the ATtiny85 is supplied with a USB interface, either a full USB port such as the DigiStump Digispark or micro USB via a cloned board commonly found on Aliexpress / Banggood etc.

Despite the small package, the ATtiny85 comes with a remarkable number of ways in which we can interface. At the most basic level, we have 5V logic digital I/O pins, three of which can also be used as analog pins for use with components such as the TMP36 sensor. Four of the available pins can also be used with Pulse Width Modulation (PWM). Also available is I2C and SPI for use with other types of sensors and devices.

What can I do with it?

The short answer is, if you can do it with an Arduino, then it is highly likely that it can be done with the ATtiny85. From simple LEDs flashing, to WS2812B multicolour LED strings, to elaborate sensor projects, the ATtiny85 can do it, and with a cloned board retailing for around $2, there is no excuse to try one out.

Building a simple project

In this tutorial, we shall set up our Attiny85 on a Windows laptop and use the board to control three LEDs.

For this project, you will need

  • An ATtiny85
  • 3 x LEDs
  • 4 x Female to male jumper jerky
  • 2 x Male to male jumper jerky
  • Breadboard
  • 3 x 330 Ohm resistors

Installing the software

We shall be using the Arduino IDE to write the code for this project. So if not already installed, download a copy from the Arduino website and install.

Open the Arduino application and click on File >> Preferences and past the following into the Additional Boards Managers URLs: dialog.

http://digistump.com/package_digistump_index.json

Next, go to Tools >> Board >> Boards Manager and from the drop-down menu select “Contributed”.

Select the “Digistump AVR Boards” and click Install.

The install process will take some time, but once completed the installation should trigger an auto install of the drivers for the board.

If the driver install fails to run after adding the board to your list, open the command prompt and enter the following command. Remember to change the USERNAME to match your own!

C:\Users\**YOUR USERNAME**\AppData\Local\Arduino15\packages\digistump\tools\micronucleus\2.0a4\post_install.bat

This will install the drivers for the ATtiny85, and there may be a red cross in the post install screen, but we can confirm that the instal is correct.

To use the ATtiny85 in the Arduino IDE we need to set it as our board. 

Go to Tools >> Board >> and select Digispark (Default - 16.5MHz) don’t worry about the Port.

Building the circuit

On the breadboard, build the circuit as shown in the diagram. The LED cathode (-) legs are on the left of the image, and they connect to a single ground pin on the ATtiny85 via a 330 Ohm resistor. The male to male jumper jerky connects the 330 Ohm resistors for two of the LEDs to the third, creating a single Ground connection that is connected to the ATtiny85. The anode (+) leg of the LED is connected directly to Pins 0,1,2 using the male to female jumper jerky.

Don’t insert the ATTiny85 just yet. First, we need to write some code.

In the Arduino IDE, we shall set up the three pins (0,1,2) that will be used as outputs first and will flash the LEDs attached to them.

void setup()

{

  pinMode(0, OUTPUT);

  pinMode(1, OUTPUT);

  pinMode(2, OUTPUT);

}

Now for the code that will continually loop round, creating the effect of cycling through the LEDs. We start by turning on each LED (HIGH) and then using a delay of 1/10 of a second between each LED turning on.

void loop()

{

  digitalWrite(0, HIGH);

  delay(100);

  digitalWrite(1, HIGH);

  delay(100);

  digitalWrite(2, HIGH);

  delay(100);

Still inside of the loop, we now need to turn off the LEDs in reverse order by pulling the output LOW for each LED. We also keep the same delay between LEDs to create a rhythmic looping pattern.

  digitalWrite(2, LOW);

  delay(100);

  digitalWrite(1, LOW);

  delay(100);

  digitalWrite(0, LOW);

  delay(100);

}

Flashing the code

To write the code to our ATTiny85 click on Sketch >> Upload or click on the right-hand arrow. In the output window, at the bottom of the Arduino IDE, you will be prompted to insert the ATtiny85, do this and the code will be flashed to the ATtiny85 within a few seconds. Your LEDs will now start flashing in a cycling pattern.

 

Latest Articles

The Electromaker ‘Connectivity’ launch contest

We are giving away FREE HARDWARE to the first 100 people that submit their project idea...

Build Your Own Arduino Keyboard Synth!

Like the Raspberry Pi, the Arduino is one of those tools that has immense potential but can end up being put away in a box and forgotten about. Well, now it’s time to open that box again: this project is the perfect way to start getting to grips with Arduino once more.

Coding the BBC micro:bit with Edublocks

The BBC micro:bit is not short of programming languages. We can use blocks, Javascript, Micro Python and the legacy TouchDevelop, CodeKingdoms and Microsoft Blocks.