ATTiny85 – Core Programming

Through some researches I did online on how to minimize components use, I stumbled with using an ATTiny85 chip to be used in the project. And through some more researching, I decided to have my new project done using the ATTiny85 Chip.

ATTiny85 Chip

I bought these chips from Ali-Express. First I need to study first the pin out of the ATTiny85, and relate this to the ATTiny85 Chip The image below shows the pin out of the integrated circuit.

The notch at the top of the chip indicates where pin 1 is, then the count continues consecutively counter-clockwise. Now, let’s look at the ATtiny85.

At the ATtiny85 IC diagram, we see the following pins labeled with PB0, PB1, PB2, PB3, PB4, and PB5. You will also see GND and VIN pins. These correspond to the Ground (Pin 4 of the IC), and Input Voltage (Pin 8 of the IC).

ARDUINO NANO TO ATTINY85 CONNECTIONS

Let’s connect the necessary pins together on both boards.

1 x Arduino Nano (or any Arduino board will do)
1 x ATtiny85
6 x Jumper Wires
1 x Electrolytic Capacitor – 10µF ~ 25V

We need to connect the MOSI, MISO and SCK pins of both boards together (refer to the IC pin out), and Digital Pin 10 of the Arduino Nano to P5 of the ATtiny85.

Connect the following (I am using an Arduino Nano, so you have to take note the necessary pins of the board you are using when using it as an ISP).

Add a 10uF capacitor between RESET and GND in Arduino. This is to avoid Arduino Nano from being auto reset when we upload the program to attiny85. If you are using a electrolytic capacitor make sure the anode goes in GND of  Arduino Nano.

 

Arduino Nano ATTINY85
MOSI Digital Pin 11 PB0 (Chip Pin 5)
MISO Digital Pin 12 PB1 (Chip Pin 6)
SCL Digital Pin 13 PB2 (Chip Pin 7)
RESET Digital Pin 10 PB5 (Chip Pin 1)
VCC VCC (5V) VCC (Chip Pin 8)
GND GND GND (Any GND pin)

 

There are two things we need to set up to successfully program the ATTiny85.

INSTALLING THE ATTINY BOARDS

Open the  Arduino IDE Software then go to Arduino > Preferences. You will see Additional Boards Manager URLs. Add this link there, by pressing the rightmost icon. and ad this link:


https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json


Press OK (then another OK to exit from Preferences).

Now, go to Tools > Board > Boards Manager. Type attiny in the search field, and you should see attiny by David A. Mellis. Click it (attiny by David A. Mellis) and install the board. Now, you should see attiny boards from the list when you go to Tool > Boards. Scroll down to verify that the board is indeed installed.

ARDUINO AS ISP

Attach the Arduino Nano to your computer. Go to File > Examples > ArduinoISP, and click on Arduino ISP. Then go to Tools > Boards and select Arduino Nano (or your preferred board). Go to Tools > Port and select the port where your board is connected to. Upload the ArduinoISP sketch to your Arduino Nano (or your preferred board) by going to Sketch > Upload. At this stage, your Arduino Nano is ready to be used as a programmer.


Note: In some cases you need to select Processor : “ATMega328P (Old Bootloader)”


UPLOADING SKETCH TO ATTINY85 DEVELOPMENT BOARD

Make sure that the connections are as stated as described here above. Open the program / sketch you want uploaded to your ATtiny85. Go to Tool and setup the following.

Board: “ATtiny25/45/85”
Processor:  “ATtiny85”
Clock: “Internal 8 MHz”
Port: Select the port where your board is connected to.

Then make sure Arduino as ISP is selected under Tools -> Programmer. By default the ATtiny85 runs at 1MHz. To make it to run at 8MHz select Tools -> Burn Bootloader.

Now open the Blink example from arduino examples and change the pin number from 13 to 0 and upload.

You can see the above message if everything was successful. Now we have upload the blink program to ATtiny85 and now lets test it out.

/* Project name: Miniaturizing - ATTiny85
   Project URI: https://www.studiopieters.nl/miniaturizing-attiny85
   Description: Testing ATtiny85 Blink
   Version: 1.0.1
   License: MIT
*/

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(0, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(0, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(0, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}
Testing ATtiny85 Blink

Now its time to test. Remove all connections from Arduino and take a power source. Here I will use a button cell to power ATtiny85.

There it is the blink program running on a ATtiny85 with just a battery cell to power it. You can do many projects with low cost, low power and low space. Only your imagination is the limit here and the number of PWM pins of course.

DO YOU HAVE ANY QUESTIONS? LEAVE A COMMENT DOWN HERE.

REFERENCES
David A. Mellis. ATtiny microcontroller support for the Arduino IDE . (2 Juli 2016) https://github.com/damellis/attiny

Scroll to Top