Adafruit Trinket Programming

- %post_shorttitle%
- %post_shorttitle_linked%
- %post_shorttitle_linked%
I recently bought an Adafruit Trinket because I wanted to build a USB Volume Knob.
First, install the Adafruit Trinket/Gemma driver for Windows.
Next, you need to install support for Adafruit AVR boards in your Arduino IDE. You also only need to do this once:
- menu File » Preferences and enter the following URL where it says Additional Boards Manager URLs:
https://adafruit.github.io/arduino-board-index/package_adafruit_index.json - menu Tools » Board » Board Manager, scroll down the list to find the Adafruit AVR Boards entry and click the Install button
Then restart the Arduino IDE.
Finally, from the Tools menu:
- menu Tools » Board » Adafruit Trinket 8MHz
- menu Tools » Programmer » USBtinyISP
That’s it! You can now upload the following Blink sketch to the Trinket to test it (menu Sketch » Upload).
void setup() { pinMode(1, OUTPUT); } void loop() { digitalWrite(1, HIGH); delay(1000); digitalWrite(1, LOW); delay(1000); }
Note that the Trinket goes into programmable mode only a few seconds after plugging it in or after pressing the reset button on the Trinket—the integrated red LED lights up during this time—before running your code. So don’t forget to press the reset button right before uploading to it or you’ll get an error message “avrdude: Error: Could not find USBtiny device”.
16 MHz vs 8 MHz
By default the Adafruit Trinket runs at 8MHz, but you can change that to 16MHz in software by adding an include and a line to your setup as shown in the example below and then changing your board selection from the Tools menu to Adafruit Trinket 8MHz. Note however, that you can only do this safely for the 5V Trinket and not for the 3.3V Trinket!
#include <avr/power.h> void setup() { if (F_CPU == 16000000) clock_prescale_set(clock_div_1); pinMode(1, OUTPUT); } void loop() { digitalWrite(1, HIGH); delay(1000); digitalWrite(1, LOW); delay(1000); }