This example will use the Teensy 3.6 and will read an MP3 file off of an SD card and play it back through the onboard 2-channel DAC. The audio output goes through an impedance matching series resistor and an RC low pass filter to remove the DC offset.
Wiring
- DAC0- connect DAC0 on the teensy to the positive (longer) lead of a 10uF electrolytic capacitor through a 68ohm resistor. The resistor value isn't critical, try to pick something in the 47 - 100 ohm range. Connect the negative (shorter) lead of the electrolytic capacitor to the left lead of the headphone jack. Connect a 10k resistor from the left lead of the headphone jack to AGND on the teensy.
- DAC1 - connect DAC1 on the teensy to the positive (longer) lead of a 10uF electrolytic capacitor through a 68ohm resistor. Again, the resistor value isn't critical, try to pick something in the 47 - 100 ohm range. Connect the negative (shorter) lead of the electrolytic capacitor to the right lead of the headphone jack. Connect a 10k resistor from the right lead of the headphone jack to AGND on the teensy.
- Connect the ground (center) pin on the headphone jack to AGND on the teensy.
Loading the SD card
Rename your MP3 file test.mp3 and load it onto a standard formatted microSD card.
Insert the microSD card into the SD slot on the teensy.
Download the Library
To begin playing files, you will need to download Adafruit_MP3 from the Arduino library manager.
Open up the Arduino library manager:
Search for the Adafruit_MP3 library and install it
We also have a great tutorial on Arduino library installation at:
http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use
Load Play from SD example
Open File->Examples->Adafruit_MP3->play_from_SD and upload to your Teensy. Open up the serial console and make sure it is able to read the SD card.
You should hear the file play through whatever is plugged into the 3.5mm jack.
Adjusting the Volume
The DAC on the Teensy and Feather/Metro M4 has 12 bit resolution. This means the output can have 4096 different values ranging from 0 (ground) to 4095 (3.3V). In this simple example we can raise or lower the volume by changing the mapping of the value that is written to the DAC.
Change VOLUME_MAX in the sketch to a desired value between 0 (inaudible) and 4095 (very loud).
Text editor powered by tinymce.