Pocket Scarface – Pi Pico Python Primarily based MP3 Clip… | element14


There's a youngsters' toy that could be a pocket-sized voice/results field. It has half a dozen buttons on the entrance, and every time any button is pressed, a burst of audio is performed. Such toys are low cost when launched, however finally can promote for rather a lot on ebay! I wished to construct one thing comparable, i.e. from a birds-eye view there's nothing very authentic for this undertaking, the top result's an open-sourced rip-off of the industrial merchandise : ) See the two-minute video under for an indication.



Not like the industrial toy, this undertaking makes use of the Python programming language operating on a Pi Pico board. It permits for youths to have the ability to customise the unit and to have the ability to simply add their very own audio recordsdata for his or her favourite motion pictures/exhibits (as an example).


The undertaking makes use of CircuitPython's MP3 taking part in capabilities as mentioned right here: MP3 Playback on PI Pico. This undertaking is just like that, the one slight distinction is that as a substitute of utilizing pulse width modulation (PWM) for producing the ultimate output for the audio amplifier, this undertaking as a substitute makes use of a separate digital to analog converter (DAC), within the audio world it is named an I2S DAC. The audio high quality can hopefully be higher than the industrial toy. In consequence, though this undertaking doesn't have hi-fi high quality, it must be means higher than typical youngsters' toys. I used MP3 recordsdata recorded from a film, however they might be changed with sounds from favourite youngsters' animations for instance or musical results. There's not quite a lot of reminiscence, however a number of minutes of audio is possible (maybe extra with totally different MP3 settings - I used the next settings: 64 kbps, 44.1 kHz, mono).



This undertaking makes use of massive parts and is simple to solder. It should not take greater than half an hour to assemble it if constructed on the printed circuit board (PCB).


The circuit under (click on it to enlarge) consists of as much as 10 push-buttons related to the Pi Pico instantly, and the digital audio output from the Pi Pico goes right into a ready-made (out there from Adafruit and resellers) MAX98357 board. The facility supply for the undertaking is usually a 9V battery; the voltage is diminished utilizing a ready-made 5V DC-DC converter5V DC-DC converter which is pin-compatible with the standard linear 7805 regulatorslinear 7805 regulators; both can be utilized with this undertaking. The circuit exhibits two slide switches, SW10 SW10 and SW11SW11. Just one is required, there are two within the board format in order that the constructor can select to suit a right-angle or vertical mount swap.


I constructed the prototype utilizing plenty of jumper wires, nonetheless, I've created a circuit board format and the recordsdata are downloadable from this weblog submit, prepared for sending to any PCB manufacturing unit resembling JLC PCB or Elecrow. Go surfing to your most well-liked PCB manufacturing unit web site, click on on Add Gerber and choose the zip file that's connected to this weblog submit. After just a few tens of seconds, the net web page ought to replace with the next sort of knowledge, after which the board might be ordered.


That is the prototype (with out the PCB):


The PCB is untested, I've not constructed this but. The board has area for as much as 10 buttons (I figured it may be transformed right into a maths toy if it had ten buttons, as an example, a maths quiz like a vocal model of Little Professor must be possible.

The finished board matches Hammond 1593T collection packing containers (see the elements record for the small print) together with a small speaker, or maybe a case might be 3D-printed.


C1, C2, C3347uF 16V Capacitor
D111N5711 or some other Schottky Diode
D215mm LED
J11PP3 9V Battery Clip
R11220 ohm Resistor
SW0 to SW910Tact Change 6 x 6 mm
SW101OS202013MT5QN1OS202013MT5QN1 DPDT Slide Change Vertical (Most well-liked)
SW111OS102011MA1QN1OS102011MA1QN1 SPDT Slide Change (non-obligatory different)
U11Raspberry Pi Pico
U21MAX98357 I2S DAC/Amplifier Board
U31R-78E5.0-0.5R-78E5.0-0.5 DC-DC Converter (Most well-liked), or 7805 Regulator
SPKR18 ohm Speaker (e.g. 'laptop computer inside speaker')
Field1Hammond 1593T collection: 1593TBK1593TBK or 1593TGY1593TGY or 1593TTBU1593TTBU



See GitHub for the latest version of the source code, nonetheless a fundamental working instance can also be printed under. Line 8 accommodates a listing of names for the audio recordsdata, this may be prolonged for as many buttons as are related to the Pi. Line 10 accommodates the mapping to the GPIO pins, for all of the buttons. The principle operate accommodates a loop that runs eternally, ready on any button to be pressed, after which taking part in out the related 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 = []
# different variables
eternally = 1

# principal program
def principal():
    world buttons
    print("Whats up")
    # 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.path = digitalio.Path.OUTPUT
    # buttons
    for idx, v in enumerate(input_gpio):
        buttons[idx].path = digitalio.Path.INPUT
        buttons[idx].pull = digitalio.Pull.UP

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

    whereas eternally:
        for idx, b in enumerate(buttons):
            if b.worth is False:  # button is pressed
                asource.file = open(fnames[idx], "rb")
                begin = time.monotonic()
                i2s.play(asource)  # play the audio supply
                whereas i2s.taking part in:
                cease = time.monotonic()
                print(f"Performed {fnames[idx]} {cease - begin} sec")

principal()  # run principal program



For the primary time, maintain down the one button that's on the Pi Pico, and join the Pi Pico to your PC utilizing a USB cable, after which launch the button. A USB Storage drive letter will seem on the PC. Drag the most recent CircuitPython firmware onto that drive letter, and the Pi Pico ought to replace itself inside just a few seconds, and the drive identify will change to CIRCUITPYTHON. To any extent further, the button on the Pi Pico doesn't ever should be pressed at USB insertion, except the CircuitPython firmware is being up to date.


Subsequent, drag the Pocket Scarface code.py file available from GitHub onto that drive letter, together with any MP3 recordsdata. That is it, now you may disconnect the USB connection and start to make use of the undertaking.


Utilizing primarily off-the-shelf modules such because the Pi Pico and an I2S Audio DAC board, it's doable to make a easy toy for youths. The advantage of utilizing the Python programming language is that hopefully youngsters could also be inspired to edit the code, modify the performance, or change the audio recordsdata. As a subsequent step, it might be attention-grabbing to rewrite the code into a distinct undertaking utilizing the identical {hardware} - as an example if the buttons have been labeled 1-10 on the enclosure, then an audio model of Little Professor might be attention-grabbing.


Thanks for studying!

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *