Introduction: Music Player Using Teensy 3.1
Teensy 3.1 from PJRC features a powerful ARM processor with DSP instructions. Audio applications are facilitated by PJRC's audio adapter and audio software library. My music player is an initial exploration of this potential, and plays WAV files from the audio adapter's micro-SD drive at full CD quality. Reportedly there is a MP3 library available for Teensy 3.1, however I find it easier to convert any MP3's to WAV using RazorLame on my PC.
Teensy 3.1 is Arduino compatible using the Teensyduino software from PJRC. This appears to include versions of all the Adafruit libraries, as well as the standard Arduino ones.
- Teensy 3.1 (pjrc.com)
- Teensy audio adapter (pjrc.com)
- ST7735 breakout board, 1.8" colour TFT 160*128 (adafruit.com, or ebay)
- Keyes rotary encoder (ebay), with knob to taste
- SPDT slider switch
- SPST switches: 1 tactile, 1 momentary pushbutton
- Micro-USB LiPo charger board (ebay)
- LiPo battery 1400 mAh (6mm thickness will fit in the box)
- Capacitors: 3 * 100nF, 1 * 270uF (optional)
- 0.1 socket strip (pjrc.com)
- Vero board (see pictures for size)
- micro-SD card
- Soldering iron
- Laser cutter
Step 1: Attach Teensy 3.1 to Audio Adapter
Solder header strips to Teensy 3.1 board as shown, then push the headers through the audio adapter. Check carefully that the pin labels correspond correctly, and then solder the necessary pins on the other side of the adapter. Note carefully the relative orientation of the two boards, with the Teensy upside down. If you connect the Teensy the other way up then many of its pins are inaccessible. Note also that a little space is left between the boards so that the Teensy's bootloader switch can be operated (with a small screwdriver). The micro-SD slot is visible here underneath the audio adapter.
The large electrolytic capacitor visible on the right is connected across the USB power supply. This is used to (mostly) suppress mains hum, which will occur if you power the player from USB and use an earthed amplifier. There is no problem if you use battery power, or use a headphone for the audio output. My capacitor is 270uF, but you can use anything that will fit in the available space (12V rating is sufficient).
Step 2: Mount the Audio Adapter and Encoder
Attach the audio adapter to the Vero board using 3mm nuts and bolts as shown. A cut-out is required to accommodate the headphone jack. Note that the soldered washer on the left side bolt was needed because I drilled the hole too close to the edge of the board -- you may not have this problem.
The rotary encoder breakout has 5 pins. Remove Vero board track from where the second and fourth pins will go, and attach the encoder breakout by soldering the first and fifth pins. The 100nF capacitors need to be connected between earth and the CLK and DT pins of the encoder. I also used a 100nF capacitor between its + and GND connections (visible in the next step), however this is probably not necessary.
Step 3: Power Connections
The battery charger board and power slider switch are mounted on top of the Vero board as shown. As described at http://pjrc.com/teensy/pinout.html, the trace between VIN and VUSB on the Teensy is cut. The power slider switch connects VIN to either VUSB or to the OUT+ pin of the battery charger. OUT- of the charger is connected to ground.
In order to prevent reverse connection I use a 3-pin battery connector (at lower right in previous picture) with a central (+) pin, and (-) pins either side. The corresponding female connector can be made from breadboard jumpers or recycled PC components. The battery connector should be connected to B+ and B- on the charger board, and NOT to anything else.
The display socket is cut to length from a socket strip. Note it is necessary to sacrifice one pin when you do this. Attempting to cut between the pins is futile.
The various ST7735 breakouts have variable pin orderings. At this point it is necessary to connect the 3.3V pin to the 3.3V output pin on the Teensy. Also connect this to the + pin of the rotary encoder.
Also connect the various earths together (Teensy, display, encoder and charger OUT-). Don't connect AGND or charger B- to earth! Ensure that all Vero board tracks are cut wherever there is an actual or potential short circuit.
The two SPST switches should be connected using flexible multi-strand wire and one side connected to earth. Note the tactile switch is used as a "Back" button and so needs to click, whereas the pushbutton is used as a "Shift" key. Note also I used a DPDT tactile switch since I had that available and they're all just as expensive.
Step 4: Logic Connections
The logic connections are point-to-point wired using whatever is convenient. I used wire-wrap wire, which is thin, is easily tinned and has high quality non-shrinking insulation. If you use this then you need a special tool to strip it, and you should avoid flexing existing connections in the vicinity of their solder joints, as they are liable to break off.
The display uses software SPI in order to avoid conflict with the SD card. Thus the connections can be chosen rather arbitrarily, as long as they aren't being used by the audio adapter. The following connections are compatible with the supplied software:
- SCLK or SCK = 5
- MOSI or SDA = 8
- CS or TFT_CS = 20
- DC or A0 = 21
- RESET = 17
- LITE or LED = 3 (must be PWM)
The rotary encoder connections are:
- SW = 28
- DATA = 27
- CLOCK = 26
And the SPST switch connections are (note other side is grounded):
- SHIFT (pushbutton) = 25
- BACK (tactile) = 24
Step 5: Boxing
The tasteful fluorescent box can be made from 3mm acrylic using the attached .dxf file. The .obj file is the original 3D model, in case you need to view or modify the design. I have custom software which converts directly from .obj to .dxf, but this is not currently distributed. So you will need a multistep process to perform such a modification.
Alternatively you can make your own box, in which case remember to provide access to the SD-card slot and the bootloader switch. The Teensy library does not write SD files, so you need to take the card out to add them with your PC.
If using my box, I suggest assembling it initially using paint masking tape rather than glue, so you can easily undo your "Ikea moment". The box is a very tight fit. When re-boxing, remove the SD card first, and note the slot at the back which allows the slider switch handle to be slid in. In the picture, arrow A points to a sheet of polycarbonate which protects the battery from solder protrusions, and arrow B points to a support for the rotary encoder board (the encoder has a built-in switch which is operated by pressing down on the encoder knob). The box is held closed by 2 small machine screws, and you will need to thread the holes the first time you insert them.
Step 6: Software
First copy some pleasing .wav files onto your micro-SD card and insert it. PJRC have some sample files which sound good despite their historic 8.3 filenames.
You need to download the Teensyduino software from PJRC. Then open aplayer.ino in Arduino and choose "Teensy 3.1" under tools. Switch the player to USB power and plug your mini-USB cable into the Teensy.
The supplied software extends the Teensyduino libraries in several ways:
- displays FAT32 long filenames
- reads .wav files with a more general header structure
- allows pausing
In order to make it compile and link, you need to make the original "play_sd_wav.cpp" file inaccessible. This is located at ...\Arduino\hardware\teensy\avr\libraries\Audio . I do this by changing the .cpp extension to .cpz . Also you will get an error about an inaccessible member in the SD card library. This is simply fixed by changing a "private" keyword to "public" in one of the .h files. I have no qualms about changing this globally, since it does not change the operation of the code in any way (but merely allows it to be subverted in ways the original authors didn't expect).
The software implements a nested menu system, with up/down being controlled by turning the encoder, "enter" by pressing down on the encoder, and "back" by clicking the tactile switch. The shift pushbutton is used to horizontally scroll the music filenames (in a specific menu).
The software purports to measure the battery voltage. Unfotunately it is measuring this on the downside of the Teensy's 3V3 regulator, so this is invalid. I need to add a pair of resistors to the Vero board in order to obtain a fraction of the battery voltage which is less than the 1V2 bandgap voltage of the Teensy.