AdSense

Wednesday 28 August 2013

Arduino code on ATtiny

As you can read in my last posts I am working at a remite control at the moment. For this purpose the "normal" ATmega8 isn't the best choice (too big, too expensive, 5V supply voltage). So the project is based on an ATtiny, but I still want to use the features and the libraries of the Arduino IDE. How you can use the IDE to programm an ATmega8 can be read in my first post on this blog. It was pretty easy because Arduino supports the ATmega8 out of the box.
For the ATtiny, a few more steps have to be taken. With the following instructions you can add the ATtiny45, ATtiny85, ATtiny24, ATtiny44 and ATtiny84 to the Arduino IDE.

First of all you have to download this file. The containing folder "attiny" must be copied to the folder "hardware" in your Arduino installation. It should look like this: "C:\Programs\Arduino\hardware\attiny".


The folder contains the file "boards.txt". It contains the information to the used "boards" (fuse settings, clock frequency,...) - in our case it's only the ATiny. Only the "boards" listed in this file will appear in the IDE. The file only includes the settings for the use of the internal clock source. For an external clock source, you have to adapt the settings. In this case it's important so set the correct fuses, otherwise you will have timing problems.

Now you have to tell the IDE the pin settings of your ATTiny. The folder "variants" in the archive you just downloaded  contains the subfolders "tiny8" and "tiny14". In these folders you can find a file named "pins_arduino.h" which specifies the pin mapping of the Tiny. In the file you can also see which pin of the ATtiny has which "Arduino function". For ATTiny24/44/84 this would be for example



                                          +-\/-+
                                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)        PWM
                                          +----+

When you start the Arduino IDE, you should see the ATtiny under "Tools-Board":

From now on, it's business as usual. Depending on the used ATiny, there might be some restrictions, e.g. with interrupts. Furthermore your have to use a programmer like the USBasp to programm the Tiny.

These instructions are also valid for every other ATtiny (and ATmega) - you just have to find the right "pins_arduino.h" or create it for yourself.

No comments:

Post a Comment