Introducing Trinket Created by lady ada Last updated on 2015-08-20 10:00:25 PM EDT
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 Windows Driver Installation Adafruit Trinket/Gemma Driver Installation Arduino Gemma Driver Installation Flora Driver Installation Windows 8 & 10 Windows 7 Locating the Driver File (Win 7 & XP) Windows 10 Driver Installation Setting up with Arduino IDE
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 56 How to activate the 16 MHz clock ...on AVR-GCC ...Arduino IDE 56 56 56 Repairing bootloader Downloads Datasheets Windows Driver Source code Schematics FAQ © Adafruit Industries 42 44 45 45 46 52 53 56 58 60 60 60 60 60 63 https://learn.adafruit.
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.
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.
© Adafruit Industries https://learn.adafruit.
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 connector - 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.
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.
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.
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.
Here's the ATtiny85 pinout © Adafruit Industries https://learn.adafruit.
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 suggested. This input is reverse-polarity protected. USB+ is the USB + Output pin.
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.
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 © Adafruit Industries https://learn.adafruit.
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.
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.
Windows Driver Installation To use a Trinket, Gemma, or Flora on Windows you will need to install a driver for your board. Follow the steps below depending on the board you're using: Adafruit Trinket/Gemma (black board) Driver Installation (http://adafru.it/eTU) Arduino Gemma (teal board) Driver Installation (http://adafru.it/eTU) Flora Driver Installation (http://adafru.it/eTU) Note on Mac OSX or Linux you don't need to install any driver to use Adafruit's boards.
If you're using Windows 10 you might need to follow the steps at the bottom of the page to manually install the driver (http://adafru.it/eTU). Arduino Gemma Driver Installation If you're using the Arduino Gemma (teal or blue/green circuit board, not the black circuit board Adafruit Gemma--if you have a Adafruit Gemma skip back up to the previous section (http://adafru.it/eTU)) follow the steps below to install a custom driver for the board.
We now have signed Windows 8/10 drivers for flora. Download the driver by clicking here. You should be able to right-click the inf file to install it directly, or point Windows to this uncompressed folder when prompted! If you're using Windows 10 you might need to follow the steps at the bottom of the page to manually install the driver (http://adafru.it/eTU). Downloads the Windows XP/7/8 signed Flora Driver http://adafru.
Click on the Device Manager (top icon in the menu) to launch it, scroll down until you see Adafruit Flora with a ! mark. Right click and select Update Driver Software © Adafruit Industries https://learn.adafruit.
Locating the Driver File (Win 7 & XP) OK if you have XP you'll basically start from here, click Browse my computer for driver software Then browse to the uncompressed Flora IDE folder, and select the drivers folder (not any other folder!) and click OK. © Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
Make sure the folder next to the Browse... button is correct, then click Next. When you get this scary window next, click Install this driver software anyway. © Adafruit Industries https://learn.adafruit.
That's it! Thankfully you only have to do this once. Windows 10 Driver Installation If you're using Windows 10 the process to an install a custom driver is a little different than previous Windows versions. When you plug in your device, like a Trinket/Gemma/Flora, you might not get a pop up telling you to install a driver for the device. However you can follow the steps below to manually install the driver.
Press the bootloader button on the Trinket/Gemma and after a few moments you should see device manager refresh and display the board under an Other devices node: © Adafruit Industries https://learn.adafruit.
Right-click the board (like Trinket in this example) and click the Update Driver Software... option at the top. This should open a new dialog that looks like the following: © Adafruit Industries https://learn.adafruit.
Select the Browse my computer for driver software option at the bottom. Now you should see a dialog to find the driver like below: © Adafruit Industries https://learn.adafruit.
Click Browse... and navigate to the folder where you unzipped the driver that was downloaded earlier. Make sure the 'Include subfolders' option is checked so Windows is sure to find the driver. Then click the Next button at the bottom. You should see the driver installation start. During the installation you will probably see a pop-up like below that asks if you want to allow the Adafruit driver to be installed: © Adafruit Industries https://learn.adafruit.
Make sure Always trust software from "Adafruit Industries" is checked, then click Install. The driver should finish installing. Note that you might see a "This device cannot start (Code 10)" failure like the following: © Adafruit Industries https://learn.adafruit.
Don't worry! This just means the Trinket/Gemma bootloader timed-out before the driver finished installing. Everything should still be fine and you can continue along with the installation. Click Close to finish the install. Now device manager should show a libusb (WinUSB) devices node with the USBtiny device below it: © Adafruit Industries https://learn.adafruit.
Don't worry if the device has an exclamation point next to it indicating a problem. Press the Trinket/Gemma bootloader button and after a moment device manager should update to show the device is working: © Adafruit Industries https://learn.adafruit.
That's it, your board should be ready to go and program with the Arduino IDE! © Adafruit Industries https://learn.adafruit.
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.
/* Blink Turns on an LED on for one second, then off for one second, repeatedly. This example code is in the public domain. To upload to your Gemma or Trinket: 1) Select the proper board from the Tools->Board Menu 2) Select USBtinyISP from the Tools->Programmer 3) Plug in the Gemma/Trinket, make sure you see the green LED lit 4) For windows, install the USBtiny drivers 5) Press the button on the Gemma/Trinket - verify you see the red LED pulse.
Then, select USBtinyISP from the Tools->Programmer sub-menu Plug in the Trinket, make sure you see the green LED lit (power good) and the red LED pulsing. Press the button if the red LED is not pulsing, to get into bootloader mode. Click the Upload button (or select File->Upload) © Adafruit Industries https://learn.adafruit.
If everything goes smoothly you should see the following (no red error messages) and of course, the red LED on the trinket will blink on/off once a second Something Went Wrong! © Adafruit Industries https://learn.adafruit.
If you get the error message avrdude: Error: Could not find USBtiny device (0x1781/0xc9f) That means the bootloader wasn't active. Make sure to press the button on the Trinket to activate the bootloader before clicking the Upload button. If you get a lot of red text, errors and also a warning about Verification Failed Check that you updated the avrdude.
On Linux if you get the error message "usbtiny_receive: error sending control message: Protocol error (expected 4, got -71)" © Adafruit Industries https://learn.adafruit.
These can generally be ignored and should not interfere with the program upload. Unfortunately Linux's USB core is a little flakey communicating with the ATtiny85 processor on the Trinket/Gemma and can cause these errors. If an upload does fail, try it again as it is likely an intermittent issue. © Adafruit Industries https://learn.adafruit.
Programming with Arduino IDE Once you've gotten the basic Blink example to work, you can try some of the other Arduino functions and libraries.
/* Button Turns on an LED when a switch connected from #0 to ground is pressed This example code is in the public domain. To upload to your Gemma or Trinket: 1) Select the proper board from the Tools->Board Menu 2) Select USBtinyISP from the Tools->Programmer 3) Plug in the Gemma/Trinket, make sure you see the green LED lit 4) For windows, install the USBtiny drivers 5) Press the button on the Gemma/Trinket - verify you see the red LED pulse.
For example, to read an analog voltage on pin #2, you would call analogRead(1) to read an analog voltage on pin #4 call analogRead(2) This is a bit confusing because the analog pins are numbered differently than the digital pins! analogWrite() There are a few PWM outputs on the Trinket, you can call analogWrite() on digital #0, #1 and #4. For example, to pulse the built-in LED slowly, upload this code: © Adafruit Industries https://learn.adafruit.
/* Pulse Pulses the internal LED to demonstrate the analogWrite function This example code is in the public domain. To upload to your Gemma or Trinket: 1) Select the proper board from the Tools->Board Menu 2) Select USBtinyISP from the Tools->Programmer 3) Plug in the Gemma/Trinket, make sure you see the green LED lit 4) For windows, install the USBtiny drivers 5) Press the button on the Gemma/Trinket - verify you see the red LED pulse.
void PWM4_init() { // Set up PWM on Trinket GPIO #4 (PB4, pin 3) using Timer 1 TCCR1 = _BV (CS10); // no prescaler GTCCR = _BV (COM1B1) | _BV (PWM1B); // clear OC1B on compare OCR1B = 127; // duty cycle initialize to 50% OCR1C = 255; // frequency } // Function to allow analogWrite on Trinket GPIO #4 void analogWrite4(uint8_t duty_value) { OCR1B = duty_value; // duty may be 0 to 255 (0 to 100%) } More... We also know the following libraries work: Adafruit NeoPixel (http://adafru.
Programming with AVRdude For more technical users, rather than using the Arduino IDE, they may want to program the Trinket directly with AVR-GCC as the compiler, vi/emacs as their editor and AVRdude as the uploader. That's easy to do! Target the Attiny85 as the chip used in avr-gcc, with F_CPU at 8MHz using the internal oscillator. To use avrdude a minor change must be made to to avrdude.conf. To figure out where the avrdude.
A slightly different configuration file is needed for Mac: avrdude.conf (Mac version) http://adafru.it/cEx You can also find a Linux version of the avrdude.conf file here: avrdude.conf (Linux version) http://adafru.it/dXe The Long Way If you want to update your avrdude.conf by hand, its not too hard. Open up that exact file in your favorite text editor and find the following text © Adafruit Industries https://learn.adafruit.
#-----------------------------------------------------------# ATtiny85 #------------------------------------------------------------ Delete the text after the Attiny85 header text starting with part and onto until the next header (in ours, that was ATmega640 © Adafruit Industries https://learn.adafruit.
Then paste in the following in the spot where you just deleted! part id = "t85"; desc = "ATtiny85"; has_debugwire = yes; flash_instr = 0xB4, 0x02, 0x12; eeprom_instr = 0xBB, 0xFF, 0xBB, 0xEE, 0xBB, 0xCC, 0xB2, 0x0D, 0xBC, 0x02, 0xB4, 0x02, 0xBA, 0x0D, 0xBB, 0xBC, 0x99, 0xE1, 0xBB, 0xAC; ## no STK500 devcode in XML file, use the ATtiny45 one stk500_devcode = 0x14; ## avr910_devcode = ?; ## Try the AT90S2313 devcode: avr910_devcode = 0x20; signature = 0x1e 0x93 0x0b; reset = io; chip_erase_delay = 900000; pgm
"x x x x x x x x chip_erase x x x x x x x x"; = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", "x x x x x x x x x x x x x x x x"; timeout = 200; stabdelay = 100; cmdexedelay = 25; synchloops = 32; bytedelay = 0; pollindex = 3; pollvalue = 0x53; predelay = 1; postdelay = 1; pollmethod = 1; hvsp_controlstack = 0x4C, 0x0C, 0x1C, 0x2C, 0x3C, 0x64, 0x74, 0x66, 0x68, 0x78, 0x68, 0x68, 0x7A, 0x6A, 0x68, 0x78, 0x78, 0x7D, 0x6D, 0x0C, 0x80, 0x40, 0x20, 0x10, 0x11, 0x08, 0x04, 0x02, 0x03, 0x08, 0x04, 0x00; hventerstabdelay =
write = "1 1 0 0 0 0 0 0 0 0 0 x x x x a8", "a7 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; loadpage_lo = " 1 " 0 0 0 0 " 0 0 0 0 " i i i i i 1 0 0 i 0 0 0 0 0 1", 0 0 0", 0 a1 a0", i i"; writepage = " 1 1 0 0 0 0 1 0", " 0 0 x x x x x a8", " a7 a6 a5 a4 a3 a2 0 0", " x x x x x x x x"; mode = 0x41; delay = 12; blocksize = 4; readsize = 256; ; memory "flash" paged = yes; size = 8192; page_size = 64; num_pages = 128; min_write_delay = 30000; max_write_delay = 30000; readback_p1 = 0xff; readback_p2 = 0xff; rea
writepage = " 0 1 0 0 1 1 0 0", " 0 0 0 0 a11 a10 a9 a8", " a7 a6 a5 x x x x x", " x x x x x x x x"; mode = 0x41; delay = 6; blocksize = 32; readsize = 256; ; # ATtiny85 has Signature Bytes: 0x1E 0x93 0x08.
memory "efuse" size = 1; write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", "x x x x x x x x x x x x x x x i"; read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", "x x x x x x x x o o o o o o o o"; min_write_delay = 9000; max_write_delay = 9000; ; memory "calibration" size = 2; read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", "0 0 0 0 0 0 0 a0 o o o o o o o o"; ; ; If editing manually, Mac users should delete all references to parallel port programmers ("type = par;"). Uploading with AVRdude Now you're ready to use avrdude.
response as shown here: If you get the response avrdude: Error: Could not find USBtiny device (0x1781/0xc9f) the bootloader is not active, make sure you see the red LED pulsing, press the reset button to start the bootloader again. Programming in a Blink example For more details on using avdude and avr-gcc, you'll need to read a detailed tutorial or book on those subjects. However, you can do a basic test by uploading the following HEX file, which will blink the #1 LED once a second on and off.
As before, type out the command, then press the reset button to start the bootloader and once the red LED is pulsing, hit return When uploading, you will see a lot of avrdude: 8 retries during SPI command and similar warnings. THIS IS OK! Because of the way the ATtiny85 works, there's a small delay when writing the new program to flash, and during that delay, it cannot save the data and also send USB data at the same time.
© Adafruit Industries https://learn.adafruit.
16MHz vs 8MHz Clock The Trinket by default runs at 8 MHz, a plenty fast speed for nearly all of your microcontroller needs. However, you may want to use code that requires it to run at 16 MHz, or maybe you just want a little boost in speed. The 16 MHz clock speed for Trinket 5V only! The ATtiny85 is only specified to run at 16 MHz when powered at 5V - that means that officially you can only run the 5V Trinket at 16 MHz.
Then select Trinket 16MHz from the Tools->Board menu. Your code will compile and run at 16 MHz! © Adafruit Industries https://learn.adafruit.
Repairing bootloader The ATtiny85 does not have a protected-bootloader section. This means its possible to accidentally overwrite the bootloader (or even if you unplug the Trinket while uploading it might have difficulties from then on) You can use an Arduino UNO to re-program the bootloader onto your Trinket (or Gemma). This loader isn't tested to work with any other kind of Arduino.
© Adafruit Industries https://learn.adafruit.
Downloads Datasheets Datasheet for the onboard regulator used (MIC5225 3.3V and 5.0V) (http://adafru.it/dQO) Webpage for the ATtiny85, the microcontroller used in the Trinket (http://adafru.it/cE5) Windows Driver Please note a driver is not required for Mac or Linux. And the driver does not appear as a 'COM' port! It will show up as a 'USBtinyISP' device USBtinyISP Windows XP/7/8 compatible http://adafru.it/djr Source code Original code for the Trinket/Gemma bootloader on github (http://adafru.
Trinket 5V schematic © Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
FAQ I'd like to use Trinket with Linux.... We don't guarantee Linux support since Linux varies from distro to distro, but here's a very nice tutorial about Trinket with Ubuntu 14) (http://adafru.it/dML) I can't seem to upload to my Trinket when it's plugged into a USB 3.0 port (newer Macbooks have USB 3 ports) Trinket's bootloader is finicky about USB 3 ports, and might not work on them.
under the ATtiny85 heading to chip_erase_delay = 400000; That is, a shorter delay. Can Trinket driver Neopixels (strips, squares, etc)? How many? Yes! Trinket was designed to drive short segments of NeoPixels. There is enough RAM on the attiny85 to drive 100 pixels, but depending on program RAM usage you may have to scale back to 60 or 40. You can use EITHER the 3V or 5V Trinket, at EITHER 8 or 16MHz! To use with neopixels: 1.
causes the 'disconnect' sound. On a new trinket, the main sketch will automatically jump back to the bootloader, which will then cause the 'connect' sound. This cycle will repeat until a user sketch is loaded. This situation can also happen if you load a sketch with a bug in it that causes a CPU reset.