Play MP3 File on Maker Pi Pico Using CircuitPython

Play MP3 file on Maker Pi Pico using CircuitPython

Introduction

CircuitPython has released a stable version for the Raspberry Pi Pico which is version 6.2.0. The latest firmware has a built-in library for audiomp3. So for this tutorial, I would like to play MP3 files using Maker Pi Pico. Ok let’s try!

Video

This video shows how to play MP3 files on Raspberry Pi Pico / Maker Pi Pico.

Hardware Preparation

This is the list of items used in the video.

Sample Program

This is CircuitPython sample code to play MP3 file on GP18 when button GP20 is pressed. Please replace with your MP3 file name and duration. Refer to the video for more detail.

import time
import board
import digitalio
from audiomp3 import MP3Decoder
try:
from audioio import AudioOut
except ImportError:
try:
from audiopwmio import PWMAudioOut as AudioOut
except ImportError:
pass # not always supported by every board!
button1 = digitalio.DigitalInOut(board.GP20)
button1.switch_to_input(pull=digitalio.Pull.UP)
# Replace with your mp3files name
mp3files = ["Selamat.mp3"]
# You have to specify some mp3 file when creating the decoder
mp3 = open(mp3files[0], "rb")
decoder = MP3Decoder(mp3)
audio = AudioOut(board.GP18)
while True:
if not button1.value:
decoder.file = open(mp3files[0], "rb")
audio.play(decoder)
print("playing", mp3files[0])
t = time.monotonic()
while time.monotonic() t < 3:
pass

view raw
code.py
hosted with ❤ by GitHub

Thank You

References:

Thanks for reading this tutorial. If you have any technical inquiries, please post at Cytron Technical Forum.

Please be reminded, this tutorial is prepared for you to try and learn.
You are encouraged to improve the code for better application.

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

DIY Digital Alarm Clock Using REKA:BIT With Micro:bit
Display Internet Time (NTP) on micro:bit
DIY Interactive Robot Using REKA:BIT With Micro:bit
BLTouch Installation for Ender 3 with 32-bit V4.2.2 Board
Pick and Send Random Meal’s Option and Locations through Telegram Bot Using Grove WiFi 8266 on micro:bit
Tutorials of Cytron Technologies Scroll to Top