element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Blog Pocket Scarface – Pi Pico Python Based MP3 Clip Player
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
GPIO Pinout
Raspberry Pi Wishlist
Comparison Chart
Quiz
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: shabaz
  • Date Created: 27 Oct 2021 12:23 AM Date Created
  • Views 13652 views
  • Likes 3 likes
  • Comments 6 comments
Related
Recommended
  • i2s audio
  • max98357
  • raspberry pi pico
  • max98357 i2s
  • game
  • i2s
  • mp3
  • mp3 player
  • pi pico

Pocket Scarface – Pi Pico Python Based MP3 Clip Player

shabaz
shabaz
27 Oct 2021

  • Introduction
  • Circuit
  • Building It
  • Parts List
  • Code
  • Uploading the Code to the Pi Pico
  • Summary

 

Introduction

There is a kids' toy that is a pocket-sized voice/effects box. It has half a dozen buttons on the front, and whenever any button is pressed, a burst of audio is played. Such toys are cheap when released, but eventually can sell for quite a lot on ebay! I wanted to build something similar, i.e. from a birds-eye view there is nothing very original for this project, the end result is an open-sourced rip-off of the commercial products : ) See the two-minute video below for a demonstration.

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Unlike the commercial toy, this project uses the Python programming language running on a Pi Pico board. It allows for kids to be able to customize the unit and to be able to easily upload their own audio files for their favorite movies/shows (for instance).

 

The project uses CircuitPython's MP3 playing capabilities as discussed here: MP3 Playback on PI Pico. This project is similar to that, the only slight difference is that instead of using pulse width modulation (PWM) for generating the final output for the audio amplifier, this project instead uses a separate digital to analog converter (DAC), in the audio world it is known as an I2S DAC. The audio quality can hopefully be better than the commercial toy. As a result, although this project does not have hi-fi quality, it should be way better than typical kids' toys. I used MP3 files recorded from a movie, but they could be replaced with sounds from favorite kids' animations for example or musical effects. There is not a lot of memory, but several minutes of audio is feasible (perhaps more with different MP3 settings - I used the following settings: 64 kbps, 44.1 kHz, mono).

 

image

 

This project uses large components and is easy to solder. It shouldn't take more than half an hour to assemble it if built on the printed circuit board (PCB).

image

 

Circuit

The circuit below (click it to enlarge) consists of up to 10 push-buttons connected to the Pi Pico directly, and the digital audio output from the Pi Pico goes into a ready-made (available from Adafruit and resellers) MAX98357 board. The power source for the project can be a 9V battery; the voltage is reduced using a ready-made 5V DC-DC converter5V DC-DC converter which is pin-compatible with the traditional linear 7805 regulatorslinear 7805 regulators; either can be used with this project. The circuit shows two slide switches, SW10 SW10 and SW11SW11. Only one is required, there are two in the board layout so that the constructor can choose to fit a right-angle or vertical mount switch.

image

 

Building It

I built the prototype using lots of jumper wires, however, I have created a circuit board layout and the files are downloadable from this blog post, ready for sending to any PCB factory such as JLC PCB or Elecrow. Log on to your preferred PCB factory site, click on Upload Gerber and select the zip file that is attached to this blog post. After a few tens of seconds, the web page should update with the following type of information, and then the board can be ordered.

image

 

This is the prototype (without the PCB):

image

 

The PCB is untested, I have not built this yet. The board has space for up to 10 buttons (I figured it could also be converted into a maths toy if it had ten buttons, for instance, a maths quiz like a vocal version of Little Professor should be feasible.

image

image

The completed board fits Hammond 1593T series boxes (see the parts list for the details) along with a small speaker, or perhaps a case could be 3D-printed.

 

Parts List

ReferenceQtyDescription
C1, C2, C3347uF 16V Capacitor
D111N5711 or any other Schottky Diode
D215mm LED
J11PP3 9V Battery Clip
R11220 ohm Resistor
SW0 to SW910Tact Switch 6 x 6 mm
SW101OS202013MT5QN1OS202013MT5QN1 DPDT Slide Switch Vertical (Preferred)
SW111OS102011MA1QN1OS102011MA1QN1 SPDT Slide Switch (optional alternative)
U11Raspberry Pi Pico
U21MAX98357 I2S DAC/Amplifier Board
U31R-78E5.0-0.5R-78E5.0-0.5 DC-DC Converter (Preferred), or 7805 Regulator
SPKR18 ohm Speaker (e.g. 'laptop internal speaker')
Box1Hammond 1593T series: 1593TBK1593TBK or 1593TGY1593TGY or 1593TTBU1593TTBU

 

 

Code

See GitHub for the latest version of the source code, however a basic working example is also printed below. Line 8 contains a list of names for the audio files, this can be extended for as many buttons as are connected to the Pi. Line 10 contains the mapping to the GPIO pins, for all the buttons. The main function contains a loop that runs forever, waiting on any button to be pressed, and then playing out the associated MP3 file.

 

 

import board
import audiomp3
import audiobusio
import digitalio
import time


# file names
fnames = ["1.mp3", "2.mp3", "3.mp3", "4.mp3", "5.mp3", "6.mp3"]
# buttons
input_gpio = [board.GP1, board.GP2, board.GP3, board.GP4, board.GP5, board.GP6]
buttons = []
# other variables
forever = 1


# main program
def main():
    global buttons
    print("Hello")
    # setup connections
    # create I2S output, pins order: (BCLK, FS, DATA)
    i2s = audiobusio.I2SOut(board.GP14, board.GP15, board.GP13)
    # board LED
    boardled = digitalio.DigitalInOut(board.GP25)
    boardled.direction = digitalio.Direction.OUTPUT
    # buttons
    for idx, v in enumerate(input_gpio):
        buttons.append(digitalio.DigitalInOut(v))
        buttons[idx].direction = digitalio.Direction.INPUT
        buttons[idx].pull = digitalio.Pull.UP


    # create MP3 decoder with any file
    dummy = open(fnames[0], "rb")
    asource = audiomp3.MP3Decoder(dummy)


    while forever:
        for idx, b in enumerate(buttons):
            if b.value is False:  # button is pressed
                asource.file = open(fnames[idx], "rb")
                start = time.monotonic()
                i2s.play(asource)  # play the audio source
                while i2s.playing:
                    pass
                stop = time.monotonic()
                print(f"Played {fnames[idx]} {stop - start} sec")




main()  # run main program

 

 

Uploading the Code to the Pi Pico

For the first time, hold down the only button that is on the Pi Pico, and connect the Pi Pico to your PC using a USB cable, and then release the button. A USB Storage drive letter will appear on the PC. Drag the latest CircuitPython firmware onto that drive letter, and the Pi Pico should update itself within a few seconds, and the drive name will change to CIRCUITPYTHON. From now on, the button on the Pi Pico does not ever need to be pressed at USB insertion, unless the CircuitPython firmware is being updated.

 

Next, drag the Pocket Scarface code.py file available from GitHub onto that drive letter, along with any MP3 files. That's it, now you can disconnect the USB connection and begin to use the project.

 

Summary

Using mainly off-the-shelf modules such as the Pi Pico and an I2S Audio DAC board, it is possible to make a simple toy for kids. The benefit of using the Python programming language is that hopefully kids may be encouraged to edit the code, modify the functionality, or change the audio files. As a next step, it would be interesting to rewrite the code into a different project using the same hardware - for instance if the buttons were labeled 1-10 on the enclosure, then an audio version of Little Professor could be interesting.

 

Thanks for reading!

Attachments:
export-pocket-scarface-rev1.zip
  • Sign in to reply
  • genebren
    genebren over 3 years ago

    Great project!  This is something that I might want to try.  I have been using the DFR0299 modules to handle the MP3 playing, but it would be nice to have this built-in on a processor.

    Thanks for trying this out.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 3 years ago in reply to rsjawale24

    Hi Rushiraj,

     

    Thanks! I use PowerPoint. Visio would be another option that people normally use (I'm just way more familiar with PowerPoint). Everything in the diagrams is composed from the Shapes menu in PowerPoint (so for example the speaker symbol was made from a triangle and a rectangle, with a circle outside).

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • rsjawale24
    rsjawale24 over 3 years ago

    I have always loved your block diagrams. What software do you use to draw those block diagrams?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fmilburn
    fmilburn over 3 years ago

    Hi Shabaz,

     

    That is really nice.  I've been using inexpensive sound breakouts but this provides more options and possibly less cost.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 3 years ago in reply to dougw

    Hi Doug,

     

    Thanks! It's very strange feeling, going against all normal procedures, dragging source code onto the microcontroller : )

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube