adafruit learning system Trinket Reference manual

Introducing Trinket
Created by lady ada
Last updated on 2014-07-03 03:30:16 PM EDT

2
4
6
8
10
11
12
13
13
13
14
14
15
15
15
15
16
17
19
20
23
24
24
26
26
27
Guide Contents
Guide Contents
Introduction
Guided Tour
Pinouts
Power Pins
GPIO Pins
Reset and Regulator Output
Starting the Bootloader
About the bootloader
Trinket USB Drivers for Windows
Special Notes on using Trinket with Linux
How to start the bootloader
Setting up with Arduino IDE
The Fast Way
The Slow Way
Step 0. Install Arduino IDE
Step 1. Add ATtiny85 Support
Step 2. Updating avrdude.conf
Step 3. Update 'ld' linker
Blink!
Something Went Wrong!
If you get the error message avrdude: Error: Could not find USBtiny device
(0x1781/0xc9f)
If you get a lot of red text, errors and also a warning about Verification Failed
Programming with Arduino IDE
pinMode() & digitalWrite() & digitalRead()
analogRead()
© Adafruit
Industries https://learn.adafruit.com/introducing-trinket Page 2 of 48

27
28
29
29
30
36
37
40
40
40
40
40
42
44
44
44
44
47
analogWrite()
More...
Programming with AVRdude
The Short Way
The Long Way
Uploading with AVRdude
Programming in a Blink example
16MHz vs 8MHz Clock
Power Tradeoffs
How to activate the 16 MHz clock
...on AVR-GCC
...Arduino IDE
Repairing bootloader
Downloads
Datasheets
Source code
Schematics
FAQ
© Adafruit
Industries https://learn.adafruit.com/introducing-trinket Page 3 of 48

Introduction
Trinket may be small, but do not be fooled by its size! It's a tiny microcontroller board, built
around the Atmel ATtiny85, a little chip with a lot of power. We wanted to design a
microcontroller board that was small enough to fit into any project, and low cost enough to
use without hesitation. Perfect for when you don't want to give up your expensive dev-board
and you aren't willing to take apart the project you worked so hard to design. It's our lowest-
cost arduino-IDE programmable board!
The Attiny85 is a fun processor because despite being so small, it has 8K of flash, and 5 I/O
pins, including analog inputs and PWM 'analog' outputs. We designed a USB bootloader so
you can plug it into any computer and reprogram it over a USB port just like an Arduino. In
fact we even made some simple modifications to the Arduino IDE so that it works like a mini-
Arduino board. You can't stack a big shield on it but for many small & simple projects the
Trinket will be your go-to platform.
Even though you can program Trinket using the Arduino IDE, it's not a fully 100% Arduino-
compatible. There are some things you trade off for such a small and low cost
microcontroller!
© Adafruit
Industries https://learn.adafruit.com/introducing-trinket Page 4 of 48

Trinket does not have a Serial port connection for debugging so the serial port monitor
will not be able to send/receive data
Some computers' USB v3 ports don't recognize the Trinket's bootloader. Simply use a
USB v2 port or a USB hub in between
There are two versions of the Trinket. One is 3V and one is 5V. Both work the same, but
have different operating logic voltages. Use the 3V one to interface with sensors and
devices that need 3V logic, or when you want to power it off of a LiPo battery. The 3V
version should only run at 8 MHz. Use the 5V one for sensors and components that can use
or require 5V logic. The 5V version can run at 8 MHz or at 16MHz by setting the software-set
clock frequency.
Here are some useful specifications!
ATtiny85 on-board, 8K of flash, 512 byte of SRAM, 512 bytes of EEPROM
Internal oscillator runs at 8MHz, but can be doubled in software for 16MHz
USB bootloader with a nice LED indicator looks just like a USBtinyISP
so you can program it with AVRdude (with a simple config modification) and/or
the Arduino IDE (with a few simple config modifications)
Mini-USB jack for power and/or USB uploading, you can put it in a box or tape it up and
use any USB cable for when you want to reprogram.
We really worked hard on the bootloader process to make it rugged and foolproof,
this board wont up and die on you in the middle of a project!
~5.25K bytes available for use (2.75K taken for the bootloader)
Available in both 3V and 5V flavors
On-board 3.3V or 5.0V power regulator with 150mA output capability and ultra-low
dropout. Up to 16V input, reverse-polarity protection, thermal and current-limit
protection.
Power with either USB or external output (such as a battery) - it'll automatically switch
over
On-board green power LED and red pin #1 LED
Reset button for entering the bootloader or restarting the program. No
need to unplug/replug the board every time you want to reset or
update!
5 GPIO - 2 shared with the USB interface. The 3 independent IO pins have 1 analog
input and 2 PWM output as well. The 2 shared IO pins have 2 more analog inputs and
one more PWM output.
Hardware I2C / SPI capability for breakout & sensor interfacing.
Mounting holes! Yeah!
© Adafruit
Industries https://learn.adafruit.com/introducing-trinket Page 5 of 48

Guided Tour
Let me take you on a tour of your Trinket! Each trinket is assembled here at Adafruit and
comes chock-full of good design to make it a joy to use.
Mini-B USB co nnector - We went with the tried and true mini-B USB connector for
power and/or USB bootloading. In our experience, Micro-B connectors can rip off the
PCB easily, but we have not had that problem with mini B, its much more rugged for DIY
electronics. It's also a proper USB connector, so you can use any length cable. Some
Attiny85 boards use a PCB that slides into a USB port to cut costs, but that makes it
hard to re-program and annoying to power with an external battery pack
Green Po wer LED - you'll know that the board is powered up when this bright LED is
lit
Red #1 LED - this LED does double duty. Its connected with a series resistor to the
digital #1 GPIO pin. It pulses nicely when the Trinket is in bootloader mode, and its also
handy for when you want an indicator LED.
Battery + Input - take your Trinket anywhere and power it from an external battery.
This pin can take up 16V DC input, and has reverse-polarity, over-curent and thermal
protections. The circuitry inside will use either the battery or USB power, safely
switching from one to the other. If both are connected, it will use whichever has the
higher voltage
USB Power Output - You can also snag the 5V power from the USB jack in case you
need 500mA+ current from your computer or portable USB power pack.
© Adafruit
Industries https://learn.adafruit.com/introducing-trinket Page 6 of 48

Breadboard friendly pins - You can easily plug this into a little breadboard and
have plenty of space for working and plugging stuff in
GPIO! - 5 GPIO pins, at 3 or 5V logic, check the next section for a detailed pinout
guide
3 or 5V output - an onboard regulator provides 3.3V or 5V output for powering
LEDs, sensors, small motors, etc.
Reset Button - an onboard reset button will launch the bootloader when pressed
and the Trinket is plugged into a computer. If it is not connected to a computer, it's
smart enough to go straight to the program.
External Reset Pin - we bring out the reset pin so you can reset or restart your
Trinket on the road. If the Trinket is in a box or otherwise hard to get to, you can wire
up a button to this pin for an external reset button.
Four mounting holes make it easy to attach with 2mm screws or even tiny zip-
ties, string, etc.
© Adafruit
Industries https://learn.adafruit.com/introducing-trinket Page 7 of 48

Pinouts
The following shows measurements in mm, both version of the Trinket have the exact same
dimensions for hole placement & outline
© Adafruit
Industries https://learn.adafruit.com/introducing-trinket Page 8 of 48

There are two versions of the Trinket: 3V and 5V. They are almost identical but there
are slight differences in the pinouts: one has a 3V output pin in the bottom right, the
other has a 5V output pin instead
© Adafruit
Industries https://learn.adafruit.com/introducing-trinket Page 9 of 48

Thanks to Adafruit Forums member ardunaut for developing this handy diagram!
Here's the ATtiny85 pinout
Power Pins
We'll start with the top pins BAT+ and USB+ and GND
BAT+ is the Battery + Input pin. If you want to power the trinket from a battery or
power adapter or solar panel or any other kind of power source, connect the +
(positive) pin here! You can connect up to 16V DC. If you have a 3V Trinket, you'll want
at least 3.5V input to get a good 3.3V output. If you have a 5V trinket, 5.5V or higher is
© Adafruit
Industries https://learn.adafruit.com/introducing-trinket Page 10 of 48

suggested. This input is reverse-polarity protected.
USB+ is the USB + Output pin. If you want to use the USB 5V power for something,
like charging a battery, or if you need more than 150mA of current (this pin can supply
500mA+ from USB ports) or to detect when the Trinket is plugged into USB, this pin
will have 5V power on it if and only if its plugged into something via the mini B
connector
GND is the common ground pin, used for logic and power. It is connected to the USB
ground and the power regulator, etc. This is the pin you'll want to use for any and all
ground connections
GPIO Pins
Next we will cover the 5 GPIO (General Purpose Input Ouput) pins! For reference you may
want to also check out the datasheet-reference above for the core ATtiny85 pin
All the GPIO pins can be used as digital inputs, digital outputs, for LEDs, buttons and switches
etc. They can provide up to 20mA of current. Don't connect a motor or other high-power
component directly to the pins! Instead, use a transistor to power the DC motor
on/off (http://adafru.it/aUD)
On a 3V Trinket, the GPIO are 3.3V output level, and should not be used with 5V inputs. On a
5V Trinket, the GPIO are 5V output level, and can be used with 3V inputs but may damage
electronic devices that are 3V input only!
The first 3 pins are completely 'free' pins, they are not used by the USB connection so you
never have to worry about the USB interface interfering with them when programming
GPIO #0 - this is connected to PB0 on the ATtiny85. This pin can be used as a PWM
output, and is also used for I2C data, and SPI data input.
GPIO #1 - this is connected to PB1 on the ATtiny85. This pin can be used as a PWM
output, and is also used for SPI data output. This pin is also connected to the onboard
LED (like pin 13 on a regular Arduino).
GPIO #2 - this is connected to PB2 on the ATtiny85. This pin can be used as an
analog input (known as Analog A1), and is also used for I2C clock and SPI clock.
The next 2 pins are also used for USB programming. That means that when the Trinket is
connected to a computer and in bootloader mode or in the middle of uploading a new
program, they are used for sending data to/from the computer! It's possible to share these
pins if you are careful. The best use of these pins is as outputs to things like LEDs , or
inputs to things like buttons and just make sure not to press the buttons while connected
to USB. We didn't want to keep these pins off the board but we strongly recommend not
using them unless you're sure you need them since you might have to disconnect any
connections to reprogram the Trinket!
GPIO #3 - this is connected to PB3 on the Attiny85. This pin is used for USB
programming, but its also an analog input known as Analog A3
GPIO #4 - this is connected to PB4 on the Attiny85. this pin is used for USB
© Adafruit
Industries https://learn.adafruit.com/introducing-trinket Page 11 of 48

programming, but it can also be used as a PWM analog output and an analog input
known as Analog A2
Reset and Regulator Output
The final two pins are at the bottom of the board.
First is the Rst reset pin. This is connected directly to the ATtiny85's reset pin and also the
reset button which is right next to it. The reset pin is used to enter the bootloader and to
reset the board in case you want to restart it. It's also possible to use this pin to re-program
in the bootloader or completely remove the bootloader if you have an AVR programmer
such as an AVR Dragon, MKii or USBtinyISP. If you want to re-program the board when its in
an enclosure or box or otherwise hard to reach, wire a simple button from the RST pin to
ground and press it to enter the bootloader for 10 seconds. The #1 LED will pulse to let you
know. The reset button cannot be used as a GPIO, but we think its a lot more useful as a
proper reset button!
Lastly we have the regulator output pin. There is an onboard mini power regulator that will
take up to 16V DC from the BAT+ or USB connection and regulate it down to a steady 3.3V
or 5.0V DC so its safe to use with your sensors and LEDs. On a 3V Trinket, this output will be
about 3.3V. On a 5V Trinket, this output will be 5V so be aware in case you want to swap one
with the other. You can draw up to 150mA output from this pin. If you need more current, you
may want to get it directly from the USB+ pin, which supplies 5V @ 500mA from a computer
or wall adapter
Note the numbering of analog pins: Pin 2 is Analog 1, Pin 3 is Analog 3, Pin 4 is Analog 2.
For the Uno, the terms A1, A2, and A3 are mapped for you. For ATtiny85's, they are not.
So for the pinMode calls, use the Pin number (stenciled on Trinket), for analogRead, use
the analog number.
© Adafruit
Industries https://learn.adafruit.com/introducing-trinket Page 12 of 48

Starting the Bootloader
About the bootloader
A bootloader is a tiny piece of software residing on the microcontroller that that helps load
your own code into the remaining space.
One of the challenges with the Trinket is that we wanted to have a built-in USB bootloader,
but the ATtiny85 doesn't have built-in USB hardware! There are existing USB bootloaders
that can work on the 't85 but they use other companies' USB VID/PIDs. Since it not permitted
by the USB developer's group (http://adafru.it/cDW) to use others' VID/PIDs we had to adapt
one of these existing bootloaders to use our USB ID, but we also wanted to not have to re-
compile avrdude or the Arduino IDE since that's such a pain.
So instead, Frank (our awesome engineer with mad USB chops) (http://adafru.it/cDX)
created a USB bootloader that combines the elegance of V-USB with the well-supported and
tested nature of the USBtinyISP. This bootloader looks just like a USBtinyISP - and since it
uses the unique Adafruit VID/PID we own and that we added to avrdude so long ago, it works
with only very minimal configuraton tweaks. No need to recompile anything, whew!
Trinket USB Drivers for Windows
The cool thing about the bootloader on the Trinket is it just looks like a classic USBtinyISP
AVR programmer. This makes it easy to use with AVRdude or Arduino IDE with only minor
configuration changes. Before you start, you may need to install the USBtinyISP USB drivers
Drivers are only required for Windows, if you are using a Mac or Linux,
drivers are no t required!
For details on installing the drivers for Windows XP, 7, 8 etc... please read this
page! (http://adafru.it/cDY)
If you're good at installing drivers, you can just download the Windows 8
drivers (http://adafru.it/djr) or Windows XP/7/Vista drivers (http://adafru.it/doK) by clicking on
those links
Don't forget to plug in the Trinket via a known-good USB cable to start the process. You
should see the green power LED lit and the red bootloading LED pulse indicating that the
Trinket is ready to start bootloading. If you've programmed the Trinket since getting it, you
Please note: you cannot use the Adafruit USB VID/PID for your own non-Trinket
products or projects. Purchase a USB VID for yourself at
http://www.usb.org/developers/vendor/
© Adafruit
Industries https://learn.adafruit.com/introducing-trinket Page 13 of 48

can always get it back to the bootloader state by pressing the small onboard reset button.
Special Notes on using Trinket with Linux
Linux is fairly picky about who can poke and prod at the USB port. You can always run
avrdude or Arduino IDE as root, which will make sure you have the proper permissions. If
you want to be super-cool you can add a udev rule which will let any user (who is not root)
connect to the USBtiny driver. That way you don't have to be root all the time!
Check http://learn.adafruit.com/usbtinyisp/avrdude#for-linux (http://adafru.it/cf3) for what to
add to your udev file.
How to start the bootloader
Before you try to upload code to the Trinket it must be in the Bootloader Mode. That means
its listening for a sketch or program to be sent to it
The Trinket must be connected to a computer via a USB cable to enter bootloader mode.
You can enter the bootloader mode by pressing the little button on the board with your
fingernail. The bootloader will 'time out' after 10 seconds, so to re-enter the bootloader
mode just re-press the button!
Don't press-and-hold the reset button, be sure to press-and-release!
See the video below for what it looks like to plug it in, have the LED pulse in bootloader
mode, time out and then press reset to restart the bootloader
Trinket is not supported on Linux operating system at this time - try Mac OS or
Windows! However, you can try the following - it does work for some computers
When the Trinket is in bootloader mode, the red LED will be pulsing. Once the red LED
stops pulsing, you must press the reset button to re-enter bootloader mode
© Adafruit
Industries https://learn.adafruit.com/introducing-trinket Page 14 of 48

Setting up with Arduino IDE
Chances are, you picked up a Trinket because it is programmable with the Arduino IDE. Note
that the Trinket is not a full Arduino-compatible, it uses a different (smaller) chip than the
Uno, Mega, Leonardo or Due. However, there are many small sketches and libraries that will
work just fine. Some may not even need anything other than pin number changes.
The Fast Way
If you don't want to modify an existing Arduino IDE install, you can simply download our
ready-to-go and tested Flora/Gemma/Trinket-ified v1.05 right here:
Mac Arduino IDE v1.05 w/Trinket,
Gemma, Flora
http://adafru.it/cTN
Windows Arduino IDE v1.05
w/Trinket, Gemma, Flora
http://adafru.it/cUa
If you're using Mac OS Mavericks you will need to update the setting to permit running
Arduino IDE
1. Click the Lock Icon and Login
2. Change "Allow Apps Downloaded From": to "Anywhere"
3. Open the downloaded IDE.
4. Go back to the Security preferences and change the selection back to "Mac App Store
and identified developers"
5. You only need to go through this procedure once. Mavericks will remember that it's OK
to run the app.
The Slow Way
Step 0. Install Arduino IDE
Even though Trinket has a USB connector, it does not have a "Serial Console"
capability, so you cannot use Serial to send and receive data to/from a computer!
On Windows machines, be sure to extract the contents of the zip file. The IDE will not
execute properly from a compressed folder.
© Adafruit
Industries https://learn.adafruit.com/introducing-trinket Page 15 of 48

Trinket support is not native to the Arduino IDE but, luckily, adding it takes only a few minutes
and you only have to do it once! This tutorial will base the IDE off of v1.0.5 which is current at
time of writing. You can try later versions but v1.0.5 is at least guaranteed to work
Adding Trinket support does not affect any other boards that are affected so you can
continue to use the IDE with any Arduino board currently supported.
If you'd like to be cutting edge, check this forum post which has some (untested!)
instructions on using w/1.5 (http://adafru.it/d6D)
Step 1. Add ATtiny85 Support
Download the following file by pressing the button.
Click to download the Trinket
hardware support zip
http://adafru.it/cEh
Unzip it and move the hardware folder from the zip file and place it into to your Arduino
sketchbook folder. Your sketchbook folder is the folder where the Arduino IDE stores your
sketches. This folder is automatically created by the IDE when you install it. If this is your first
time using the Arduino IDE, it will be empty!
On Linux machines, the folder is named "Sketchbook" and it is typically located in
/home/[username]
On Windows and Macintosh machines, the default name of the folder is "Arduino"
and is located in your Documents folder.
Now you can start (or restart the the IDE) and check the Tools->Bo ard menu, you should
see the three new entries for Trinket and Gemma:
Arduino v1.5+ has a different way of handling add-ons like this, please stick to v1.0.x
until we can determine what's different about v1.5! Thanks!
This is a common source of confusion on Windows and Mac machines, your
sketchbook folder is not named "sketchbook" it is named "Arduino"!
© Adafruit
Industries https://learn.adafruit.com/introducing-trinket Page 16 of 48

OK you are half done! Next is updating the avrdude configuration file.
Step 2. Updating avrdude.conf
The second step is to update the AVR chip program upload helper to be a little more patient
with the ATtiny85 bootloader we have on the Trinket. We will update the description of the
chip's erase cycle to be longer, to avoid timeouts and errors.
Windows and Linux users can download the new avrdude.conf by clicking this button:
avrdude.conf for Windows &
Linux
http://adafru.it/cE3
Mac users should download this version and uncompress it
Download avrdude.conf for Mac
http://adafru.it/cGO
Now we will hunt for the original avrdude.conf file. If you are using a Mac, right-click on the
Arduino application icon and select “Show Package Contents” then navigate through the
Contents & Java folders. On Windows you will have to find the installation directory, which
may be a folder on the Desktop or possibly in C:\Program Files if you used the installer.
Likewise in Linux it is where-ever you uncompressed the folder.
Now find the hardware\too ls\avr\etc folder, and inside you should see the
avrdude.conf file. You can also use your operating system's find tool to locate it.
© Adafruit
Industries https://learn.adafruit.com/introducing-trinket Page 17 of 48

Rename the old avrdude.conf to avrdude.bak and copy over the new avrdude.conf
to the same folder
© Adafruit
Industries https://learn.adafruit.com/introducing-trinket Page 18 of 48

Be sure you rename the old file before replacing it with the new one so you are sure to make
the swap!
Step 3. Update 'ld' linker
There's a bug in the 'linker' used by Arduino on Mac & Windows, where you can't make
sketches that are larger than 4K on the Attiny85. Since its really likely you'll make sketches
this large, we suggest replacing it. It's a lot like replacing the avrdude.conf
On Windows: explore the Arduino folder and get to the hardware\tools\avr\bin
subfolder, you'll see a lot of files starting with avr-xxx.
On Mac: Explore the App and find Adafruit
Arduino.app/Contents/Resources/Java/hardware/tools/avr/avr/bin
© Adafruit
Industries https://learn.adafruit.com/introducing-trinket Page 19 of 48

Download the ld for your operating system and replace the one you have now (thanks to
TCWorld for this fix! (http://adafru.it/cGP))
Download the new ld for
Windows
http://adafru.it/cGQ
Download the new ld for Mac
http://adafru.it/cGR
Now restart the Arduino IDE. You are done with setup! Now it's time to say "hello, world" to
your new Trinket with the basic Blink sketch.
Blink!
OK let's practice uploading a sketch by uploading the classic Blink sketch. This program with
blink the onboard red LED that is connected to pin #1. Create a new sketch and copy&paste
© Adafruit
Industries https://learn.adafruit.com/introducing-trinket Page 20 of 48
Table of contents
Other adafruit learning system Microcontroller manuals
Popular Microcontroller manuals by other brands

Microchip Technology
Microchip Technology megaAVR 0 Series manual

STMicroelectronics
STMicroelectronics STM32F038C6 manual

Cypress
Cypress CY8CKIT-042 quick start guide

Nuvoton
Nuvoton NuTiny-SDK-NUC240 user manual

Texas Instruments
Texas Instruments LAUNCHXL-CC1310 Wiring diagrams

Renesas
Renesas V850E2/Fx4 user manual