Using an ATtiny as an Arduino

Learn how to use ATtiny45 and ATtiny85 microcontrollers with Arduino in chapter forty-four of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – a series of articles on the Arduino universe. The first chapter is here, the complete series is detailed here.

Updated 07/10/2014

Did you know you can use an Atmel ATtiny45 or ATtiny85 microcontroller with Arduino software? Well you do now. The team at the High-Low Tech Group at MIT have published the information and examples on how to do this, and it looked like fun – so the purpose of this article is to document my experience with the ATtiny and Arduino and share the instructions with you in my own words. All credit goes to the interesting people at the MIT HLT Group for their article and of course to Alessandro Saporetti for his work on making all this possible.

Introduction

Before anyone gets too excited – there are a few limitations to doing this…

Limitation one – the ATtiny has “tiny” in the name for a reason:

it’s the one on the left

Therefore we have less I/O pins to play with. Consider the pinout for the ATtiny from the data sheet:

So as you can see we have thee analogue inputs (pins 7, 3 and 2) and two digital outputs with PWM (pins 5 and 6). Pin 4 is GND, and pin 8 is 5V.

Limitation two – memory. The ATtiny45 has 4096 bytes of flash memory available, the -85 has 8192. So you may not be controlling your home-built R2D2 with it.

Limitation three – available Arduino functions. As stated by the HLT article, the following commands are supported:

Other functions may work or become available over time.

Limitation four – You need Arduino IDE v1.0.1 or higher, except for v1.0.2. So v1.0.3 and higher is fine.

So please keep these limitations in mind when planning your ATtiny project.

Getting Started

You can use an existing Arduino-compatible board as a programmer with some external wiring. Before wiring it all up – plug in your Arduino board, load the IDE and upload the ArduinoISP sketch which is in the File>Examples menu. Whenever you want to upload a sketch to your ATtiny, you need to upload the ArduinoISP sketch to your Arduino first. Consider this sketch the “bridge” between the IDE and the ATtiny.

Next, build the circuit as shown below:

schematicuno

Depending on the Arduino board you’re using, you may or may not need the 10uF capacitor between Arduino RST and GND. Follow the schematic above each time you want to program the ATtiny.

Software

From a software perspective, to use the ATtinys you need to add some files to your Arduino IDE. First, download this zip file. Then extract the”attiny” folder and copy it to the “hardware” folder which sits under your main Arduino IDE folder, for example:

hardwarelocationfolder

 Now restart the Arduino IDE. As you’re using the Arduino as a programmer, you need select “Arduino as ISP” – which is found in the Tools>Programmer menu. Next – select the board type using the Tools>Board  menu. Select the appropriate ATtiny that you’re using – with the 1 MHz internal clock option. Now you can enter and upload your ATtiny sketch. When uploading sketches you may see error messages as shown below:

errors

The message is “normal” in this situation, so nothing to worry about.

Creating Arduino sketches for ATtinys

When creating your sketches, note that the pin number allocations are different for ATtinys in the IDE. Note the following pin number allocations:

  • digital pin zero is physical pin five (also PWM)
  • digital pin one is physical pin six (also PWM)
  • analogue input two is physical pin seven
  • analogue input three is physical pin two
  • analogue input four is physical pin three

For a quick demonstration, load the Blink example sketch – File>Examples>1. Basics>Blink. Change the pin number for the digital output from 13 to 0. For example:

Upload the sketch using the methods described earlier. If you’re using programmer method one, your matching circuit is:

blinksch

If you’re using programmer method two, this will blink the on-board LED.

Final example

We test the digital outputs with digital and PWM outputs using two LEDs instead of one:

finalexampleschematic1

And the sketch:

And a quick demonstration video:

So there you have it – another interesting derivative of the Arduino system. Once again, thanks and credit to Alesssandro Saporetti and the MIT HLT Group for their published information. And if you enjoyed this article, or want to introduce someone else to the interesting world of Arduino – check out my book (now in a fourth printing!) “Arduino Workshop”.

visit tronixlabs.com

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our forum – dedicated to the projects and related items on this website.

The following two tabs change content below.

John Boxall

Founder, owner and managing editor of tronixstuff.com.

12 Responses to “Using an ATtiny as an Arduino”

  1. Gabriel Joachim Perumal says:

    how to use digitalread for attiny?

  2. Mark Beckett says:

    Digispark is a complete ATtiny85 with bootloader and USB connection.
    A modified IDE is available along with tweaked libraries to suit.
    Check them out at http://www.Digistump.com

    Mark

  3. Mac says:

    ATtiny85(Arduino) have EEPROM function ?

  4. John says:

    Thanks very interesting,you can also use port manipulation commands,only works with 0Bxxxxxxxx not Bxxxxxxxx I have yet to investigate the shiftOut() commands,presumably can be used with a shift register.
    Using a USB asp programmer is very cheap ,quick and easy.

    Many thanks, as always I find your tutorials very informative.

    John

  5. pippin31 says:

    When I try to upload i get this error.
    Blink.ino:10:21: error: Arduino.h: No such file or directory
    Any ideas what’s wrong?

Trackbacks/Pingbacks


Leave a Reply

Receive notifications of new posts by email.

The Arduino Book

Arduino Workshop

Für unsere deutschen Freunde

Dla naszych polskich przyjaciół ...

Australian Electronics!

Buy and support Silicon Chip - Australia's only Electronics Magazine.

Use of our content…

%d bloggers like this: