We usually think of the Adafruit Trinket as a tiny subset of a “real” Arduino; less RAM, less code space, less I/O. But this little chip has a couple tricks up its sleeve, things its larger brethren can’t do. One of these is a high-speed PWM mode. With just a few extra components this can be used for audio output. Not simply piezo beeps and buzzes…actual sampled digital sound!

You could make an electronic greeting card with your own customized message or song, add a background soundtrack to a model train diorama, or create the world’s smartest whoopee cushion.

So will this play MP3s and stuff?

No. It’s a very simple circuit that just plays a short “raw” audio loop. For more sophisticated audio projects, check out our VS1053 Codec board.

Parts Needed

There are two phases to this project. The first (using a regular Arduino) loads sound data onto a flash memory chip, the second (using Trinket) plays it back. Both stages use some parts in common:

For the “loading” stage:

  • Arduino Uno or similar board
  • Capacitor: one 0.1 μF
  • Resistors: 3 each 470 Ohm and 1K Ohm
  • You can optionally add an LED (any color) and 220 Ohm resistor for a status indicator
Not all of these parts are available from Adafruit. You may be able to swap out for different parts you already have on-hand or can acquire locally; the “Loading Sounds” page has some guidance on alternative parts selection.

For the “playback” stage:

and either:
or:
The “Sound Playback” page likewise has some guidance on alternative parts selection. There’s a lot of wiggle room, not everything needs to be a super-precise value.

Software Needed

You'll need sound files in WAV format. You can search for downloadable examples on the internet (movie quotes, cartoon sounds, etc.), or record or convert something from your music collection using software such as Audacity (free download).

This project uses both Processing and the Arduino IDE. Both look very similar when running, which can lead to confusion, so make sure you’re loading the right code in the right editor! Processing is for writing code to run on your computer, while Arduino is for writing microcontroller code.

Download version 2.0 (or later) of Processing from processing.org (our software won’t work with the 1.5 version, if you currently have that installed).

If this is your first time using Trinket, work through the Introducing Trinket guide first; you need to install and then customize some settings in the Arduino IDE. Once you have it up and running (test the “blink” sketch), then download and install the TinyFlash library:
Installing Arduino libraries is a frequent stumbling block. If this is your first time, or simply needing a refresher, please read the All About Arduino Libraries tutorial.

When properly installed, in the Arduino IDE you should then have access the rollover menu File→Sketchbook→Libraries→Adafruit_TinyFlash

The “examples” folder included with the library contains all the code for this project; there’s nothing else to download.

Why this weird flash memory chip? Why not an SD card?

Good question! There are a couple of reasons:
  • The flash chip is super affordable, so you can make it a permanent part of a small project. As it’s in DIP chip form, you don’t need to buy a special breakout board like you would for an SD card.
  • Reading a FAT-formatted SD card with this tiny microcontroller is incredibly difficult; a single SD block would fill the chip’s entire RAM! We have seen projects that do this, so it’s not impossible but is nonetheless quite challenging. Perhaps we’ll revisit this idea in the future.
Last updated on 2014-04-24 at 12.30.21 AM Published on 2013-10-21 at 07.43.46 PM