Getting Code Onto Trinket

Before we start disassembling or building the circuit, it's a good idea to get code uploaded to the micro-controller first. If you don't write / understand code, don't to worry! You don't need to be a programmer to be able to upload prewritten code :-) 

We'll walk you through the whole process. 

First, visit the Trinket tutorial page by clicking the button below. Follow the instructions to download & setup the Arduino IDE and install drivers.

Make sure you are able to get sketches compiled and uploaded, especially the blink example in the tutorial. Once you are comfortable with using the Trinket, you can continue!

Install Adafruit NeoPixel Library

Next, we need to add support for NeoPixels.

Visit the Adafruit NeoPixel tutorial to install the NeoPixel library!

Download Code to Sketch Folder

Now that we have the Adafruit boards & NeoPixel library installed, we can get our code ready to upload onto the board. Click the button below to download a zip file of the Arduino sketch. Uncompress it and place the folder to the Sketches folder. Open the file named "GemmaHoopAnimator.ino".

Uploading Code to Board

Then, in Arduino IDE, paste it in the sketch window (making sure to overwrite anything currently there). Next, goto the Tools menu > Board and select Adafruit Trinket (if you're using the 3V Adafruit Trinket version use Trinket 8Mhz. If you're using the 5V Trinket, select Trinket 12Mhz). Now you can click on the "check mark" icon to verify the code. If it's all good, we can continue to upload the code to the board.

Connect USB Data Cable to Trinket

Be sure to use a micro USB cable that can transfer data - A USB cable that ONLY charges devices will simply not work. Plug it into the microUSB port on the Adafruit Trinket board and the USB port on your computer (try to avoid connecting to a USB hub). As soon as you plug it in, you'll see a red LED blink on the Adaruit Trinket - This let's you know the board is ready to except code. While the LED is blinking, click on the Upload button (It's a right arrow icon, next to the check mark). The Arduino IDE will notify you if the upload is successful and completed.

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN 4 // the neopixels are wired to pin #4
#define NUM_LEDS 76 // here's the number of neopixels
#define BRIGHTNESS 50 // change brightness here – 255 for full brightness

//neopixel object defined here
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRBW + NEO_KHZ800); 

void setup() {
  //special sauce for trinket
  #if defined (__AVR_ATtiny85__)
    if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  #endif
  //special sauce for trinket

  strip.setBrightness(BRIGHTNESS); //global brightness 
  strip.begin(); // start neopixel 
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  colorWipe(strip.Color(0, 0, 0, 255), 50);
}


void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

  

This guide was first published on Feb 08, 2017. It was last updated on Feb 08, 2017.

This page (Code) was last updated on Feb 02, 2017.

Text editor powered by tinymce.