vs1053_avr_renesas_uno 0.1.0
Arduino Library for VS1053 shield
Loading...
Searching...
No Matches
VS1053 Library for Arduino AVR and UNO R4

Support me on Ko-fi

Copyright © 2025 Kaled Souky. All rights reserved.

This project is licensed under the terms of the GNU General Public License v3.
You can find the full license text in the LICENSE.txt file included in this repository.

For more details, visit the official GNU General Public License website.


Introduction

Developed by Kaled Souky in 2025, the vs1053_avr_renesas_uno library is an Arduino port of the vs1053_SdFat library, originally created by Michael P. Flaga in 2012.

The vs1053_avr_renesas_uno library is a real-time, non-blocking, interrupt-driven library designed for VLSI’s VS10xx series (specifically, the VS1053). It uses the SPI bus for controller/peripheral communication, where the microcontroller on the Arduino board (or compatible) acts as the main processor (controller) and the VS1053 as a coprocessor (peripheral), responsible for decoding and playing audio files in formats such as Ogg Vorbis, MP3, AAC, WMA, FLAC, WAV, and MIDI.

Note
Controller/peripheral is formerly known as master/slave. Arduino no longer supports the use of this terminology.

This new version

  • Fully compatible with Arduino IDE 1 and IDE 2.
  • Includes the original examples (buttonplayer, demo, fileplayer, and webplayer) from the previous library, updated and fully functional. Additionally, two new examples—portable_mp3_player and portable_mp3_player_UNO_R4—have been added to demonstrate the creation of a complete portable MP3 player, featuring control buttons and an OLED display for visual feedback. These examples also include a dedicated wiring diagram to guide the hardware setup.
  • In addition to being compatible with AVR-based hardware, such as Arduino UNO R3 (ATmega328P), Arduino Mega R3 (ATmega2560), Arduino Leonardo (ATmega32u4), and similar boards, it is also compatible with the new Arduino UNO R4 Minima, Arduino UNO R4 WiFi and Nano R4, which incorporate the powerful 32-bit microcontroller Renesas RA4M1 ARM Cortex-M4.
  • For audio decoding and playback, this library supports the SparkFun MP3 Player Shield, along with other VS1053-based MP3 player shields, such as the Seeeduino Music Shield and the Gravitech MP3-4NANO Shield, among others.

Library Benefit Keys

Harnessing the Power of the New Arduino UNO R4

The Arduino UNO R4 introduces a significant leap in processing power, speed, and memory. With its ARM Cortex-M4 architecture, 48 MHz clock speed, 32 kB of SRAM, and 256 kB of flash memory, this board delivers a substantial improvement in SPI controller/peripheral communication speed, enabling smoother and more efficient interaction with peripherals.

This is particularly important because the Renesas RA4M1 ARM Cortex-M4 microcontroller acts as the main processor (controller), managing the core logic of the program, while the VS1053 chip functions as a coprocessor (peripheral) dedicated to audio decoding and playback.

These advancements unlock new possibilities in project development, such as:

  • The creation of advanced graphical interfaces on OLED screens, featuring dynamic animations (e.g., a cassette with spinning reels during music playback) and interactive visual effects linked to physical controls, greatly enhances the user experience.
  • Higher SPI bus speeds, which improve the efficiency of data transfer between the Arduino, the VS1053 chip, and the SD card. This is especially critical because every byte transmitted to the VS1053 must also be read from the SD card via the same shared SPI bus. Higher SPI speeds reduce overhead and enhance performance, particularly with high-bitrate audio files.
  • The ability to implement more ambitious and functional web servers.
  • Faster response times for physical controls, smoother transitions between audio tracks, real-time information updates on the display, and much more.
Note
In summary, the integration of the Renesas RA4M1 ARM Cortex-M4 microcontroller into the Arduino UNO R4 enables a level of project complexity that was previously difficult to achieve with earlier generations. For more details, refer to the RA4M1 datasheet.

The Quality, Power, and Longevity of the VS1053 Chip

The VS1053 chip, featured in the SparkFun MP3 player shield or other compatible MP3 player shields, is widely regarded as an excellent choice for audio decoding and playback. It delivers exceptional performance, particularly when compared to alternatives such as the YX5200-24SS chip used in the DFPlayer Mini MP3 player or the MY1690X chip found in other modules. What sets the VS1053 apart are its superior features, including:

  • The ability to decode multiple audio formats, such as Ogg Vorbis, MP3, AAC, WMA, FLAC, WAV, and MIDI.
  • Outstanding audio playback quality, enabled by its advanced DSP core and integrated stereo DAC.
  • High-quality components, including a stereo headphone driver capable of handling loads up to 30 Ω, along with excellent noise protection.
  • Advanced features, such as spatial processing (EarSpeaker), stereo/mono mode control, bass and treble adjustments, precise volume control, silent power-on and power-off, among others.
Note
Thanks to these features and its extensive range of functions for flexible parameter control in code development, the VS1053 empowers developers to create ambitious and highly customized programs, significantly enhancing the quality and functionality of projects. For more details, refer to the VS1053 datasheet.

Software Details

  • This library primarily relies on the SdFat library (for efficient SD card access), SPI (for controller/peripheral communication), among others. Thanks to its integration, it offers robust functionality that is reflected in the provided examples and can be leveraged in any developed project.
  • For projects that involve momentary push button switches, such as the buttonplayer and portable MP3 player examples, the Bounce2 library eliminates switch bounce, improving stability in pulse detection.
  • When network connectivity is needed, as in the webplayer example included in this library, the Ethernet library provides compatibility with Arduino Ethernet Shield, Ethernet Shield Rev2, and other W5100 or W5500-based Ethernet shields, as long as they maintain the same form factor, pin configuration, and operating voltage.
  • Additionally, for graphical interface applications, the U8g2 library offers compatibility with a wide range of display controllers, enabling the use of various monochrome OLED and LCD screens. One example is the popular 0.96 OLED display with an I²C interface (featuring the SSD1306 or SSD1315 chips), utilized in the portable MP3 player examples of this library
  • Optionally, if hardware interrupts are not supported, the SimpleTimer and TimerOne libraries can be used.

8.3 Short Filename Format for SdFat

The SdFat library enforces a slightly restricted format for short filenames, following the legacy 8.3 naming convention inherited from DOS and the FAT file system. This means filenames are limited to 8 characters, followed by a dot (.), and an extension of up to 3 characters. This constraint is integral to the FAT directory structure, where each entry has a fixed size, optimizing both access speed and memory usage. By adhering to this format, file location calculations become more efficient, reducing fragmentation and lowering CPU load during file system operations. For example, you can name your files track001.mp3, track002.mp3, track003.mp3, ..., but not MyMusicPlaylist.mp3, as it exceeds the character limit. Maintaining this structure ensures compatibility with FAT-based storage systems and enhances performance in resource-constrained environments, such as embedded systems.

Note
Make sure your SD card is formatted in FAT16 or FAT32 before using it, as these file systems optimize short filename management due to their directory structure. The SdFat library provides the SdFormatter example, a tool designed to properly format SD cards in FAT16 or FAT32. You can use other formatting applications or tools, as long as they adhere to the appropriate specifications for SD cards. They must ensure proper sector alignment, preserve the FAT16 or FAT32 structure without improper modifications, and optimize read/write performance. SdFormatter follows the SD Association's guidelines, ensuring a properly formatted SD card for optimal performance.

Plugins and Patches

The VS10xx chips are DSPs that run firmware from an internal ROM. Additionally, the VSdsp's RAM can also be loaded with external firmware (known as patches or plugins) and executed via the SPI port. This allows the VSdsp to troubleshoot factory ROM firmware or add new features available on the VLSI website. It's even possible to write custom VSdsp code using its Integrated Development Tools (VSIDE).

vs_plg_to_bin.pl is a perl script, that is provided in this library to run on your PC, to read and digest the .plg files converting them to raw binary as to be read by vs1053::VSLoadUserCode() from the SD card. Allowing updates to the VSDsp into its volatile memory after each reset. These updates may be custom features or accumulated patches.

By storing them on the SdCard these plug-ins do not consume the Arduino's limited Flash spaces.

Below are pre-compiled binary's of corresponding provided VSLI patches/plugins. Filenames are kept short since the SD card supports only the 8.3 naming convention.

VS1053b Plugins:

Zip Folder PLG File Binary File
vs1053-pcm140b.zip vs1053pcm.plg pcm.053
vs1053b-admix130.zip admix-left.plg
admix-mono.plg
admix-right.plg
admix-stereo.plg
admix-swap.plg
admxleft.053
admxmono.053
admxrght.053
admxster.053
admxswap.053
vs1053b-eq5-100.zip vs1053b-eq5.plg eq5.053
pitchshifter131.zip pitchshifter131/code/ps1053b.plg pshift.053


VS1053b Patches:

Zip Folder PLG File Binary File
vs1053b-patches290.zip vs1053b-patches-flac.plg
vs1053b-patches.plg
vs1053b-patches-latm.plg
vs1053b-patches-flac-latm.plg
vs1053b-patches-dsd.plg
patchesf.053
patches.053
patchesl.053
patchefl.053
patchesd.053
vs1053b-rtmidistart.zip rtmidistart.plg rtmidi.053


Note
The required precompiled plugins and patches are located in the plugins_and_patches folder and must be placed in the root directory of the SD card to function correctly. The cumulative update patches.053, which resolves numerous known issues, is applied during the vs1053::vs_init initialization routine. VLSI periodically publishes updates on its software support page. To compile .plg files and generate your own binaries, use the vs_plg_to_bin.pl script included in the same folder. Example usage:
 Linux: perl vs_plg_to_bin.pl vs1053pcm.plg pcm.053
 Windows: vs_plg_to_bin.pl .\vs1053pcm.plg .\pcm.053
 
Perl is available natively on Linux and can be downloaded for Windows from ActivePerl.
See also
About Analog to Digital Mixer (e.g. admx____.053) please note Limitations of the VS1053 as an SPI Peripheral.

Hardware Details

Arduino UNO R4 Full Compatibility

The Arduino UNO R4 Minima and UNO R4 WiFi maintain the same form factor, pin layout, and 5V operating voltage as their predecessor, the UNO R3. This ensures full compatibility with the SparkFun MP3 Player Shield and the vs1053_avr_renesas_uno library, eliminating any risk of incompatibility or damage to the components.

Although the Arduino Nano R4 has a different physical format, it shares the same pin assignment, and 5V operating voltage as the Arduino UNO R4 Minima and WiFi. Therefore, the same pin numbering can be used to connect to the MP3 Player Shield via jumper wires.

Note
For more information, refer to the Arduino UNO R4 Minima, UNO R4 WiFi or Nano R4 cheat sheets, available on the official Arduino website.

Arduino Mega and Leonardo SPI Pin Connections

The Arduino Mega and Leonardo compatibility requires additional jumpers. Since the SPI pins are not located at the same positions as on the Arduino UNO R3 or UNO R4, when using a Mega or Leonardo with a SparkFun MP3 Player Shield or other compatible MP3 Player Shields.

Note
The acronyms MISO (Master In Slave Out), MOSI (Master Out Slave In), and SCLK (Serial Clock) are no longer used by Arduino. Instead, CIPO (Controller In Peripheral Out), COPI (Controller Out Peripheral In), and SCK (Serial Clock) are used. The legacy acronyms are shown for reference.

The following pins must be connected.

Arduino Mega SPI Pin Connections:

Mega Pin Conexión MP3 Player Pin
D51 (MOSI/COPI) ────► D11 (MOSI/COPI)
D50 (MISO/CIPO) ────► D12 (MISO/CIPO)
D52 (SCLK/SCK) ────► D13 (SCLK/SCK)


Arduino Mega R3 wiring


Note
For more information, consult the Mega pinout.

Arduino Leonardo SPI Pin Connections:

Leonardo ICSP Conexión MP3 Player Pin
ICSP4 (MOSI/COPI) ────► D11 (MOSI/COPI)
ICSP1 (MISO/CIPO) ────► D12 (MISO/CIPO)
ICSP3 (SCLK/SCK) ────► D13 (SCLK/SCK)


Arduino Leonardo wiring


Note
For more information, consult the Leonardo pinout.
Warning
Ensure correct jumper connections to avoid communication issues. The remaining connections remain unchanged.

Limitations of Arduino boards based on the AVR architecture

  • The portable_mp3_player_UNO_R4 example is compatible with the Arduino UNO R4 (Minima, WiFi, and Nano). It is not compatible with Arduino boards based on the AVR architecture (e.g., UNO R3, Mega R3, Nano, Leonardo, Micro) due to limited memory and processing power. In the case of the Arduino Mega R3, although it has sufficient memory, its limited CPU cannot establish ISP communication with the VS1053 and the SD card while simultaneously rendering the cassette animation and updating all information on the OLED via I²C.
  • Although the ATmega32U4 has the same Flash memory as the ATmega328P in the Arduino UNO R3 (32 KB), the Leonardo lacks a separate USB coprocessor like the ATmega16U2 in the UNO R3. Instead, it manages USB directly, requiring 4 KB for the bootloader and communication functions, leaving insufficient memory space for the webplayer example. This limitation also applies to other ATmega32U4-based boards, such as the Teensy 2.0 and the conductive touch board (BARETOUCH).
  • When using the portable_mp3_player example, I²C communication must be handled via the microcontroller’s dedicated hardware to control the OLED display. On the Arduino Leonardo, the only available I²C port corresponds to pins D2 (SDA) and D3 (SCL), which conflicts with the SparkFun MP3 Player Shield. This is because the MP3-DREQ pin of the VS1053 chip—responsible for indicating when the audio chip is ready to receive more data—is connected to pin D2.

    This conflict prevents the use of interrupts or software polling to detect the MP3-DREQ status. Implementing software I²C is not recommended due to the low refresh rate of the display, which would negatively affect the fluidity of the OLED interface.

    To use the Leonardo board with the SparkFun MP3 Player Shield in these cases, jumpers must be used and the pin assignments reconfigured in the vs1053_avr_renesas_uno_config.h file, ensuring that pins D2 (SDA) and D3 (SCL) are reserved exclusively for the OLED display.

Note
In cases where the pin assignment and operating voltage remain the same (e.g., Arduino Nano), jumpers can be used to connect to the SparkFun MP3 Player Shield or equivalent. If the pin assignment differs from the Arduino UNO standard, both jumpers and the configuration file vs1053_avr_renesas_uno_config.h must be adjusted accordingly.

Teensy 2.0 Board

Support for Teensy 2.0 board please see TEENSY2

SparkFun MP3 Player Shield

The SparkFun MP3 Player Shield should work seamlessly out of the box with an Arduino UNO R3 (or compatible), as well as the UNO R4 Minima and UNO R4 WiFi.

Seeeduino Music Shield

Support for Seeeduino Music Shield please see SEEEDUINO and may require additional libraries, as per Requirements

MP3-4NANO Shield

Support for Gravitech MP3-4NANO shield please see GRAVITECH

OLED Display

For the portable MP3 player examples, the popular 0.96 OLED display with an I²C interface (featuring the SSD1306 or SSD1315 chip) is used. Although the SSD1315 chip is not explicitly listed among the types defined in the OLED display configuration constructor of the U8g2 library, it is fully compatible with the SSD1306 type.

After experimental testing, some cases of incompatibility were identified. One such case involves the display Grove - OLED Display 0.96 (SSD1315) I²C Interface Compatible with Arduino.

While this display is fully compatible with the dedicated I²C hardware of the Arduino UNO R4, it does not work directly with AVR-based Arduino boards. To use the U8g2 library in these cases, 1 kΩ pull-up resistors must be added to the SCL and SDA pins. This allows the HW_I2C constructor to initialize the communication protocol using dedicated I²C hardware, enabling high communication speeds.

Note
The use of Software-emulated I²C/TWI, available through the SW_I2C constructor in the U8g2 library, is not recommended. Emulating I²C via software consumes valuable CPU cycles to manage communication, rather than leveraging dedicated hardware. This approach is less efficient, reduces communication speed, and negatively impacts the fluidity of display handling.

Limitations of the VS1053 as an SPI Peripheral.

  • SPI Bus: The VS1053 chip is configured as a peripheral on the SPI bus, along with the SD card, sharing the same master bus hosted by Arduino. See the Performance section for more details.
  • Non-Blocking: The library operates in a non-blocking manner, allowing the main program to continue executing other tasks while playing an audio file. To check if playback has finished, use vs1053::isPlaying. This approach enables audio playback from the SD card using playTrack or playMP3, while maintaining real-time execution flow without interruptions.
  • Multi-Chip VS10xx support: Currently unavailable. There are too many issues with member functions of the vs1053 class requiring to be static.
  • Audio Input: Most commercially available shields do not support line-level or microphone input. Exceptions such as the Seeeduino Music Shield and other custom shields do allow input. For these devices, vs1053::ADMixerLoad and vs1053::ADMixerVol are provided to enable the input mixer. In other cases, the example demo has these lines commented out in setup(). To activate them, simply uncomment the lines.
  • Recording: Since most commercial shields do not support audio input, the recording feature has not been implemented in the library. However, its integration is under evaluation for future versions.
Todo
Support Audio Recording.

Performance

Since each byte transmitted to the VS1053 must also be read from the SD card via the shared SPI bus, the bus efficiency is reduced to less than half, introducing overhead. This overhead can significantly constrain real-time availability, particularly when dealing with high-bitrate audio files. Additionally, features like the Playback Speed Multiplier can rapidly consume available processing time.

Most Arduino boards based on 8-bit AVR microcontrollers operate at a clock frequency of 16 MHz, while the Arduino Uno R4 Minima and R4 WiFi boards, based on the 32-bit Renesas RA4M1 ARM architecture, run at 48 MHz.

In SPI communication, the data transfer speed is determined by the architecture of both the controller and the peripheral, as well as the clock frequency at which they operate. In this case, the VS1053, a DSP specialized in audio processing, uses a 12.288 MHz crystal, allowing stable maximum speeds of 4 MHz when used with 16 MHz AVR microcontrollers, and 7.9 MHz in the case of the 48 MHz Renesas RA4M1.

This makes it possible to have sufficient real-time execution for properly handling SD card reading tasks and transmitting high-bitrate data to the VS1053, as well as performing other demanding tasks like the playback speed multiplication function, without imposing an overhead on the CPU.

Although the Arduino Uno R3, with its 16,000,000 MIPS and an optimal SPI communication speed, is capable of handling these tasks well, the new Arduino Uno R4, with 48,000,000 MIPS and a higher SPI communication speed, stands out in this aspect. Its greater number of available CPU cycles allows it to execute more tasks with ease, dedicating its 32-bit computing capacity to the execution of the required operations without overloading the CPU. This enables it to handle audio files with a higher bitrate, which translates to superior performance and greater efficiency.

The actual CPU usage can be measured by defining PERF_MON_PIN on a valid pin, which generates a low signal on the configured pin when servicing the VSdsp. This includes SD card reads.

Note
Thanks to the SdFat library, the SD card read and write speed can be individually set using the SPI_HALF_SPEED and SPI_FULL_SPEED macros in the sd.begin() argument. This contributes to flexibility in using SD cards available on the market, which may perform better at one speed or another, while also optimizing real-time execution efficiency.
Warning
using non-compatible hardware is not recommended, as it may lead to incompatibility issues or potential damage to components.

Troubleshooting

The below is a list of basic questions to ask when attempting to determine the problem.

  • Did the Serial Monitor initially PRINT the available RAM and full help menu?
    • The demo and fileplayer examples in the vs1053_avr_renesas_uno library should initially provide an opening print indicating the amount of available SRAM and full menu help. If this output does not appear, the issue likely stems from communication between your target board and the IDE, rather than from this library.
    • Is the Serial Monitor set to the correct tty or COM port and 115200 baud rate? Did you change the baud rate?
    • After opening the Serial Monitor, reset the Arduino or send any key—it may have printed the information before the Serial Monitor started.
  • WHAT error is reported?
  • Did the SD card LOAD?
    • Try reseating your SD card.
  • Is MP3player.begin() locking up in setup()?
  • Are you trying to update from a version of Arduino IDE 1 earlier than 1.01.00?
  • Why does my Serial Monitor display: "...do not have a sd.begin in the main sketch, See Trouble Shooting Guide."
  • Compiler Error: "...undefined reference to `sd'"
  • Is the last thing printed to the Serial Monitor: "Free RAM = 978" then nothing...
    • Versions of Arduino IDE 1 later than 1.01.00, as well as IDE 2, require SdFat::begin() to be initialized in the setup() function of sketch, as shown in the following example. This allows more immediate access to SD card files from the main sketch. However, if this initialization is not performed, it won't trigger an immediate compilation error, but the sketch will freeze when vs1053::begin() is called.
...
SdFat sd; // required in Arduino IDE 1.01.00 and later, as well as in IDE 2.
void setup() {
if(!sd.begin(SD_SEL, SPI_HALF_SPEED)) sd.initErrorHalt(); // required in Arduino IDE 1.01.00 and later, as well as in IDE 2.
if(MP3player.begin() != 0) {Serial.print(F("ERROR"));
...
SdFat sd
SdFat sd;.
#define SD_SEL
A macro to configure the SdCard Chip Select for vs1053_avr_renesas_uno library.
  • Is the SD card formatted as FAT (FAT16 or FAT32)?
    • If the error code indicates problems with initialization, volume access, or track playback failure, it is recommended to use the QuickStart example from the SdFat library to verify whether the card is accessible. Additionally, SdInfo, another example from the SdFat library, can indicate whether the card can be mounted. If formatting is required, FAT16 or FAT32 should be used, and SdFormatter—also part of the SdFat library—can handle this process for you.
  • Are the required files on the root directory?
  • "Error code: 1 when trying to play track"
  • "Warning: patch file not found, skipping."
    • Refer to Plug_Ins for additional information.
  • Why do I only hear 1 second of music, or less?
    • This symptom is typically caused by the interrupt not triggering vs1053::refill(). Repeatedly sending a track number will likely advance playback by about one second at a time before stopping.
    • What board are you using? Check the Hardware Details related to interrupts.
    • Are you using the test files ? provided for the SparkFun MP3 Player Shield or homemade MP3 files? The SparkFun MP3 Player Shield test files are useful because they start at a high volume.
    • Interrupt issues may cause MP3 files with a quiet lead-in (or gradual volume ramp-up) to be falsely diagnosed as not playing at all. If the first second is too quiet, it may not be audible.
  • "Free RAM = 978"
    • As a best practice, the demo and fileplayer examples display the remaining available RAM rather than the statically allocated amount, as actual availability depends on factors such as the processor, IDE version, and libraries used. On an Arduino Uno R3 compiled with IDE version 2.3.5, the demo example should show approximately 978 bytes of free RAM, while fileplayer would reduce that figure to 832 bytes. Meanwhile, on an Uno R4, which has greater RAM capacity, demo should reflect around 26,412 bytes available and fileplayer close to 26,404 bytes.
Note
This library makes extensive use of SdFat Library as to retrieve the stream of audio data from the SD card. Notably this is where most failures occur. Some SD card types and manufacturers may not be supported by SdFat. Though SdFat Lib is at this time, supporting most known cards.

Error Codes

Error codes are typically returned by this library's objects in place of Serial.print messages to both conserve flash memory and accommodate situations where serial devices may not always be present. It is the responsibility of the calling sketch to appropriately handle these codes or display corresponding messages.

begin function:

The following error codes are returned by the vs1053::begin() member function.

 0 OK
 1 *Failure of SdFat to initialize physical contact with the SdCard
 2 *Failure of SdFat to start the SdCard's volume
 3 *Failure of SdFat to mount the root directory on the volume of the SdCard
 4 Other than default values were found in the SCI_MODE register.
 5 SCI_CLOCKF did not read back and verify the configured value.
 6 Patch was not loaded successfully. This may result in playTrack errors
 
Deprecated
Error codes 1,2,3 due to use of sd.begin() as global, starting version 1.1.0

Playing functions:

The following error codes return from the vs1053::playTrack() or vs1053::playMP3() member functions.

 0 OK
 1 Already playing track
 2 File not found
 3 indicates that the VSdsp is in reset.
 

Skip function:

The following error codes return from the vs1053::skipTo() member function.

 0 OK
 1 Not Playing track
 2 Failed to skip to new file location
 

Library installation

The vs1053_avr_renesas_uno library is not included in the standard Arduino distribution. To use it, you need to clone or download it from this repository and install it manually.

There are two methods to install the library:

  • Importing a ZIP library: Download the library as a ZIP file and import it directly into the Arduino IDE.
  • Manual installation: Clone or extract the library into the libraries folder of your Arduino IDE installation.
Note
Both methods are described in detail in the Installing Libraries tutorial available on the official Arduino website.
Support me on Ko-fi