Saturday, 21 September 2013

Adafruit Trinket Trial

I couldn't resist buying a six pack of Trinkets, so now it's time to see if I can get one working. I went straight to the http://learn.adafruit.com/introducing-trinket/setting-up-with-arduino-ide page in the tutorial and followed the mac instructions. I renamed the ld file to avr-ld to match the one that was already in the package, then followed the instructions to select Trinket 8Mz as the board and USBtinyISP as the programmer. (Serial Port seems to be a non-issue...)

The blink sketch loaded and ran on a 3V Trinket with the results you would expect. Tried uploading the Button sketch from the next tutorial page and got avrdude: Error: Could not find USBtiny device (0x1781/0xc9f) repeatedly. Apparently you need to press the button on the Trinket before uploading to wake up the boot loader and the red LED will pulse for about 10 seconds, then fall back to whatever program was already loaded. Pulse also loaded and ran with the expected result. Switching to the 5V Trinket produced the same results.

Can it replace an Arduino Micro in the Hat Demo?

The brim of the ball cap has a little sign that
flips up and down on a servo
The Hat Demo is a ball cap I augmented for the Kingston Maker Space booth at this summer's Princess Street Promenade. It uses a Sharp proximity sensor to measure distance to whoever is fight in front of you, then actuates a servo to raise a little sign. Basically, the sign pops up when somebody comes close. It couldn't get much simpler. (Motors/ServoSharp has the code.)

Compiling produced errors from the servo library, which I would have expected if I had read http://learn.adafruit.com/trinket-gemma-servo-control/overview before I tried it. Switching the code over to the Adafruit_SoftServo library lets it compile.

The Arduino Micro version of the hat controller drives the servo and the Sharp sensor from the 5V regulated voltage on the Micro, which can supply an unspecified current. The trinket can provide up to 150 mA on the 5V pin. I tried a straight substitution and it didn't work for me. Back to start. Tried the TrinketKnob sketch and circuit and it provided sensible results. Turns out I needed some extra code for interrupts to keep the SoftwareServo stuff working. I also found that the servo rotated only half as far as it did with the Micro and the standard servo library.

Once I got it working I ran into some odd behaviour with the system working on USB, but behaving strangely when powered from a 9V battery. It seems to have been just loose wires, but there may have been some elements of getting slightly different voltages back from the analog sensor with the different supply. Still, with a little fiddling around I now have liberated the $30 Micro from the hat demo and replaced it with the $8 Trinket and that has the potential to bring down the cost of many small projects!

The trinket version has a controller smaller than the sensor, and cheaper too!






No comments:

Post a Comment