From Trammell Hudson's Projects

Trinket USB Accellerometer Keyboard

Trinket accelerometer

This project combines an Adafruit Trinket with a i2c accelerometer to create a USB seismograph. The output is sent as the keys A to Z to make it easy to integrate with environments like Scratch.


Trinket accelerometer
Trinket accelerometer

The header pins need to be cut to the right length for the Trinket. The breadboard can be used as a jig to hold the pins straight on the Trinket. For the accelerometer it helps to put another header underneath to hold it level.

Soldering party
Soldering party

We held a soldering party to put together forty kits. So many header pins!


Trinket wiring
Trinket accelerometer

The two components can be connected on the breadboard or in the air using female-female jumper wires. Don't connect them while the Trinket is powered to avoid accidental shorts or other problems! The pinout is:

Function Trinket MMA8451 Color
Power USB VIN Red
Ground GND GND Black
Data #0 SDA Yellow
Clock #2 SCL Green


The code flashed on the devices is in github/osresearch/trinket in the imu/ directory. If you want to change the update rate it is controlled by the last_keystroke timeout in loop().

To setup the Arduino IDE you need to install the Adafruit board package. In Preferences, add to the Board Manager URL:

Install the Trinket Keyboard/Mouse library: or go into Library Manager and install Trinket Keyboard


Adafruit MMA8451 library was too big to fit along with the keyboard library, so I cut it down to just the pieces that were required. The driver is included in the source tree above.