ATtiny Programmer: Immediately save 2k Flash and gain complete
control over low power operation. An Extremely simple walk through on
how you can do this.
Program ATtiny chips for stand-alone operation.
How to program many ATtiny chips using an Uno.
The example here is for the ATtiny85 but many others can be programmed using the same process.
The DIY ATtiny programmer described here shows you how to program a
lot of chips in the ATtiny range. The example shown here uses the
ATtiny85 with the Arduino Uno as the ATtiny
programmer (so it is an ATtiny85 programmer).
In fact the setup is very easy - all you do is connect the
SPI signals from the programmer to the SPI signals on the target chip.
Note: You can use many other Arduino boards as the programmer.
Note that while this setup is fairly easy it has extra steps compared
to using the Digispark ATtiny USB interface. If you are not worried
about the program size - yet! (the main reason for using this process) -
then using the Digispark board is a good idea.
TIP: The DigiSpark board with ATtiny85 is easier to use if you have not run out of memory - there is about 6k Bytes of usable Flash in the DigiSpark.
An Interesting Question
How many external components do you need to operate an Arduino Sketch
in an ATtiny85? If you think about an Uno or Nano (or any other Arduino
board) you could come up with about 10 components but what is the
Q: What are the minimum number of components required to run an Arduino Sketch in an ATtiny85?
(click to find out)
Amazingly the answer is 3 (if you include the power supply) -
You only need the ATtiny85, a decoupling capacitor and a power source e.g.LiPoly battery. All the other
components on Arduino boards are convenience components e.g a USB
interface, external crystal clock, power supply conditioning etc.
You should have at least one power supply decoupling capacitor to
eliminate switching noise. If you program the ATtiny85 using an AVRISP
as described here then you don't need the USB interface chip (required
on all Arduino boards).
Obviously you will need more external components to create the useful
circuit but by using an ATtiny85 you can create the smallest possible
In normal use the Arduino IDE
communicates with an Arduino board, pre-programmed with a bootloader.
This is a small program that communicates over the serial link,
allowing you to easily upload programs using the Arduino IDE. This is
the reason that you don't need an ISP chip programmer for Arduino projects.
There are several reasons using an ISP programmer; you might need to:
Save some space by not using a bootloader.
Re-program the bootloader (or program the bootloader into a new chip).
Use the chip with a slower (internal) clock.
One problem is that the bootloader uses up some of the Flash memory in the
chip; memory which you can't use for your own program. You may just
need that extra 2k of
space and decide not to use a bootloader!
Why use an ISP ATtiny programmer?
Using an ISP programmer allows you to upload
a standard program directly to the target chip without requiring the
target chip to be pre-programmmed i.e. you don't need a bootloader to execute Arduino sketches.
The disadvantage is that you have to connect up the SPI signals (MOSI
MISO etc.) to the target chip. This usually means removing the chip
from the project board and putting it into the programmer board (unless
the SPI pins are routed to a connector, which is more likely for higher
Dedicated ISP or Arduino ISP?
You can buy a dedicated AVR ISP programmer that plugs into a USB port providing the required ISP signals.
Alternatively you can use the Arduino
IDE along with a standard Arduino board; using the Arduino board itself
as your ISP programmer - this turns your Arduino into an AVRISP.
If you are on a budget then the Arduino programmer is the one you want.
ATtiny Programmer library
Install Spence Konde library
You need to add an entry for the boards manager. Select:
Menu > File > Preferences
...and paste the following:
...into the text field labelled 'Additional Boards Manager URLs'.
If you have problems make sure you have Arduino IDE 1.8.9 or later.
Now open the boards manager and select ATtinyCore by Spence Konde:
Menu > Tools > Board > Boards Manager
Chip list for Spence Konde library
Here's a list of the chips that can be programmed using the Spence Konde library:
ATtiny24/44/84(a) (No bootloader)
ATtiny84(a) (Micronucleus / California STEAM)
ATtiny24/45/84 (No bootloader)
ATtiny85 (Micronucleus / DigiSpark)
ATtiny44/88 (No bootloader)
ATtiny88 (Micronucleus, MH-ET t88 w/16MHz CLOCK)
ATtiny87/167 (No bootloader)
ATtiny167 (Micronucleus / DigiSpark Pro)
ATtiny441/841 (No bootloader)
ATtiny841 (Micronucleus / Wattuino)
ATtiny43 (No bootloader)
ATtiny828 (No bootloader)
ATtiny1634 (No bootloader)
ATtiny2313(a)/4313 (No bootloader)
You can see that you do have the option of using a
specific bootloader but check how much memory it takes up; its a trade
off between convenience and the amount of memory used.
Here's a few points of interest on some of these chips:
Here you program the Arduino Uno with a Sketch that allows it to be an ATtiny programmer (an ISP - In System Programmer).
Select the Arduino ISP from the example programs in the IDE:
Menu > File > Examples > 11.ArduinoISP > ArduinoISP
ATtiny programmer: From the Tools Menu set-up three options:
Board: "Arduino/Genuino Uno". This is the programmer board in use.
Port : COMnn. (Arduino/Genuino Uno); The port for your Arduino Uno.
Programmer : "Arduino as ISP".
They should match the screen shot below - except for the port number which will be different for your system.
Program the sketch into the Arduino Uno.
Menu > Sketch > Upload
Note: Pins are on PORTB (it only has PORTB and no PORTA!) so you can use code such as:
... to set all pins on PORTB high.
As with all Arduino boards pins are related to logical port pins and
not physical chip pin numbers so check the diagram for the correct 'pin'
when coding for Arduino.
AVRISP Programmer Connection diagram
This diagram shows you how to wire up the Arduino uno as an ATtiny
programmer. Simply connect MISO, MOSI, SCK, 5V and GND to the chip.
Additionally connect pin 10 to the reset pin on the chip.
Arduino Uno pin
ATtiny85 [chip] pin
13 - SCK
7 - SCK - White
12 - MISO
6 - MISO - Purple
11 - MOSI
5 - MOSI - Blue
10 - RESET
1 - RESET - Yellow
GND - Green
VCC - Red
pin 7 Arduino Uno [optional] [Programming]
1k & LED to GND [any]
pin 8 Arduino Uno [optional] [ERROR]
1k & LED to GND [red]
pin 9 Arduino Uno [optional] [heartbeat]
1k & LED to GND [green]
For testing add 1k resistor to pin 3 (ATtiny85 as shown below), and LED anode to
the resistor. The flat side is the cathode which connects to GND.
Optional Status LEDs
You can also add LEDs (and resistors) to the following Arduino Uno pins to show programmer status:
Heartbeat - programmer is operational.
Error - something went wrong.
Programming - communicating with target.
IDE Set-up for the ATtiny85
Now choose the no-bootloader option for ATtiny85 as follows:
Menu > Tools > Board > ATtinyCore > ATtiny25/45/85 (No bootloader):
Note: Leave the other settings at default values i.e. 8MHz (Internal) clock etc.
So this shows the setup for an ATtiny85 programmer.
Programming Options, Clock source...etc.
There are quite a few options in the Spence Konde library. This
section will got through the most common ones so you know what they do.
Options are found from:
Menu > Tools
Note: This menu will change when on selecting different chips. The
one shown here is for the ATTiny85, starting from the 'Board' option:
ATtiny programmer Options
You can change the 'Chip family' by clicking Boards. This will come
up with a sub menu that allows you to select one of the following:
Arduino AVR Boards
(You may or may not have the last one depending on what you did a while ago!).
You set up the ATtiny85 chip previously here when you selected the Spence Konde library and the ATtinyCore entry.
This allows you to select a specific chip from the related versions available.
Here you can select the clock - whether internal or external. You
must burn the bootloader into the chip to set this option (hence the
wording 'Only Set on Bootloader).
Timer 1 Source
You can select from 3 sources of internal clock signal (CPU, 64MHz, 32MHz).
Link Time Optimization - this can save memory of very low Flash parts. This is enabled by default.
When disabled this saves you Flash memory. Note that the interrupt
code (in Arduino internal operation) for millis()/micros() cannot work
correctly below 1MHz. See this page for more.
EEPROM is retained between programming sessions - you can toggle this setting.
The default for this setting is off (no Brown Out Detect). When it is
off, it saves power. When enabled this will reset the processor if the
voltage dips below a threshold (selected in the menu option).
Programming the ATtiny85
Do this FIRST - Clock Setting and BOD
Perform a 'Burn Bootloader' before programming your Sketch but after programming the Arduino Uno as an AVRISP.
Menu > Tools > 'Burn Bootloader'
TIP: DO THIS FIRST: Menu > Tools > 'Burn Bootloader'
Since you have setup the board as an ATtiny85, burning the bootloader
(can) burn a bootloader into the ATtiny85 (Not the Arduino Uno). For
the setup here, where no bootloader is selected, it is not bunt in -
however the other settings must be updated.
Clicking burn bootloader, in this case, will program the clock setting fuses or BOD
If you want to:
Change the internal clock used,
Change the BOD (Brown Out
Set clocks for the first time,
Set BOD for the first time.
...then you must hit
Menu > Tools > 'Burn Bootloader'
The action of programming the bootloader sets the ATtiny85 fuses that
allow a clock change. This is the reason that the text 'Only Set on bootload' is written into
the Clock source menu item:
Menu > Tools > Clock Source (Only Set on bootload) "8Mhz (internal)"
Warning: Click Burn Bootloader when changing clocks or BOD.
When you re-program the ATtiny85 with your Sketch (without a
bootloader selected), the fuses are left as they were - i.e. correct for the
selected clock rate.
Note: Burning the Bootloader erases the original Sketch!
If you had a program in the Attiny85, after burning the bootloader you need to reload it; burning the bootloader erases memory.
LED Flash program for ATtiny85
The standard blink example uses LED_BUILTIN which is pin 6 on the
ATtiny85 and it is connected to MOSI above. If you removed the chip and
then attached an LED to pin 6 via 1k to ground it would work on another
solder-less breadboard. However to test it in the circuit above you need
to use pin 4 (here set by definition TEST_LED) and not LED_BUILTIN.
The text LED_BUILTIN was changed to TEST_LED to use allow you to use any LED pin:
#define TEST_LED 4
// The setup function runs once on reset or powering the board.
// initialize digital pin TEST_LED as an output.
// the loop function runs over and over again forever
digitalWrite(TEST_LED,HIGH);// turn the LED on.
// PORTB= 0xff;
digitalWrite(TEST_LED,LOW);// turn the LED off.
// PORTB= 0x00;
Note: The pin refers to PB4 not the physical pin (PB4 is on chip pin 3).
Programming the ATtiny85 Sketch
To program the ATtiny85 with the standard Arduino code, using the
ATtiny85 programmer, just hit the programming symbol (right arrow as
usual) or use the menu; it is exactly the same as normal Arduino IDE
Menu > Sketch > Upload
The reason this works is that the IDE bypasses the normal serial
interface and uses the Arduino Uno as an ISP programmer (because of the
setup you did previously).
If your program defines any of the pins as outputs then there could
be conflict since the Arduino Uno also outputs data to the Clock and
MOSI. Fortunately in the Arduino ISP program (after programming has
completed) these Arduino Uno pins are set up as inputs thus avoiding
The relevant section of the Arduino ISP code is:
// We're about to take the target out of reset so set SPI pins as input
Program Space used
This is the output from the Arduino IDE status screen (programming the ATyiny85 using the Arduino Uno as ISP programmer):
Sketch uses 462 bytes (5%) of program storage space. Maximum is 8192 bytes. Global variables use 9 bytes (1%) of dynamic memory, leaving 503 bytes for local variables. Maximum is 512 bytes.
You can see that only 462 bytes are used and there is a maximum of the full Flash memory available for your use.
There is no bootloader, yet the same blink program (essentially) has
been loaded into the ATtiny85 and this process saves you memory.
Sketch uses 700 bytes (11%) of program storage space. Maximum is 6012 bytes. Global variables use 9 bytes of dynamic memory.
Here the maximum space is reduced by 2180 Bytes (more than 1/4 of the total available) - this loss is due entirely to the bootloader code.
These are the same chip but the Digispark system uses a software
bit-banged USB interface (bootloader) that is very clever (and convenient) but does
require a lot of Flash memory.
Conclusions - ATtiny programmmer
With the ATtiny85, you can save over 25% of the total available
Flash memory space compared to the Digispark bootloader. This becomes
crucial for some programs, given that having just 6k is already quite
limiting. However, gaining an additional 2k boost could be the key to
making the project fully functional.
An ATtiny programmer also allows you to change the clock frequency which can be important in low power operation.
P.S. Unbricking an ATtiny
Programming an ATtiny can be tricky and you can brick the chip quite easily. So...