The Trinket: small, versatile and cute

IMG_2603I’ve become a fan of microcontrollers. These little marvels can do a lot: control motors, lights, LED’s,LCD’s, servo mechanisms, keyboards, mice…you name it, it probably has one of these things in it.  Some of them, such as the PIC24, are as powerful as yesterday’s microprocessor and can even run real operating systems or video games (the PIC24 is the heart of the XGS PIC 16 bit board I’ve been porting BASIC-the same BASIC will also run on the Arduino line of microcontroller based development boards.)

Adafruit Industries is one of the leaders in the burgeoning hobby that has sprung up around IMG_2631these little beasts.  They recently introduced the Trinket. The Trinket, based on the ATtiny85 controller, is about an inch long by half inch wide (approx.) and contains a sole USB connection and five I/O lines.

The Trinket is easy to use and program. Using Arduino IDE (free from the Arduino web site) you write using C++ and then upload the resulting code to the device. This is the only thing about the device that I have issue with: You have a very short time in which the device is programmable. The IDE is rather slow, and the interval with which the device will program is about ten seconds. You have to repeatedly press the reset button on the device and hope that you have time to program it, otherwise, you have to start over and the IDE does not appear to be smart enough to know that the source has already been compiled. 

IMG_2637The upload process aside, everything else is rather straight forward. There are a number of guides on the Adafruit site to explain how to set to set up the IDE.  Basically, download and install the IDE, then USBTiny, the driver, then there are two config files you need to download and copy into directories under Arduino IDE and in the Documents directory. Complete instructions are here. I suggest you read through the entire article and then do the install.

Once installed, you would code as if it were an Arduino.  Keep in mind, there is no Serial port, but there is a library that ‘maps’ one to one of the I/O pins. It works, great. I used it to talk to one of the Parallax 2×16 LCD panels I picked up from Radio Shack. See my source code snippet below for more.

One of the really nice features is that you can power this thing using three 1.5 volt AAA batteries. Input voltage can be from 3.3 to 16 volts.  The device comes in 3v and 5v flavors, meaning you have to be careful about what you connect to the device. I got two 3v boards as the 5v boards were sold out. I tried with both a 9v battery and three 1.5 volt AAA cells. Of course, you can also power it from the USB connections. And anything connected will, likely, need its own power source.

At $7.95, you cannot really go wrong.  Check out Adafruit’s site for project ideas. I have a couple in mind, including that Star Trek game I wrote of, several posts ago.  In a future post, I will share what I have done with these as well as how my homebrew PIC16 project turns out. And look for more on that Tiny Basic port to the XGS.

#include <SoftwareSerial.h>

SoftwareSerial s(0,1); //receive on "0", and transmit on "1" aka "PB1" aka pin 6

void setup() {   s.begin(9600);// set baud rate to 9600 baud   }    void loop() {   s.write(12);// clear screen   s.write(17);// turn on backlight   s.println("Adafruit Trinket");   s.println("2x16LCD Parallax");      } 
Advertisements

2 thoughts on “The Trinket: small, versatile and cute

  1. hi, I also want to use Serial communication on my trinket to talk with my computer. How can I connect the 2 pins to my computer? And needs the trinket still an usb connection to the computer? I didn’t get it how this work 😦

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s