You are on page 1of 5

Small tutorial for a tiny Arduino: the challenge to pin the pins.

While making an application for the ATtiny84, I discovered strange problems. It turns out that using an ATtiny as an Arduino is not totally straight forward. At hlt.media.mit.edu they have a nice tutorial and software for using the ATtiny84 and ATtiny85 as Arduino’s, but there are some problems with the tutorial (at least for the ATtiny84). In the end the problems were simple to solve and also reasonable, but they help us better understand Arduino and also allow us to close the gap between Arduino and AVR-GCC a bit further. Note: I’m using Arduino 1.0. The Arduino tiny libraries come from arduinotiny.googlecode.com (that after all caused the problems, but read further to find out how I resolved them).

Image 1. The pinout according to hlt.media.mit.edu. The very complete tutorial from hlt.media.mit.edu gives us the pinout like in image 1. Unfortunately when uploading, the ATtiny didn’t work as expected... Well, what is your problem then?!

Pinning the pins - Resolving ATtiny Arduino issues. / J.A. Korten / CC Share Alike !

1

// wait for a second digitalWrite(4.h #define PIN_A0 #define PIN_A1 #define PIN_A2 #define PIN_A3 #define PIN_A4 (10) ( 9) ( 8) ( 7) ( 6) 2 Pinning the pins . LOW). then off for one second. Now let’s see how they are declared in core_pins. HIGH). OUTPUT).A.. Korten / CC Share Alike ! ./* TinyBlink Turns on an LED on for one second.A. First let’s see the original Atmel datasheet. The pinout from the attiny24/44/84 datasheet So it turns out PA5 and PA6 become high and low (and vice versa) instead. Our not so well working blinker When putting this sketch on the attiny84 it turns out that (physical) pins 7 and 8 alternate! So how do we find out what exactly the problem is. / J. */ void setup() { // initialize the digital pins as outputs. Korten to let two LED’s alternate. OUTPUT). // set the LED on delay(1000). Image 2. // wait for a second } Sketch 1. // set the LED off digitalWrite(5. pinMode(5.Resolving ATtiny Arduino issues. pinMode(4.. LOW). } void loop() { digitalWrite(4. Modified by J. // set the LED off delay(1000). // set the LED on digitalWrite(5. repeatedly. HIGH).

pinMode(6. Korten / CC Share Alike ! 3 . Korten to let two LED’s alternate. // set the LED on digitalWrite(6. Modified by J. repeatedly. */ void setup() { // initialize the digital pins as outputs.A.Resolving ATtiny Arduino issues. HIGH). // wait for a second digitalWrite(5.A. OUTPUT). // set the LED off digitalWrite(6. LOW). // set the LED on delay(1000). then off for one second. / J. // set the LED off delay(1000). LOW). HIGH). // wait for a second } Table 1.#define PIN_A5 ( 5) #define PIN_A6 ( 4) #define PIN_A7 ( 3) #define PIN_B0 ( 0) #define PIN_B1 ( 1) #define PIN_B2 ( 2) #define PIN_B3 (11) /* RESET */ This seems to give some important clue: in Arduino pin 4 and 5 are respectively associated with pins PA6 and PA5! We in fact wanted this: #define PIN_A0 (10) #define PIN_A1 ( 9) #define PIN_A2 ( 8) #define PIN_A3 ( 7) #define PIN_A4 ( 6) #define PIN_A5 ( 5) #define PIN_A6 ( 4) #define PIN_A7 ( 3) #define PIN_B0 ( 0) #define PIN_B1 ( 1) #define PIN_B2 ( 2) #define PIN_B3 (11) /* RESET */ If we want to alternate between PA4 and PA5 we then must change our sketch to this: /* TinyBlink Turns on an LED on for one second. OUTPUT). pinMode(5. Complete mapping Pinning the pins . } void loop() { digitalWrite(5.

So in fact it turns out that different libraries use different pin mappings (see Source 1). we’ll use a port of the Arduino core libraries created by Alessandro Saporetti and slightly modified by HLT.” So that is the definite end of this mystery :) Lesson learned. It was modified by R.Resolving ATtiny Arduino issues. Mellis library. / J. PWM In Source 1 one can see that the Mellis-based library would in fact work with the examples from the MIT high-low tech tutorial. // ATMEL ATTINY84 / ARDUINO // // +-\/-+ // VCC 1| |14 GND // (D 10) PB0 2| |13 AREF (D 0) // (D 9) PB1 3| |12 PA1 (D 1) // PB3 4| |11 PA2 (D 2) // PWM INT0 (D 8) PB2 5| |10 PA3 (D 3) // PWM (D 7) PA7 6| |9 PA4 (D 4) // PWM (D 6) PA6 7| |8 PA5 (D 5) // +----+ Source 1. Korten / CC Share Alike ! 4 . the methods are not Arduino compatible so converting a sketch causes us more work) is the David A.Physical pin 2 3 [4] 5 6 7 8 9 10 11 12 13 Attiny84 pin name Software pins PB0 PB1 PB3 PB2 PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0 0 1 11 2 3 4 5 6 7 8 9 10 An other library that is less Arduino compatible (I mean. It might however be that the performance of the Mellis based libraries is slightly better since they define some functions using macros instead of doing it inline (the normal way). always check your libraries when doing more complex stuff! Pinning the pins .A. Some comments from the Mellis tiny14 pins_arduino. Wiersma (a fellow adult LEGO hobbyist or as we call it AFOL) for the ATtiny84 and A.com library caused the pin mappings to be off from the examples used in the MIT tutorial. The guys and gals from MIT actually also state: “To program them.googlecode.h file. Saporetti for the ATtiny45. My use of the arduino-tiny.

media.nl LEGuanO is powered by Ministickers.edu (Programming an ATtiny w/ Arduino 1. white ‘safe’ blink option d. also read other tutorials there! About us We are Arduino enthusiasts that use Arduino for all kinds of applications (mostly educational. two servos for the (optional) automated barriers b. At this moment we use the ATtiny84 for an automated level crossing.LEGuanO. visit us at www.0). from primary to university level. / J.nl Pinning the pins .com MIT High-Low Tech tutorial: hlt. either a LEGO PF (tm) compatible receiver e. This project is called LEGuanO. connectors for red warning lights (alternating) c. As Adult Fans Of LEGO (AFOLs). we also enable others (that are not so tech-able) to enjoy Arduino for LEGO applications.mit.References Arduino ATtiny library: arduino-tiny. or reed sensors for automated functioning of the crossing The LEGuanO has a footprint of 4 by 4 (LEGO) studs and can be easily connected to LEGO bricks.A.Resolving ATtiny Arduino issues.googlecode. Note: this is a very educational site. The potential of the ATtiny84 is fully used: a. Korten / CC Share Alike ! 5 .