Re-Programming the LilyTiny / LilyTwinkle

Pages
Contributors: bri_huang
Favorited Favorite 4

Introduction

The LilyTiny (and LilyTwinkle) are both great, low-cost, sew-able microcontrollers for eTextile projects. For most projects that only need to interface to a small number of LEDs or sensors, the LilyTiny is a great option.

LilyTiny

LilyTiny

DEV-10899
$5.95
12

The LilyTiny has 6 petals. Two are reserved for power(+) and ground(-). The other four are general purpose I/O pins (GPIOs). The LilyTiny is pre-loaded with a sample sketch which shows a variety of LED patterns on each of the pins:

  • "breathing" pattern (pin 0)
  • heartbeat pattern (pin 1)
  • simple on-off blink (pin 2)
  • random fade (pin 3)

This is a great place to start, but the only way to re-program one of these boards is to use an AVR Programmer and an ISP Pogo Pin Adapter to connect to the 6 exposed pins on the bottom of the LilyTiny board.

This is okay if you haven't already sewn your board into your project. If you have, we can still re-program your board. This tutorial will show you exactly how to accomplish this.

Required Materials

To follow along with this tutorial, you will need the following materials. You may not need everything though depending on what you have. Add it to your cart, read through the guide, and adjust the cart as necessary.

Tiny AVR Programmer

Tiny AVR Programmer

PGM-11801
$17.50
111
LilyTiny

LilyTiny

DEV-10899
$5.95
12
Jumper Wires Premium 12" M/F Pack of 10

Jumper Wires Premium 12" M/F Pack of 10

PRT-09385
$4.95
1
IC Test Clip - SOIC 8-Pin

IC Test Clip - SOIC 8-Pin

COM-13153
$19.50
4

USB Cable Extension - 1.5 Foot

CAB-13309
Retired

There are a couple of ways to re-program your board. We will focus on one of the easiest methods here -- using the Tiny AVR Programming stick.

Tiny AVR Programmer Connected to a ProtoSnap LilyTwinkle's ATtiny85 via a SOIC IC Test Clip

Tiny AVR Programming Stick with Pomona 5250 SOIC Clip used to re-rogram the ATtiny85 on the LilyTwinkle.

ATTiny Board Add-On Files

Before we start, we need to setup the Arduino programming environment to handle the ATTiny hardware. The ATTiny is not part of the "default" board files that comes with Arduino IDE v1.x. You will need to "install" these board files to your Arduino environment in order to re-program your LilyTiny.

Manually Installing the ATtiny hardware files

If you prefer to manually install the files, we will first need to install the ATtiny hardware board files. Download the zipped files from the GitHub repository to manually install the files.

Create a folder under your Arduino sketchbook called "hardware."

  • Locate your Arduino sketchbook folder (you can find its location in the preferences dialog in the Arduino software) - this is typically under Documents > Arduino

  • Create a new sub-folder called “hardware” in the sketchbook folder, if it doesn’t exist already.

  • Open (unzip) the attiny-master.zip file and copy the “attiny” folder (not the attiny-master folder) from the unzipped attiny-master.zip file to your new “hardware” folder.

You should end up with folder structure like Documents > Arduino > hardware > attiny that contains the boards.txt file and another folder called variants.h.

  • Restart the Arduino IDE.

  • You should see ATtiny entries in the Tools > Board menu.

Tiny AVR Programmer

Drivers

Follow the hook-up guide for the Tiny AVR programmer. For Windows / PC users, there are a few driver files that you'll need. For Mac / OS X users, the Tiny AVR Programmer should be plug-and-play ready.

Tiny AVR Programmer Hookup Guide

October 28, 2013

A how-to on the Tiny AVR Programmer. How to install drivers, hook it up, and program your favorite Tiny AVRs using AVRDUDE!

Hardware Hookup

While the photos show us using the 4-wire ribbon cables and the straight pin break-away headers to connect the SOIC clip to the Tiny AVR Programmer, we have found that the straight pin break-away headers (or any square pins) do not sit into the Tiny AVR Programmer very well. Instead, we recommend using the 12" Male-to-Female jumper wires to connect the SOIC clip to the Tiny AVR Programmer.

Wires

Make sure that the left side pins on the programmer are wired to the left side of the clip and the right side pins are wired to the right side of the clip. When you clip this onto the LilyTiny, make sure that the chip is right-side up. There are a few distinguishing marks to identify which way is up. On the programmer, there is a notch where an 8-pin chip would go. This should be up. And, on the LilyTiny, the Lilypad script "L" should be on the bottom.

Close up of tiny AVR programmer ATtiny85 socket and the LilyPad with an ATtiny85 surface mountfacing the same orientation

When you are finished connecting the Tiny AVR Programmer to the ATtiny85, it should look similar to the image below.

Tiny AVR Programmer Connected to ATtiny85

You are now ready to re-program the LilyTiny or LilyTwinkle! The last step is to insert the Tiny AVR Programmer to your computer's USB port to begin programming.

Test Code - "Hello World!"

Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE.

As with nearly every introductory Arduino project, we test our system with a "blink" program -- the equivalent to "Hello World!" in most other programming environments. First, we need to make sure the configuration is set properly in the Arduino IDE.

Step 0 - Open up the Arduino IDE

Open the Arduino IDE if you have not already.

Step 1 - Setting the Board Type

The LilyTiny has an ATtiny85 microcontroller on it. Change the board type in the Arduino IDE to correspond with this. The ATtiny85 can be set with either a 1 MHz internal clock or an 8 MHz internal clock. Be sure to select 8 MHz. Select: Tools --> Board --> ATtiny85 (internal 8 MHz clock)

Board Selection

Step 2 - Setting the Programmer

Because we are using the Tiny AVR as our programmer, we need the change the default programmer. This settings is also under the Tools > Programmer > USBtinyISP.

Select Programmer

Step 3 - Upload Code

Copy the code below and paste this into your Arduino window.

language:c
int blinkPin = 0;
void setup()
{
   pinMode(blinkPin, OUTPUT);
}

void loop()
{
    digitalWrite(blinkPin, HIGH);
    delay(500);
    digitalWrite(blinkPin, LOW);
    delay(500);
}

Click the upload button. You may see a few warning messages such as:

language:bash
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85

You can ignore this one. If everything is working, you should be able to see a blinking LED on GPIO 0 (pin 5 of the ATtiny). This can be on the Tiny AVR Programmer, the ProtoSnap LilyTwinkle Kit, or an LED that is attached to the ATtiny 85.

Notes on Programming the ATtiny85

The ATtiny85 isn’t your everyday Arduino microcontroller. It packs a lot of punch for its small size.

ATmega85 Pin Reference

The following Arduino commands should be supported:

All 5 pins are general purpose digital I/Os (GPIO). This means that they can be used with both digitalWrite() and digitalRead().

Pins 0 and 1 support PWM output (analogWrite).

Pins 2, 3, & 4 are tied to A/D on the chip (analogRead).

While the ATtiny85 supports most of the things you need, there are some things it can’t do.

No Hardware Serial (UART)

The ATtiny85 does not have a built in hardware UART. If you try to compile any Arduino code with Serial.begin() or Serial.print() you’ll get an error. However, there is a work around for this -- using Software Serial. This tutorial shows an example of how to do this:

Resources and Going Further

The TinyAVR Programmer is a real slick way to re-program the ATTiny45 or ATTiny85 chips. However, it does require that you install a few additional drivers. You can use this programmer directly with the Pomona 5250 SOIC clip. This programmer already has a debug LED on pin 0. We have a full hook-up guide for the Tiny AVR Programmer here.

Tiny AVR Programmer Hookup Guide

October 28, 2013

A how-to on the Tiny AVR Programmer. How to install drivers, hook it up, and program your favorite Tiny AVRs using AVRDUDE!

For more information regarding the ATtiny85, LinyTiny/Twinkle or more AVR programming tutorials, check out the following links:

Need some inspiration for your next project? Check out some of these related tutorials:

  • H2OhNo! -- The H2OhNo! water alarm and development board uses an ATtiny85 to sense the presence of water. This tutorial goes deep into getting the ATtiny85 into a very low power mode.
  • Shift Registers -- If you're feeling restrained by the ATtiny's lack of pins, you may be able to use a shift register to expand on that I/O count.
  • Using the Arduino Pro Mini 3.3V -- If you're looking for small, but need more pins and functionality check out the Arduino Pro Mini.
  • Installing an Arduino Bootloader -- You can use the Tiny AVR Programmer to program all sorts of AVRs, including those on most Arduino-compatible boards. If you ever find yourself needing to reprogram your Arduino bootloader, the Tiny AVR Programmer should be all you need.

Or check out these tutorials using the Attiny.

Pocket AVR Programmer Hookup Guide

Skip the bootloader and load your program directly onto an AVR with the AVR Pocket Programmer.

Wake-on-Shake Hookup Guide

A basic hookup guide for getting started with the SparkFun Wake-on-Shake. The board gives you the ability to put your project into hibernation until bumped or shaken awake using the ADXL362 accelerometer. This means you can design projects meant to stay inert for long periods of time, possibly even several years, depending on the battery type used to power the project.

Twinkle Zodiac Constellation

Create a quick and easy piece of e-textile art based on a Zodiac sign using a LilyTiny, LilyPad LEDs, battery holder, conductive thread, and coin cell battery.

SparkFun Qwiic Quad Solid State Relay Kit Hookup Guide

A Hookup Guide to get you started with the SparkFun Qwiic Quad Solid State Relay Kit (say that five times fast!).