Setting up with Arduino IDE

Author Gravatar Image LADY ADA
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.
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!
When you're ready to upload, make sure the "Programmer" in the Tools menu is set to USBtinyISP!

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:
On Windows machines, be sure to extract the contents of the zip file. The IDE will not execute properly from a compressed folder.

Mac OSX

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.

Linux

When installing the Linux version of the modified Arduino IDE you will want to add a udev rule so the IDE can be run as a non-root user and access the USB ports.  If you're using Ubuntu you can follow these steps to install an updated udev rule:

Copy Code
wget https://github.com/adafruit/Trinket_Arduino_Linux/raw/master/adafruit-trinket.rules
sudo cp adafruit-trinket.rules /etc/udev/rules.d/
sudo reload udev

If you're not using Ubuntu, you might need to modify the udev rule to change the group to something other than "dialout".  Check out this page for more tips on udev configuration ideas and try:

SUBSYSTEM=="usb",ATTR{idProduct}=="0c9f",ATTRS{idVendor}=="1781",MODE="0660",GROUP="dialout"

Seems to be the right one for most installs

NOTE: When using Trinket in the Linux Arduino IDE make sure to change the programmer to "USBtinyISP" under the Tools -> Programmer menu!

The Slow Way

Step 0. Install Arduino IDE

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.

Linux note: You can find instructions for manually modifying the Arduino IDE to support Trinket/Gemma/Flora in the README of the Trinket Arduino Linux github repository.

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!

Step 1. Add ATtiny85 Support

Download the following file by pressing the button.

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.
This is a common source of confusion on Windows and Mac machines, your sketchbook folder is not named "sketchbook" it is named "Arduino"!
Now you can start (or restart the the IDE) and check the Tools->Board menu, you should see the three new entries for Trinket and Gemma:

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 users can download the new avrdude.conf by clicking this button:

Mac users should download this version and uncompress it

On Linux download this version of the file:

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\tools\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.
Rename the old avrdude.conf to avrdude.bak and copy over the new avrdude.conf to the same folder
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
Download the ld for your operating system and replace the one you have now (thanks to TCWorld for this fix!)
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 the following into it, you can then save it as trinketblink or something similar, so you have it handy
If you are using Linux you will have to be "root" running the Arduino program to have access to the USB port
Copy Code
      /*
  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. This means it is ready to receive data
  6) Click the upload button above within 10 seconds
*/
 
int led = 1; // blink 'digital' pin 1 - AKA the built in red LED

// the setup routine runs once when you press reset:
void setup() {
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);

}

// the loop routine runs over and over again forever:
void loop() {
    digitalWrite(led, HIGH); 
    delay(1000);
    digitalWrite(led, LOW);
    delay(1000);
}
    
Select the Trinket 8MHz board from the Tools->Board menu
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)
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!

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.conf file above - if you don't update the description of the Attiny85 in the configure file by replacing it, the IDE wont know to be patient with the Trinket bootloader and will have many upload errors

On Linux if you get the error message "usbtiny_receive: error sending control message: Protocol error (expected 4, got -71)"

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.

Last updated on 2015-02-28 at 11.30.17 AM Published on 2013-09-03 at 05.30.12 PM