How to Program an Attiny85 From an Arduino Uno

by NemesisC in Circuits > Arduino

176124 Views, 88 Favorites, 0 Comments

How to Program an Attiny85 From an Arduino Uno

5828bd4fdeafa439470002ea.jpeg

Quick tutorial showing how to program the ATtiny85 from the Arduino IDE with the help of the Arduino Uno!

This tutorial was requested by my friend Orlando so hope it helps !

Comments,Concerns,Feedback,Requests welcomed:

@NemesisContrer8

Add Support for the ATtiny85 to the Arduino URL Board Manager

Screen Shot 2016-11-13 at 10.46.22 AM.png

By default the Arduino IDE does not support the ATtiny85 it's required to add support for the Attiny85 to the Arduino Board Manager:

  • From the Arduino IDE Go to Arduino->Preferences then scroll down to Additional Board Managers URLs
  • Copy & paste the following (if you already have a board manager URL just add a comma before pasting)

Thanks David-one of the Arduino founders for writing the code!

<p>https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json</p>
  • Press "OK" at the bottom then restart the Arduino IDE

Install the ATtiny Board Package

Screen Shot 2016-11-13 at 11.02.31 AM.png
Screen Shot 2016-11-13 at 11.02.43 AM.png
Screen Shot 2016-11-13 at 10.52.38 AM.png
  • From the Arduino IDE go to Tools--> Board-->Boards Manager
  • A new tab will open and at the top of the tab type: attiny
  • Select Install on the Attiny by David. A Mellis
  • Restart the Arduino IDE
  • The ATtiny85 board should now be added ! Go to Tools--> Board-->Attiny85

Set the Arduino Uno Into ISP Mode

Screen Shot 2016-11-14 at 1.26.27 PM.png

Since what we want is to be able to program the ATtiny85 from the Arduino IDE which requires to burn the bootloader to the ATtiny85 we will need to "prep" the Arduino fist by uploading the ISP sketch to it.

In the Arduino IDE select File-->Examples--> 11. Arduino ISP-->ArduinoISP

the ISP sketch should open and upload it to your Arduino Uno

How a Microcontrollers Pins Are Labeled

Screen Shot 2016-11-13 at 8.56.08 PM.png

Before the connections are made there is a very important fact to know how pins on microcrontrollers/ICs are labeled.

Pin numbers used to program a chip on the Arduino IDE are based on how the chip manufacturer has internally named/aranged the pins . The manufacturer of the ATtiny85 is ATMEL (the AT in ATtiny85-actually stands for ATMEL);It's common for chips to have the first two initials of the company who makes them.

Pins are gathered into groups called "ports" these ports are labeled A,B,C etc. Each port has a number of pins which are labeled 0,1,2,3 etc and stick out on different parts of the chip which is why a microcontroller's physical pin often time will be different than the pin number used when programming the chip.


An example:

PB0 (in the above datasheet) just means pin 0 is located on Port B of the Chip.

If pin 0 was located on Port A the name would look something like PA0 (Port A pin 0)

To add to the complexity pins can have more than one fuction and be labeled multiple names.

Wrapping it all together! :

Writing a program to light an LED on pin 0 on the ATtiny85 might be confusing at first because just by looking at the chip , there is no pin 0! However, by checking the datasheet of the ATtiny85 from ATMEL-snippet shown above-pin 0 is internally located on the chip's port B (and is actually the chip's physical pin 5 )!

Connecting the Arduino to the ATtiny Pins

582a31d84fbade561200087b.jpeg
ATtiny45-85.png

Have an electrolytic capacitor-10uF is recommend but I used a 22uF and it worked fine- to prevent the Arduino from restarting it's self connected to GND & RESET on the Arduino

Use a breadboard and jumper wires to make the connections bellow from the Arduino Uno to the ATtiny85:

Arduino--> ATtiny85

5V            Vcc              
GND           GND               
Pin 13        Pin 2
Pin 12        Pin 1
Pin 11        Pin 0
Pin 10        Reset

Making the ATtiny85 Arduino Compatible

582a300a4936d415bc000303.jpeg
20161114_133458.jpg
Screen Shot 2016-11-14 at 1.31.51 PM.png

By default any fresh microcontroller chip bought will not be able to be programmed with the Arduino IDE out of the box. This is why it's required to burn the Arduino bootloader onto the chip to make sure the chip will accept any programs uploaded via the Arduino IDE.

Quick checklist before pressing "burn bootloader"

  • Go to Tools -> Board scroll to the bottom select ATtiny25/45/85
  • Under Tools -> Processor--> 8 MHz (internal)
  • Under Tools-->Programmer-->Arduino as ISP
  • Check that all wiring, capacitor, and board selections are correct
  • Finally select Burn Bootloader
  • leave the wires connected they will be used in the next step

A message will appear saying "Done Burning Bootloader"

Uploading the Blink Sketch

GIF_20161114_140643.gif
GIF_20161114_140605.gif
582a519915be4dac8f0005ae.jpeg

Test that the ATtiny85 can now receive sketches from the Arduino IDE by uploading the blink example

  • Go to File-->Example-->01.Basics-->blink
  • Edit the sketch by replacing pin 13 with 0
  • Make sure to still have the ATtiny85 board settings from the previous step selected
  • Make sure all wiring is the same as the previous step
  • Upload the sketch
  • Wire an LED by connecting the anode to pin 0 (physical pin 5 ) and the cathode to a 1K resistor connected to ground (physical pin 4)
  • While a resistor is not needed since the battery provides 3v (not enough to blow up an LED) it is recommended to lower the brightness of the LED

Any request for future tutorials all welcomed! Just leave a comment bellow