Adafruit's Kattni Rembor Shows How Easy It Is to Play MP3s on a Raspberry Pi Pico via CircuitPython

Three-component project only needs a Raspberry Pi Pico or other RP2040-based board, an amplifier, and a speaker.

Gareth Halfacree
2 months agoMusic / Python on Hardware

The Raspberry Pi RP2040, its first microcontroller and the first major design from its in-house application-specific integrated circuit (ASIC) team, has found its way into an amazingly wide variety of projects — and now Adafruit wants to show you how to put it at the heart of a simple MP3 player.

"Compressed audio can be a nice alternative to uncompressed WAV files," writes Kattni Rembor of the thinking behind a project which eschews the usual method of putting audio files onto a microcontroller, "especially when you have a small filesystem like that on many CircuitPython boards, as WAV files get sizeable quite quickly. You can listen to a much longer playlist with CircuitPython, using the built in MP3 playback capability!"

Rembor's project requires only three components: A Raspberry Pi Pico or other board based around the RP2040 microcontroller; an amplifier, with Adafruit's own PAM8302 breakout being picked as the perfect choice; and a speaker.

"Mono and stereo files less than 64kbit/s work," Rembor writes, "with sample rates from 8kHz to 24kHz. The RP2040 has a PWM output with 10 bits, so there's not much point in using high bit rates. Be aware, doing things like updating a display, or having intense flash activity like reading and writing files can result in distorted sounds or noise during playback."

The software takes up only a few lines of CircuitPython, using the language's built-in MP3 decoding and playback libraries to drive one of the RP2040's pulse-width modulation (PWM) capable pins — sending the decoded audio to the amplifier, which then boosts it so you can hear it through the speaker.

The full guide, along with one customised for use with the RP2040-based Adafruit MacroPad, is now available on the Adafruit learning portal.

Gareth Halfacree
Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire: freelance@halfacree.co.uk.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles