Overview
All this functionality is implemented in a light-weight SPI interface so nearly any microcontroller can play audio from an SD card. There's also a special MIDI mode that you can boot the chip into that will read 'classic' 31250Kbaud MIDI data on a UART pin and act like a synth/drum machine - there are dozens of built-in drum and sample effects! But the chip is a pain to solder, and needs a lot of extras. That's why we spun up the best breakout, perfect for use with an Arduino but also good for other microcontrollers that just don't have the computational power to decode MP3s.
The breakout is slim enough to fit on a breadboard with 1 row of holes left over for wiring. There are 3.3v and 1.8v regulators onboard with ferrite beads and analog filtering for quality analog output. There's a microphone input port that you can wire up a line-in or mic to and record compressed audio. All 8 GPIO are broken out and they all have built in 100K pulldowns, simply connect your button from the GPIO pin to 3.3V for an active-high connection. You'll likely want to play music from a microSD card so we added a holder on-board. And since we know so many of our customers use 5V microcontrollers like the Arduino, we made the interface pins all 5V compliant with level shifters so you can use the chip at 3V or 5V power/logic!
The breakout board comes fully assembled and tested. All v1.0 boards come with two 100uF electrolytic capacitors for line-level output coupling, v2.0 have the capacitors integrated into the PCB. All kits come with some 0.1" male header you can solder to the breakout so it plugs into a breadboard and a bonus stereo headphone jack that will be handy when you want to plug headphones in!
Page last edited June 30, 2013
Text editor powered by tinymce.
Assembly
Assembly is the same for both v1 and v2 breakouts, even if the boards look a bit different!
Prepare the Headers
Cut the header strips to length if necessary and place the long-pins-down in the breadboard.Page last edited June 30, 2013
Text editor powered by tinymce.
Getting Started - VS1053 Software
To get started with the VS1053 breakout (any version) you will first need to download the Adafruit VS1053 Library:
Â
Open up the Arduino library manager:
Search for Adafruit_VS1053 library and install it
Page last edited June 30, 2013
Text editor powered by tinymce.
Simple Audio Player Wiring
These steps are identical for both v1 and v2 codec breakouts, even if the boards look a little bit different
Prepare the breadboard
Place the VS1053 breakout on the breadboard. Center it so that there is one row of holes on each side.Add the breakout friendly headphone jack and wire power and ground jumpers as shown.
-
VCC -> 5v
- GND -> GND
Connect SPI and Reset
Add jumpers for:-
CLK -> Arduino #13 (Mega 52)
-
MISO -> Arduino #12 (Mega 50)
-
MOSI -> Arduino #11 (Mega 51)
-
CS -> Arduino #10
-
RST -> Arduino #9
Connect the rest of the digital signals
Add more jumpers for:-
XDCS-> Arduino #8
-
SDCS -> Arduino #4
-
DREQ -> Arduino #3
Connect the Headphone Jack
This step will be a little bit different depending on which version you have. If your breakout is v2 and has the round silver capacitors, add jumpers for:-
AGND -> Center 'ground' Pin
-
LOUT -> Left Pin
- ROUT -> Right Pin
If your breakout is v1, the pins will be labeled
-
GBUF -> Center 'ground' Pin
-
LOUT -> Left Pin
- ROUT -> Right Pin
Load some MP3 files
Copy 2 MP3 files to a micro SD card and name them track001.mp3 and track002.mp3 (this is just for the test, you can re-name them later). Then install the card in the slot on the VS1053 breakout.
Simple Audio Player Sketch
Connect the Arduino to your computer with a USB cable and plug your headphones into the headphone jack. Select File->Examples->Adafruit_VS1053_Codec->player_simple to load the example code.You should hear your MP3 files in the headphones.
You can also run File->Examples->Adafruit_VS1053_Codec->player_interrupts. This example demonstrates playing files in the background using interrupts. This allows you to do other things in your sketch while the music plays!
With both examples, you can change the file names in the code to play different files - or even extend the code to search the SD card for files to play.
For the Micro:
Frank Cohen has submitted a wiring diagram for the FilePlayer example on a Micro. See his code posted here as well: http://votsh.files.wordpress.com/2014/02/vs1053-arduino-micro-connections.pdf
Note: Â For paying sounds in the background using interrupts, connect DREQ to pin 3 and change the code to match.
Page last edited June 30, 2013
Text editor powered by tinymce.
Audio Connections
For audio devices requiring a 'line level' input, use the included capacitors. These are polarized electrolytic capacitors, so it matters which way you connect them. Connect the positive (longer) leads to the LOUT and ROUT pins, and the negative leads to the L & R pins of the headphone jack or L and R inputs of the audio device. The common (center) pin of the audio jack should be connected to the AGND pin.
If you have a v2 breakout, these capacitors can be skipped, they are included onto the breakout board itself.
Page last edited June 30, 2013
Text editor powered by tinymce.
MIDI Connections
Prepare the breadboard
Place the VS1053 breakout on the breadboard. Center it so that there is one row of holes on each side.Add the breakout friendly headphone jack and wire power and ground jumpers as shown.
-
VCC -> 5v
-
GND -> GND
Configure for MIDI operation
Add jumpers as follows:-
GPIO-0 -> GND
-
GPIO-1 -> 3.3v
-
Rx -> Arduino Digital #2
-
RST -> Arduino Digital #9
Connect the Headphone Jack
Same as the earlier tests, add jumpers for:-
AGND (v2) or GBUF (v1) -> Center Pin
-
LOUT -> Left Pin
-
ROUT -> Right Pin
Midi Example Sketch
Connect the Arduino to your computer with a USB cable and plug your headphones into the headphone jack. Select File->Examples->Adafruit_VS1053_Codec->player_miditest to load the example code for MIDI operation.. You should hear a repeating series of ascending tones from the MIDI player.Page last edited June 30, 2013
Text editor powered by tinymce.
GPIO
Add some LEDs
Add a jumper from the ground bus on the left to the ground bus on the right of the breadboard.Then add some LEDs from the GPIO pins to ground. Be sure to connect the long lead (anode) to the GPOI pin and the short lead (cathode) to ground.
Run the player_gpiotest sketch
Connect the Arduino to your computer with a USB cable. Select File->Examples->Adafruit_VS1053->player_gpiotest to load the example code.If you have headphones, you will hear a beep at the start to indicate that the sketch is running. Then you should see the LEDs flashed in sequence.
If you open the Serial Monitor, you can see the values that are written to and read from each GPIO pin.
Page last edited June 30, 2013
Text editor powered by tinymce.
Ogg Recorder
Recording with the VS1053
The record_ogg example sketch turns your VS1053 breakout into a recording device that generates OGG encoded files on the SD card in real-time.
Wiring
Wiring for the record_ogg sketch is as follows:Power and Ground:
-
VCC -> 5v
-
GND -> GND
Basic SPI connections:
-
SCLK -> Arduino #13
-
MOSI -> Arduino #11
-
MISO -> Arduino #12
- CS -> Arduino #10
Additional Control Signals:
-
SDCS -> Arduino A0
- XDCS -> Arduino #8
-
RST -> Arduino #9
- DREQ -> Arduino A1
Start/Stop Button (Momentary):
- from Arduino #7 to GND
Electret Microphone Circuit:
The Microphone circuit is derived from the reference design shown in Figure 3 on Page 13 of the VS1053B Datasheet. Note that the ground connections shown are to analog ground (AGND).
A note about microphone circuits:
Microphones, by their nature, are very sensitive devices. They are prone to picking up all sorts of noises (both electrical and acoustic) in addition to what you are trying to record. A microphone circuit built on a breadboard is not likely to sound good at all. For good sound, you will want to review the spec sheet recommendations and build this on a good quality circuit board.Recording Sketch:
Connect the Arduino to your computer with a USB cable and plug your headphones into the headphone jack. Select File->Examples->Adafruit_VS1053_Codec->record_ogg to load the example code.Plug-Ins
The record_ogg example sketch demonstrates a powerful feature of the VS1053 breakout: Plug-ins. OGG recording capability is not supported natively in the chip itself, but through a plug-in code module. A binary file containing the code image of the plug-in is loaded from the SD card at startup. Once loaded, the VS1053 becomes an OGG recording device.To Record:
Press the start/stop button to start the recording. Press once again to stop. Each recording will be stored in a separate .OGG file on the SD card.To Playback:
Use any OGG capable audio player on your computer - or playback through the VS1053 using the Simple Audio Player configuration (see link at left).Page last edited June 30, 2013
Text editor powered by tinymce.
Library Reference
class Adafruit_VS1053_FilePlayer
The Adafruit_VS1053_FilePlayer class is derived from the Adafruit_VS1053 class and provides high level functions for playing files stored on the VS1053 breakout SC Card reader.Public Methods:
Adafruit_VS1053_FilePlayer (uint8_t mosi, uint8_t miso, uint8_t clk, uint8_t rst, uint8_t cs, uint8_t dcs, uint8_t dreq, uint8_t cardCS) - Software SPI constructor. Uses Software SPI, so you must specify all SPI pins.
Adafruit_VS1053_FilePlayer (uint8_t rst, uint8_t cs, uint8_t dcs, uint8_t dreq, uint8_t cardCS) - Hardware SPI constructor. Uses Hardware SPI and assumes the default SPI pins.
boolean begin(void) - Initialize communication and reset the chip.
boolean useInterrupt(uint8_t type) - Specifies the interrupt to use for interrupt-driven playback. Valid arguments are:
- VS1053_FILEPLAYER_TIMER0_INT
- VS1053_FILEPLAYER_PIN_INT
boolean startPlayingFile(char *trackname) - Begin playing the specified file from the SD card using interrupt-driven playback. This allows your program to perform other tasks as the file is playing.
boolean playFullFile(char *trackname) - Play the complete file. This function will not return until the playback is complete.
Public Member Variables:
File currentTrack - File currently being played
boolean playingMusic - True if playback in progress
class Adafruit_VS1053
The Adafruit_VS1053 class implements an interface to the basic VS1053 functionality. For more detail on the operation of the VS1053 chip, please refer to the documentation on the Downloads page (see the link to the left).public Methods:
Adafruit_VS1053(uint8_t mosi, uint8_t miso, uint8_t clk, uint8_t rst, uint8_t cs, uint8_t dcs, uint8_t dreq) - Software SPI constructor - must specify all pins.
Adafruit_VS1053(uint8_t rst, uint8_t cs, uint8_t dcs, uint8_t dreq) - Hardware SPI constructor - assumes hardware SPI pins.
uint8_t begin(void) - Initialize SPI communication and (hard) reset the chip.
void reset(void) - Performs a hard reset of the chip.
void softReset(void) - Attempts a soft reset of the chip.
uint16_t sciRead(uint8_t addr) - Reads from the specified register on the chip.
void sciWrite(uint8_t addr, uint16_t data) - Writes to the specified register on the chip.
void sineTest(uint8_t n, uint16_t ms) - Generate a sine-wave test signal.
void spiwrite(uint8_t d) - Low-level SPI write operation.
uint8_t spiread(void) - Low-level SPI read operation.
uint16_t decodeTime(void) - Reads the DECODETIME register from the chip.
void setVolume(uint8_t left, uint8_t right) - Set the output volume for the chip.
void dumpRegs(void) - Prints the contents of the MODE, STATUS, CLOCKF and VOLUME registers.
void playData(uint8_t *buffer, uint8_t buffsiz) - Decode and play the contents of the supplied buffer.
boolean readyForData(void) - Test if ready for more data.
void applyPatch(const uint16_t *patch, uint16_t patchsize) - Apply a code patch (See datasheet for details).
uint16_t loadPlugin(char *fn) - Load the specified plug-in.
void GPIO_digitalWrite(uint8_t i, uint8_t val) - Write to a GPIO pin.
void GPIO_digitalWrite(uint8_t i) - Write to all 8 GPIO pins at once.
uint16_t GPIO_digitalRead(void) - Read all 8 GPIO pins at once.
boolean GPIO_digitalRead(uint8_t i) - Read a single GPIO pin.
void GPIO_pinMode(uint8_t i, uint8_t dir) - Set the Pin Mode (INPUT/OUTPUT) for a GPIO pin.
boolean prepareRecordOgg(char *plugin) - Initialize chip for OGG recording.
void startRecordOgg(boolean mic) - Start recording (mic = true for microphone input).
void stopRecordOgg(void) - Stop the recording.
uint16_t recordedWordsWaiting(void) - Returns the number of words recorded.
uint16_t recordedReadWord(void) - Reads the next word from the buffer of recorded words.
uint16_t recordedReadWord(void) - Reads the next word from the buffer of recorded words.
Page last edited June 30, 2013
Text editor powered by tinymce.
Downloads and Links
Library:
Files:
- VS1053B (Codec chip) datasheet
- Details about the Ogg vorbis encoder/recorder
- App note on connecting to analog outputs!
- Fritzing object in Adafruit Fritzing Library
- EagleCAD PCB files on GitHub
Schematic & Fabrication Print
Page last edited June 30, 2013
Text editor powered by tinymce.