Martin's corner on the web

Setting up Arduino IDE for working with Attinys

There are a number of posts on the subject already, but I’d like to share my experience as well. Here are the steps I undertook to set up my environment for working with Attiny84 and Attiny85:

  1. As a first step, of course get the latest Arduino IDE. You can keep your old environment intact by installing it in a new folder – I do that myself so I can work with old libraries that are not ported to IDE 1.0 or newer. You get the latest IDE from the official web site.
  2. I am running a 64bit Windows 7 laptop and freshly installed Arduino IDE is terribly slow to open the menus. This is due some bug that has been carried over for ever since at least IDE #17, but fortunately there is a fix. Read all about it here, the fix is to replace a faulty DLL that gives you trouble on 64bit Windows systems.
  3. Next, get the latest Arduino Tiny Core from here. The included in the archive Readme gives you all you need to know on installing the core:
* Ensure the Arduino IDE is NOT running.
* Download the Arduino-Tiny archive (ZIP-file).
* Locate the Arduino Sketch folder.  This is the folder where the Arduino IDE stores Sketches.

* Ensure the "hardware" folder exists under the Arduino Sketch folder.  For example, if the Arduino Sketch folder is...

      C:\Projects\Arduino\

  Ensure this folder exists...

      C:\Projects\Arduino\hardware\

* Extract the contents of the archive into the "hardware" folder.  For example, if the Arduino Sketch folder is...

      C:\Projects\Arduino

  After extracting, the following two files should exist...

    C:\Projects\Arduino\hardware\tiny\boards.txt
    C:\Projects\Arduino\hardware\tiny\bootloaders\attiny84\empty.hex

  And the following folder should contain the Arduino-Tiny core...

      C:\Projects\Arduino\hardware\tiny\cores\tiny\

* Open the "boards.txt" file and change both of the "upload.using" entries to
  the appropriate value for your setup.  Following from the examples above, the
  file would be here...

      C:\Projects\Arduino\hardware\tiny\boards.txt

* Start the Arduino IDE and ensure there are two new boards listed under the 
  [Tools] [Board] menu...

      "ATtiny84 @ 8 MHz"
      "ATtiny84 @ 1 MHz"

You are now ready to use Arduino-Tiny!

4. I have found that many of the compiler errors that you will stumble upon, if you leave it here are related to not updating the avr toolchain. Most probably you will be seeing error messages relating to R_AVR_13_PCREL. There is a good explanation on how to update the avr toolchain that comes bundled with the Arduino IDE to the latest version here.

5.  We are almost there 🙂 . There is some nasty incompatibility between the Jeelib that we heavily rely on and the Tiny Core, luckily there is a solution as well. Follow the instructions here if you get errors like “hardware\tiny\cores\tiny/Print.h:71: error:   overriding ‘virtual void Print::write(uint8_t)'” . The fix requires editing a bit the Ports.h and Ports.cpp so that they work and don’t give you trouble.

So with these steps you do have a fully operational Arduino IDE that supports Attinys.

I program the little guys with an USBTiny ISP programmer, just be careful when you program them and have 3.3V components on the board as well, such as the RFM12B module. Most ISP programmers (like the USBTiny ) do have a jumper that when removed does not power the board with 5V, thus you can use a battery or other 3.3V power source and not fry the other components. If you don’t own an ISP programmer, I do recommend you get one. They are quite cheap and available on ebay for example. I work with USBTinyISP v3.0.

Alternatively you can program the ATTinys with an Arduino as a programmer, but that is rather masochistic approach given that an ISP programmer costs $9 delivered.

12 thoughts on “Setting up Arduino IDE for working with Attinys

  1. Pingback: Atmega32U4 based micro node with RFM12B | Martin's corner on the web

  2. Mike Alport

    Hi Martin,
    I have made up a number of your SuperFunky and RFMtoPi boards but am currently tearing my hair out!

    If you can give me any pointers on the following problem, I would be grateful:
    I am running OSX 10.8.3 with Arduino IDE 1.0.4.
    I have downloaded arduino-tiny-0100-0015.zip and put the two folders, tiny and tools in the Arduino hardware directory.
    I am using an Arduino Duemilanove as an ISP.
    I can compile, upload and run the blink.ino fine.
    But when I try and compile any softwareSerial program such as SoftwareSerialExample of your TinySensor_RF_Demo I get a bunch of compile errors when I select the ATTiny84. Interestingly I don’t get these errors when I select the Arduino Duemilanove w/ ATmega328.

    The compile errors are:
    /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn84.o: In function `__vector_default’:
    (.vectors+0x2): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_1′ defined in .text.__vector_1 section in core.a(WInterrupts.c.o)
    /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn84.o: In function `__vector_default’:
    (.vectors+0x16): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_11′ defined in .text.__vector_11 section in core.a(wiring.c.o)
    /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn84.o:(.init9+0x0): relocation truncated to fit: R_AVR_13_PCREL against symbol `main’ defined in .text.main section in core.a(main.cpp.o)
    /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn84.o:(.init9+0x2): relocation truncated to fit: R_AVR_13_PCREL against symbol `exit’ defined in .fini9 section in /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/avr25/libgcc.a(_exit.o)
    TinySensor_RF12_Demo.cpp.o: In function `saveConfig’:
    /Applications/TinySensor_RF12_Demo.ino:82: relocation truncated to fit: R_AVR_13_PCREL against symbol `Print::println(char const*)’ defined in .text._ZN5Print7printlnEPKc section in core.a(Print.cpp.o)
    TinySensor_RF12_Demo.cpp.o: In function `showString’:
    /Applications/TinySensor_RF12_Demo.ino:106: relocation truncated to fit: R_AVR_13_PCREL against symbol `Print::print(char, int)’ defined in .text._ZN5Print5printEci section in core.a(Print.cpp.o)
    /Applications/TinySensor_RF12_Demo.ino:107: relocation truncated to fit: R_AVR_13_PCREL against symbol `Print::print(char, int)’ defined in .text._ZN5Print5printEci section in core.a(Print.cpp.o)
    TinySensor_RF12_Demo.cpp.o: In function `showHelp’:
    /Applications/TinySensor_RF12_Demo.ino:113: relocation truncated to fit: R_AVR_13_PCREL against symbol `Print::println(char const*)’ defined in .text._ZN5Print7printlnEPKc section in core.a(Print.cpp.o)
    /Applications/TinySensor_RF12_Demo.ino:132: relocation truncated to fit: R_AVR_13_PCREL against symbol `Print::print(int, int)’ defined in .text._ZN5Print5printEii section in core.a(Print.cpp.o)
    /Applications/TinySensor_RF12_Demo.ino:133: relocation truncated to fit: R_AVR_13_PCREL against symbol `Print::print(char const*)’ defined in .text._ZN5Print5printEPKc section in core.a(Print.cpp.o)
    /Applications/TinySensor_RF12_Demo.ino:134: additional relocation overflows omitted from the output

    1. Martin Post author

      Mike,
      did you complete step 4 outlined in the post? I was getting the same errors, but that was fixed for me once I followed the simple instructions that are linked to item 4.

      1. Troy Miller

        I tried to follow the post but on my version of the jeelib library that change has already been made. I tried just replacing the section but still I get the same error. Using arduino 1.0.1 and 1.0.2, and 1.04.

  3. Mike Alport

    I couldn’t figure how to implement the AVR-tools upgrade in OSX from your link.

    But did find a pointer at:
    https://github.com/pbrook/minimus-arduino/wiki
    using CrossPack and the following instructions:

    avr-gcc used by the Arduino IDE is too old to support atmega32u2, luckily there are nice people that maintain an AVR Crosspack for OSX here: http://www.obdev.at/products/crosspack Download and install that

    By default it install into /usr/local/CrossPack-AVR while the Arduino IDE expects it to be in its app directory, so we do the ‘ol switcharoo

    cd /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/
    mv avr avr-original
    ln -s /usr/local/CrossPack-AVR /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr
    Rejoice

  4. Mike Alport

    Now trying to compile TinySensor_RF12_Demo.ino only get 1x compile error:
    TinySensor_RF12_Demo.ino:86:18: error: variable ‘helpText1’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’

    1. Martin Post author

      That’s odd, no idea how to fix it (check what google has to say).
      BTW, why not set Arduino IDE on your Raspberry Pi?

  5. casestudies

    I’m having a lot of trouble compiling an Arduino sketch for the ATtiny84 chip. I followed the above, and many other hints on the web, but can’t seem to get it to compile when using the attiny84at8 settings. I’m using a program called “ino” for compiling Arduino sketches on the command line so that I can get the hex file to burn to the chip. Running on a Raspberry Pi Arduino v 1.0.1

    I was wondering if you have happened to come across the following error message during compiling.

    pi@emoncmspi ~/TinyTX/TinyTX_RX_Simple/ino $ ino build -m attiny84at8
    src/TinyTX_RX_Simple.cpp
    In file included from /usr/share/arduino/libraries/jeelib/JeeLib.h:7:0,
    from .build/attiny84at8/src/TinyTX_RX_Simple.cpp:2:
    /usr/share/arduino/libraries/jeelib/Ports.h:696:49: error: âSerialâ was not declared in this scope
    /usr/share/arduino/libraries/jeelib/Ports.h:697:60: error: âSerialâ was not declared in this scope
    make: *** [.build/attiny84at8/src/TinyTX_RX_Simple.o] Error 1

    Any hints would be great! Thanks.