Introducing Trinket Created by lady ada Last updated on 2018-02-17 07:37:06 PM UTC
Guide Contents Guide Contents Introduction Guided Tour Pinouts Power Pins GPIO Pins USB 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 Manual Driver Installation Setting up with Arduino IDE Arduino IDE Setup Blink! Something Went Wrong! 2 4 6 7 8 8 9 9 11 11 11 11 11 13 14 16 16 16 19 If you get the error message avrdude: Error: Could not find USBt
Datasheets Source code Schematics Newer Trinket (Micro USB) dimensions Older Trinket (Mini USB) dimensions FAQ 38 38 38 39 40 42 How come I can't find the Trinket Serial (COM) Port? Why is no Serial port found when the Trinket is plugged in? I'd like to use Trinket with Linux.... 4242 I can't seem to upload to my Trinket when it's plugged into a USB 3.
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 devboard and you aren't willing to take apart the project you worked so hard to design.
ATtiny85 on-board, 8K of flash, 512 byte of SRAM, 512 bytes of EEPROM Internal oscillator runs at 8MHz, but can be doubled in software for 16MHz USB bootloader with a nice LED indicator looks just like a USBtinyISP so you can program it with AVRdude (with a simple config modification) and/or the Arduino IDE (with a few simple config modifications) Mini or Micro-B USB jack for power and/or USB uploading, you can put it in a box or tape it up and use any USB cable for when you want to reprogram.
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.
Pinouts 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 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.
On a 3V Trinket, the GPIO are 3.3V output level, and should not be used with 5V inputs. On a 5V Trinket, the GPIO are 5V output level, and can be used with 3V inputs but may damage electronic devices that are 3V input only! The first 3 pins are completely 'free' pins, they are not used by the USB connection so you never have to worry about the USB interface interfering with them when programming GPIO #0 - this is connected to PB0 on the ATtiny85.
© 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.
When the Trinket is in bootloader mode, the red LED will be pulsing. Once the red LED stops pulsing, you must press the reset button to re-enter bootloader mode The Trinket must be connected to a computer via a USB cable to enter bootloader mode. You can enter the bootloader mode by pressing the little button on the board with your fingernail.
Windows Driver Installation Mac and Linux do not require drivers, only Windows folks need to do this step Before you plug in your board, you'll need to possibly install a driver! Click below to download our Driver Installer. Download Latest Adafruit Windows Driver Installer https://adafru.it/A0N Download and run the installer.
On Windows 7, by default, we install a single driver for most of Adafruit's boards, including the Feather 32u4, the Feather M0, Feather M0, Express, Circuit Playground, Circuit Playground Express, Gemma M0, Trinket M0, Metro M0 Express. On Windows 10 that driver is not necessary (it's built in to Windows) and it will not be listed. The Trinket / Pro Trinket / Gemma / USBtinyISP drivers are also installed by default.
https://adafru.it/AB0 And point windows to the Drivers folder when it asks for the driver location © 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 1) 2) 3) 4) 5) upload to your Gemma or Trinket: Select the proper board from the Tools->Board Menu Select USBtinyISP from the Tools->Programmer Plug in the Gemma/Trinket, make sure you see the green LED lit For windows, install the USBtiny drivers Press the button on the Gemma/Trinket - verify you see the red LED pulse.
The Serial Port menu will not show the Trinket, that's normal! 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 © Adafruit Industries https://learn.adafruit.
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. © Adafruit Industries https://learn.adafruit.
If you get a lot of red text, errors and also a warning about Verification Failed Try again! Make sure you have a good USB cable, try connecting through a hub if you have one. © Adafruit Industries https://learn.adafruit.
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. © 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.
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.
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%) } Wire (i2c) You can use I2C with the Trinket! If you have our board manager package v1.6.
Programming with AVRdude For more technical users, rather than using the Arduino IDE, they may want to program the Trinket directly with AVRGCC 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.
avrdude.conf (Linux version) https://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 #-----------------------------------------------------------# ATtiny85 #------------------------------------------------------------ © Adafruit Industries https://learn.adafruit.
Delete the text after the Attiny85 header text starting with part and onto until the next header (in ours, that was ATmega640 Then paste in the following in the spot where you just deleted! part id = "t85"; desc = "ATtiny85"; has_debugwire = yes; © Adafruit Industries https://learn.adafruit.
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_enable = "1 0 1 0 "x x x x 1 1 0 0 x x x x 0 1 0 1 x x x x 0 0 1 1", x x x x"; chip_erase = "
write "a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; = "1 1 0 0 "a7 a6 a5 a4 0 0 0 0 a3 a2 a1 a0 0 0 0 x i i i i x x x a8", i i i i"; loadpage_lo = " 1 1 " 0 0 0 0 " 0 0 0 0 " i i i i writepage = " 1 " 0 0 x " a7 a6 a5 " x x x 1 x a4 x mode = 0x41; delay = 12; blocksize = 4; readsize = 256; ; memory "flash" paged size page_size num_pages min_write_delay max_write_delay readback_p1 readback_p2 read_lo 0 0 0 i 0 0 a1 i x a2 x 0 x 0 x 0 x a3 x = = = = = = = = = 0 0 0 i 0 yes; 8192; 64; 128; 300
# ATtiny85 has Signature Bytes: 0x1E 0x93 0x08.
Now you're ready to use avrdude. Open up your command line and enter in this line (but don't hit return) avrdude -c usbtiny -p attiny85 Now plug in the Trinket into the computer's USB port and/or press the reset button to enter the bootloader. You should see the red LED pulsing.
trinketblink.hex https://adafru.it/cF1 And uploading it with the command avrdude -c usbtiny -p attiny85 -U flash:w:trinketblink.hex or, if that's giving errors, avrdude -c usbtiny -p attiny85 -D -U flash:w:trinketblink.hex (note the extra -D) 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.
© 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 is 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.
© 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.
If you keep getting "Failed to verify fuses" while trying to restore the bootloader on a 3.3V Trinket using a Duemilanove. Try connecting 5V to the 3V pin on the Trinket, not VBAT+. Make sure USB is not plugged into the Trinket when you do this. Its a bit of a hack but may help! © Adafruit Industries https://learn.adafruit.
Downloads Datasheets Datasheet for the onboard regulator used (MIC5225 3.3V and 5.
Newer Trinket (Micro USB) dimensions These are the same for the 3V and 5V versions The following shows measurements in mm, both version of the Trinket have the exact same dimensions for hole placement & outline For more dimensions or if something is missing you need, check the Eagle CAD files above which will give you the location of every component and hole! © Adafruit Industries https://learn.adafruit.
Older Trinket (Mini USB) dimensions These are the same for the 3V and 5V versions © Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
FAQ How come I can't find the Trinket Serial (COM) Port? Why is no Serial port found when the Trinket is plugged in? Trinket (and Pro Trinket) do not have a USB-serial converter chip on board, this is how we can make them so small! Instead of a serial console, the Trinket is programmed directly over USB. No COM/Serial port is used at all! I'd like to use Trinket with Linux....
To use with neopixels: 1. Connect the + power line of the strip to VBUS (5V from USB), to VBAT if you are powering the Trinket with 47VDC, or to a separate 4-7VDC power source such as a 3 or 4 pack of AA batteries. 2. Connect the - common ground to the battery pack (if being used) and also to the Trinket GND pin 3. Connect the data in line to Trinket #1 - this will let you also see when data is being sent because the #1 red LED will flicker.