Arduino Bootloader Download

After some research I found that my first option was the straight one. Just plug it as a normal Arduino, the last two needed something else. The last two options were missing something called a bootloader. A bootloader is “a small program that has been loaded on to the microcontroller.

PagesFavoritedFavorite10

Introduction

In this tutorial, we'll show you how to use Arduino to install the micronucleus bootloader, which has V-USB, onto an ATtiny84. These steps will work for other ATtiny chips, but you'll need to change things like the pins_arduino.h file and target parameters in avrdude.

By following this guide, you will be able to upload Arduino sketches directly to the ATtiny84 over USB without needing to use a programming device (such as another Arduino or FTDI chip).

The Atmel AVR ATtiny84 is very similar to the ATtiny85 but with a few more I/O pins (six more, to be exact). If you like working with very small, inexpensive microcontrollers, the ATtiny84 and lower-power ATtiny84A are good options. Either the ATtiny84 or ATtiny84A will work for this tutorial.

AVR 14 Pin 20MHz 8K 12A/D - ATtiny84

COM-11232
1
FavoritedFavorite16
Warning: To make this work, we'll need to run the ATtiny84 at 12MHz during the bootloader phase. This tutorial shows how to do that with the internal RC clock at 3.3V. Note that this is out of spec for the ATtiny84! We're essentially overclocking/hacking the ATtiny to do something it's not supposed to do. Do this at your own risk! SparkFun takes no responsibility if you brick/smoke/blow up your ATtiny. Good thing they're cheap.

In this tutorial, we'll show you how to:

  1. Load Arduino ISP (In-System Programmer) on an Arduino
  2. Install the micronucleus bootloader on the ATtiny84
  3. Manually change fuses in the ATtiny84 to allow USB programming
  4. Create a new board definition in Arduino for the ATtiny84
  5. Install any necessary USB drivers
  6. Upload example firmware from Arduino IDE to the ATtiny84

The ATtiny microcontrollers are fantastic little chips but often suffer from low programming space. The ATtiny84 and 85 have 8k of flash memory (compared to 32k in the ATmega328p, the most commonly found microcontroller on Arduino platforms). A bootloader like micronucleus allows us to upload firmware to the microcontroller over a 'virtual' USB (V-USB) connection rather than using a separate microcontroller for programming. The downside is that micronucleus uses 2k of the available flash, leaving us with only 6k of flash for our program!

However, using a bootloader potentially reduces the production cost of a custom Arduino board if you don't want to rely on separate hardware for programming.

Note: If you don't want to use the bootloader, you can still program the ATtiny84 directly from Arduino using another Arduino device as an ISP.

Parts List

To follow along, you will need these parts:

You will also need the following:

Arduino Uno Bootloader Download

  • 2x 68Ω Resistors
  • 1x 1.5 kΩ Resistor

Suggested Reading

Before moving along, we recommend you have familiarity with the following concepts.

Load Arduino ISP

To get started, we'll need to use another Arduino as an In-System Programmer (ISP) to send firmware to the target device (our ATtiny84). We'll only need to do this once in order to upload the micronucleus bootloader.

Hardware Connections

To start, make the following connections:

Upload ArduinoISP Sketch

Download the latest Arduino IDE.

Note: This tutorial was tested with Arduino v1.6.13.

Connect an FTDI breakout to the Arduino Pro Mini. In Arduino, select File > Examples > ArduinoISP > ArduinoISP. Select your Arduino board in Tools:

  • Board: Arduino Pro or Pro Mini
  • Processor: ATmega328 (3.3V, 8MHz)
  • Port:

Click upload to burn the Arduino ISP firmware to the Arduino Pro Mini.

Install Micronucleus

Micronucleus is a bootloader created for ATtiny microcontrollers. It has V-USB built in so that we can send compiled firmware over a virtual USB connection.

When we say 'virtual USB,' we're actually mimicking low-speed USB with GPIO pins on the ATtiny, since there is no actual USB hardware on the ATtiny84. Essentially, the V-USB library bit-bangs the differential pair signaling of USB communications to make the USB host on our computer think we're transferring information using the USB protocol.

Warning: Once again, this is extremely hackerish. SparkFun can't promise this will work with all computers.

Hardware Setup

Add a 10μF capacitor between the RESET and GND pins of the Arduino. Watch the polarity! The capacitor will prevent the Arduino from entering bootloader mode so that it will pass the compiled firmware to the connected ATtiny rather than trying to program itself.

Upload Micronucleus to the ATtiny84

Head to the micronucleus GitHub repository to clone the bootloader or download the zip here.

Unzip the folder.

The Arduino IDE comes with a tool called AVRDUDE, which is a piece of software that can be used to download and upload firmware, read and write fuses, and manipulate ROM and EEPROM on AVR microcontrollers. Whenever you upload code to an AVR-based Arduino, the Arduino IDE is quietly calling AVRDUDE in the background to make that happen.

We're going to call AVRDUDE manually to send a piece of pre-compiled firmware to the ATtiny.

Open a command terminal and navigate to /hardware/tools/avr/bin:

Enter the following command, changing to wherever you downloaded and unzipped the micronucleus repository and to the serial port connected to your Arduino ISP (e.g., COM65 on Windows).

Your output should look similar to the following.

Change Fuses

Most microcontrollers come with a number of configuration bits that reside in nonvolatile memory outside of the normal program space. In AVR chips, like our ATtiny84, these bits are known as 'fuses.' By default, the fuses on a new ATtiny84 are set to:

  • Divide the clock by 8
  • Disabled brown-out detection
  • No self-programming

We want to change the fuses so that we have:

  • No clock divider
  • Brown-out detection at 2.7V (not necessary, but useful if running off battery)
  • Self-programming

To see which fuses need to be changed, select ATtiny84 from the dropdown list on the AVR Fuse Calculator site.

Burning Fuses with AVRDUDE

If you change the features on the fuse calculator, you'll see that we need to set the following:

  • Low Fuse Byte: 0xE2
  • High Fuse Byte: 0xDD
  • Extended Fuse Byte: 0xFE

To do that, we'll use AVRDUDE. Once again, navigate to the directory with AVRDUDE in Arduino and execute the following command:

Verify that the fuses have been written with the following:

While you are telling AVRDUDE to specifically read the lfuse, it will print out the state of all the fuses. You should see the following at the bottom of the printout:

Create an Arduino Board Definition

To be able to program the ATtiny84 from Arduino, we need to make a custom board definition. There are three main parts for a board definition, and we'll create each one:

  • boards.txt -- Information about the microcontroller (clock speed, program space, etc.)
  • platform.txt -- Extra information the compiler might need and which loader tool to use (e.g., AVRDUDE)
  • pins_ardiuno.h -- Tells the compiler which pins in code map to which pins on the microcontroller

Additionally, we'll need to copy over the micronucleus loader tool from the micronucleus project directory to the Arduino directory. The loader tool will be used to send compiled firmware to the ATtiny84 (much as AVRDUDE does).

boards.txt

Navigate to /hardware and create a directory that corresponds to the class of platforms or company name that our ATtiny84 will belong to. I'll call mine mytiny.

In that directory, create another directory that corresponds to the target microcontroller family, 'avr' in this case.

In the avr directory, create a file named boards.txt and copy in the following text:

platform.txt

In the avr directory, create a file named platform.txt and copy in the following:

Pin Definitions

At this point, we need to create a custom pin definitions file. Create a directory in avr with the name variants:

Arduino Uno Bootloader Download Hex

Create another directory in variants named tiny14. In tiny14, create a file named pins_arduino.h.

Copy the following code into pins_arduino.h. Note that the original contents of this file come from the ATtiny cores for Arduino project.

If you look through the platform.txt file, you'll see that the loader tool is micronucleus and not avrdude. Because Arduino does not come with the micronucleus loader tool, we need to build it or copy it from the micronucleus project directory.

Build the Micronucleus Loader (Mac)

First, you'll need to make sure you have Homebrew installed. Then, open a command terminal and enter:

Navigate to /commandline. Copy the micronucleus executable in the commandline directory to /hardware/tools.

Copy the Micronucleus Executable (Windows)

Navigate to

Install USB Drivers

Because micronucleus requires custom drivers based on libusb, many operating systems will need to have the custom drivers installed or perform some custom configuration. Find your operating system below and follow the instructions.

Windows

Unfortunately, Windows doesn't know what to do with the micronucleus bootloader on the ATtiny84. It comes up as an Unknown USB Device, so we'll fix that with a custom driver. Lucky for us, the micronucleus project already comes with one.

Plug in a USB micro cable from your computer to the USB micro breakout on the breadboard. Windows will likely tell you that no driver could be found.

Navigate to

Linux

You have two choices. You can either run Arduino with root privileges in order to send data to an 'unknown' USB device, or you can install a set of udev rules to allow regular users to upload programs. To install the udev rules, run the following commands:

Example: Blinky

We should have everything set up to flash a program onto the ATtiny84 from the Arduino IDE! But first, let's simplify the hardware.

Hardware Setup

We can modify our hardware to disconnect the programming lines from the Arduino Pro Mini, which will free up some GPIO on the ATtiny. We'll still want to use the Pro Mini's voltage regulator to drop the USB voltage from 5V to 3.3V.

Warning: Make sure you unplug the USB cable from the Arduino! We don't want to short anything. From now on, we'll be using the USB micro breakout on the breadboard to program the ATtiny84.

The Code

Close and reopen the Arduino IDE to load the new board definition files.

Note: On Linux and OS X, you'll need to run the Arduino IDE with administrator/root privileges in order to upload sketches over USB.

In a new sketch, copy in the following:

Upload and Run

In Tools > Board, you should see only one option under MyTiny Boards. Select it.

This part is important! Follow these steps to upload the sketch to the ATtiny84. Because our V-USB connection does not automatically reset the ATtiny, we'll need to reset it manually as the bootloader runs for the first five seconds after power-up before relinquishing control to the user program.
  1. Unplug USB cable
  2. Press Upload in the Arduino IDE
  3. Wait for the phrase 'Uploading...' to appear just above the Arduino console
  4. Plug in the USB cable
  5. Wait five seconds for the ATtiny84 to reboot and time out of the bootloader to start running our Blinky sketch

And that's it! You should see the LED begin to blink on and off.

Resources and Going Further

While this is a lot of information to take in, it shows how to hack the Arduino IDE to load custom board definitions. These steps should work for other ATtiny devices that are supported by the micronucleus project, such as:

You might have to modify the pins_arduino.h file, however, if you plan to use a different ATtiny.

ATtiny84 Pinout

If you need additional support, please check out the following resources.

If you want to go further with the ATtiny, please check out our additional tutorials that showcase the ATtiny:

Electronic E-craft Terrarium

A guest tutorial on an Electronic Terrarium from the Performative Sculpture class of Parsons DT.

Roshamglo Hookup Guide

Download
This tutorial provides everything you need to know to get started with the Roshamglo badge.

Qwiic Quad Relay Hookup Guide

SparkFun’s Qwiic Quad Relay is a product designed for switching not one but four high powered devices from your Arduino or other low powered microcontroller using I2C.

Atmega328 With Arduino Bootloader

Qwiic Twist Hookup Guide

Arduino Bootloader Source Code Download

Take your volume knob beyond 11 with the Qwiic Twist digital RGB LED encoder via I2C!