Setup Arduino IDE to program Attiny 13/44/45/84/85

      1 Comment on Setup Arduino IDE to program Attiny 13/44/45/84/85

This post explains how to install the popular Arduino IDE (v1.6) on your computer and configure it so you can program Attiny micro controllers.

Install Arduino IDE

First, download the IDE from this location: Arduino IDE download site.
Once it is downloaded, you can run the program.
What you downloaded is the application, not an installer, so simply move that application to a folder that makes sense to you.
In my case, I placed it in a folder called C:/Arduino on my Windows PC. On my Mac, I simply copied that executable into the Applications folder.

Add support for Attiny 44/45/84/85

If it’s not already running, launch the Arduino IDE.

Open the following menu option:
– On windows: File | Preferences…
– On Mac: Arduino | Preferences…

This will open the Preferences window.
Copy the following URL into the “Additional Board Managers URLs” text box: https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
This is an extension, from MIT, that’s recommended by Arduino.
If you want to see what other board managers exists, you can find the list here: http://playground.arduino.cc/Main/ArduinoOnOtherAtmelChips.
An unofficial list of other board managers can also be found here: https://github.com/arduino/Arduino/wiki/Unofficial-list-of-3rd-party-boards-support-urls.

OK, let’s continue with the configuration.
Press the OK button to close the preferences window.
Then, open the Tools | Board | Boards Manager… menu option.
You should now see a list of board managers.
Find the one that’s named “ATtiny by David A. Mellis” and press it’s install button.
If you don’t see that board entry, close the Arduino IDE and restart it (there used to be a bug in the IDE).
That’s it, you now have support for some Attiny micro controllers!
If you open the Tools | Board menu, you will see an entry for ATtiny micro controller at the end of the list.

Add support for Attiny 13/13A

As of now, there is no official board manager for Attiny 13.
So, we will have to perform a few manual steps to add support for that micro controller.

Go on the Arduino on other Atmel chips page and download the file that will used to add support for ATtiny13.
If it’s open, close your Arduino IDE.

On Mac:
Open the Finder application.
In Finder, open the Documents folder.
You should see a folder called Arduino.
Open it.
If the Arduino folder doesn’t contain a “hardware” folder, create it.
In the hardware folder, create a folder called “attiny_13”.
Open the attiny_13 folder.
Open the file you downloaded previously (support for Attiny13). It should contain a folder called “avr”.
Copy the “avr” folder, from the downloaded file, to the attiny_13 folder you created on your computer.

On Windows, follow the same steps as for Mac, except that you will use the File Explorer instead of Finder. The Arduino folder will be found under the “My Documents” folder.

You should now have the following folder structure:

Documents/Arduino/hardware/attiny_13/avr/
    boards.txt
    cores/
        15 files
    platform.txt

You will have to replace the content of the boards.txt file with the following text:

##############################################
menu.cpu=Processor
menu.clock=Clock
attiny_13.name=ATtiny_13
attiny_13.bootloader.tool=arduino:avrdude
attiny_13.bootloader.unlock_bits=0xff
attiny_13.bootloader.lock_bits=0xff
attiny_13.build.core=arduino:arduino
attiny_13.build.board=attiny_13
attiny_13.upload.tool=arduino:avrdude
##############################################

#################################################
attiny_13.menu.cpu.attiny13=ATtiny13
attiny_13.menu.cpu.attiny13.upload.maximum_size=1024
attiny_13.menu.cpu.attiny13.build.mcu=attiny13
attiny_13.menu.cpu.attiny13.build.variant=core13
attiny_13.menu.clock.internal96=9.6MHz (internal)
attiny_13.menu.clock.internal96.bootloader.low_fuses=0x7A
attiny_13.menu.clock.internal96.bootloader.high_fuses=0xff
attiny_13.menu.clock.internal96.build.f_cpu=9600000L
################################################

attiny_13.menu.clock.internal48=4.8MHz (internal)
attiny_13.menu.clock.internal48.bootloader.low_fuses=0x79
attiny_13.menu.clock.internal48.bootloader.high_fuses=0xff
attiny_13.menu.clock.internal48.build.f_cpu=4800000L
################################################

attiny_13.menu.clock.internal12=1.2MHz (internal)
attiny_13.menu.clock.internal12.bootloader.low_fuses=0x6a
attiny_13.menu.clock.internal12.bootloader.high_fuses=0xff
attiny_13.menu.clock.internal12.build.f_cpu=1200000L
################################################

If you don’t, you won’t see the ATtiny 44/45/84/85 micro controller anymore in the Arduino IDE menus.

The last step is to fix the platform.txt file so you don’t get warnings every time you compile your applications.
You have 2 options here. It you are using Arduino 1.6.6, you can simply replace the content of the file with the following:

name=Attiny13
version=0.22

# AVR compile variables
# --------------------- 

# Default "compiler.path" is correct, change only if you want to overidde the initial value
compiler.path={runtime.tools.avr-gcc.path}/bin/
compiler.c.cmd=avr-gcc
compiler.c.flags=-c -g -Os -w -ffunction-sections -fdata-sections -MMD
# -w flag added to avoid printing a wrong warning http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59396
# This is fixed in gcc 4.8.3 and will be removed as soon as we update the toolchain
compiler.c.elf.flags=-w -Os -Wl,--gc-sections
compiler.c.elf.cmd=avr-gcc
compiler.S.flags=-c -g -x assembler-with-cpp
compiler.cpp.cmd=avr-g++
compiler.cpp.flags=-c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD
compiler.ar.cmd=avr-ar
compiler.ar.flags=rcs
compiler.objcopy.cmd=avr-objcopy
compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
compiler.elf2hex.flags=-O ihex -R .eeprom
compiler.elf2hex.cmd=avr-objcopy
compiler.ldflags=
compiler.size.cmd=avr-size

# This can be overriden in boards.txt
build.extra_flags=

# These can be overridden in platform.local.txt
compiler.c.extra_flags=
compiler.c.elf.extra_flags=
compiler.S.extra_flags=
compiler.cpp.extra_flags=
compiler.ar.extra_flags=
compiler.objcopy.eep.extra_flags=
compiler.elf2hex.extra_flags=

# AVR compile patterns
# --------------------

## Compile c files
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"

## Compile c++ files
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"

## Compile S files
recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.S.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"

## Create archives
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"

## Combine gc-sections, archives, and objects
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" "-L{build.path}" -lm

## Create eeprom
recipe.objcopy.eep.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.objcopy.eep.flags} {compiler.objcopy.eep.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.eep"

## Create hex
recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"

## Compute size
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
recipe.size.regex=^(?:\.text|\.data|\.bootloader)\s+([0-9]+).*
recipe.size.regex.data=^(?:\.data|\.bss|\.noinit)\s+([0-9]+).*
recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).*


# AVR Uploader/Programmers tools
# ------------------------------

tools.avrdude.cmd.path={path}/bin/avrdude
tools.avrdude.config.path={path}/etc/avrdude.conf

tools.avrdude.upload.params.verbose=-v
tools.avrdude.upload.params.quiet=-q -q
tools.avrdude.upload.pattern="{cmd.path}" "-C{config.path}" {upload.verbose} -p{build.mcu} -c{upload.protocol} -P{serial.port} -b{upload.speed} -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"

tools.avrdude.program.params.verbose=-v
tools.avrdude.program.params.quiet=-q -q
tools.avrdude.program.pattern="{cmd.path}" "-C{config.path}" {program.verbose} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{build.path}/{build.project_name}.hex:i"

tools.avrdude.erase.params.verbose=-v
tools.avrdude.erase.params.quiet=-q -q
tools.avrdude.erase.pattern="{cmd.path}" "-C{config.path}" {erase.verbose} -p{build.mcu} -c{protocol} {program.extra_params} -e -Ulock:w:{bootloader.unlock_bits}:m -Uefuse:w:{bootloader.extended_fuses}:m -Uhfuse:w:{bootloader.high_fuses}:m -Ulfuse:w:{bootloader.low_fuses}:m

tools.avrdude.bootloader.params.verbose=-v
tools.avrdude.bootloader.params.quiet=-q -q
tools.avrdude.bootloader.pattern="{cmd.path}" "-C{config.path}" {bootloader.verbose} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{runtime.platform.path}/bootloaders/{bootloader.file}:i" -Ulock:w:{bootloader.lock_bits}:m


# USB Default Flags
# Default blank usb manufacturer will be filled it at compile time
# - from numeric vendor ID, set to Unknown otherwise
build.usb_manufacturer=
build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}'

Or, simply look at the warnings while compiling in the Arduino IDE and fix the platform.txt file accordingly.

You can now launch the Arduino IDE.
You should now see the entry, for the ATtiny 13 micro controller at the end of the list: Tools | Boards.

Your IDE is now ready to program ATtiny13/44/45/84/85 micro controllers!

In my next posts, I will explain how to program an ATtiny using 2 different approaches:
using an Arduino Uno as an ISP programmer
using an USBtinyISP programmer

One thought on “Setup Arduino IDE to program Attiny 13/44/45/84/85

  1. Pingback: Programming An ATtiny Using An Arduino Uno | Francois' Corner

Leave a Reply

Your email address will not be published. Required fields are marked *

Comments Protected by WP-SpamShield Spam Plugin