Adafruit Trinket Programming

This is part 1 of 3 in the series USB Volume Knob
  • %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:

  1. 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
  2. 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:

  1. menu Tools » Board » Adafruit Trinket 8MHz
  2. 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);
}
USB Volume Knob »

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.