Tiny chip, Mega fun
An ATTiny85 & ATmega328P microcontroller chip workshop for ITP's 2019 Unconference.
This is where I learned everything!
- Arduino board as ATtiny programmer
- From Arduino to a Microcontroller on a Breadboard
- Programming ATtiny85 with Arduino Uno
- Programming ATtiny85 with Arduino Uno - Blink
- Instructable: Use a $1 ATTiny to Drive Addressable RGB LEDs
Purpose: Why Use an IC instead of a Arduino Uno?
Our Arduino Unos use an ATmel AVR chips as their onboard microcontroller (AVR stands for "automatic voltage regulation"). If you look closely at your board, you'll see that it has a ATmega328P. AVR chips are a type of IC, or integrated circuit.
For most purposes, don't need all the features onboard the Arduino Uno (for example, it has an external oscillator that can bump up its clock date to 16 MHZ).
For our workshop, we're going to focus on the ATTiny85. It's a bit smaller than the ATmega328P, but can do most
- It's way cheaper
- It's way smaller!
- It can do most things!
- Harder for beginners
- It's a bit slower. The onboard oscillator can go as fast as 8mHZ, which is not noticeable for most use cases but its clock rate is slower than your Arduino Uno.
- No UART serial communications (but yes, I2C and SPI)
- Arduino Uno (or other microcontroller board you are comfortable with)
- ATTiny85 chip
- 10 μF capacitor (the shop is out of 10 uF, so I'm using 47 μF)
- Male-to-male jumpers
- 5V power supply (can be from your Arduino, battery, independent power supply, etc.)
- Neopixel strand
- 47 μF capacitor
- Maybe a resistor of low resistance
We have a few options for programming our ATTiny85 chips. We can use a Tiny AVR Programmer (which costs $15.95!!!) or, we can temporarily reprogram our Arduinos to act as an ISP, or "in-system programmer."
About the ATTiny85
To understand how we will go about communicating with our ATTiny85 chip, let's take a look at its pins:
It's got 3 analog pins, 2 PWM pins, all of the I/O pins can be used as digital pins.
Program our Arduino to act as an AVR programmer
- Open the Arduino IDE. Load the ArduinoISP sketch from File -> Examples -> ArduinoISP. Upload this sketch onto your Arduino board. You only need to do this once, at this step.
Update settings in our Arduino IDE so it can talk to our ATTiny85
- We also need to add the ATtiny85 board to our Board Manager. Go to File -> Preferences and under Additional Boards Manager add this url:
- Select ATtiny25/45/85 from Tools -> Board... You may have to have to search and install the ATtiny25/45/85 from the Boards Manager (also found under Tools -> Board...).
- Change Processor to ATTiny85 (Tools -> Processor -> ATTiny85).
- Select 8 MHz (internal) under Tools -> Clock. By default, the clock rate of ATTiny85 runs at 1 Mhz, but this will be too slow for most things we want to do.
- Select "Arduino as ISP" from Tools > Programmer.
Your settings under Tools should look something like this:
Connect and initialize our ATTiny85 chip
- Next, wire your Arduino to your ATTiny85 so we can actually start talking to it! Wire it as seen below:
- 10 μF capacitor between RESET & GND on your Arduino
- IC Pin 8 to 5V
- IC Pin 7 to Arduino Pin 13
- IC Pin 6 to Arduino Pin 12
- IC Pin 5 to Arduino Pin 11
- IC Pin 1 to Arduino Pin 10
- IC Pin 4 to GND
- By default, the internal clock date of the ATtiny85 is 1 MHz, which is too slow. In order to reset its clock rate to 8 MHz (as per our settings above), we need to burn the bootloader! Go to Tools > Burn Bootloader.
Note: You only need to burn bootloader once (when you first initialize your ATtiny/reset its clock). Afterwards, you can just go directly to step 9, assuming that you're connected to your ATtiny85 as described in step 7.
- Once the bootloader has been successfully burned, you can upload whatever program you want onto your IC. (Blink is probably a good place to start.)
Load whatever program you want onto your ATTiny85
Now, your Blink (or whatever program) can run independently of your Arduino, though you will still need to give it a power supply. Your Arduino is free to be used for something else. If you use Blink from examples, change the Pin # to 0 (which is in position 5 on the ATtiny85 IC). This tutorial shows you how to wire your ATTiny85 so that can see Blink in action.
Beyond the scope of this workshop, but the next step is:
- Solder your desired circuit (+ IC chip) onto perf board. Be free of your breadboard!
We can see more complex programs too! Let's try to program some Neopixels. This Instructable shows the basic wiring of an ATTiny85 to a Neopixel strand.
- Error burning the bootloader: double check your wiring and then click Burn Bootloader again!
- Double check your wiring using a multimeter.
- Make sure that you have the
ArduinoISPsketch loaded onto your Arduino, NOT your ATTiny85 chip. You only want to upload the target script (like, Blink or Strandtest) to your ATTiny85. You can double check the settings under Tools to confirm you're talking to the right board.
- Make sure that your serial port is talking to the Arduino IDE (disconnect and reconnect your Arduino as necessary, and re-select the correct port).
- If you're using different development board (Arduino Zero, Curie 101, etc.) you may have to adjust the pins either in the
ArduinoISPsketch or adjust which pins you connect the ATTiny85 when programming it from your board.
A bunch of other resources and questions I encountered while learning about this: