Raspberry Pi Pico audio participant
For an index to all my tales click on this textual content.
After all of the continuing tales the time has come to construct an entire stand-alone audio participant with the Raspberry Pi Pico. The audio high quality shouldn’t be Hifi however it’s actually good !! Good sufficient as a participant in your mancave, bed room and even as a conveyable participant. I’ve made a everlasting setup and utilizing it to play music and podcasts. My setup has a number of neat additional options which shall be described in a while.
The programming is finished in MicroPython with Thonny because the IDE.
You can use a Pico or a Pico-W for this venture. The pin connections and this system are the identical.
To construct this I’m going to record the elements which might be wanted first:
– A Raspberry Pi Pico or Pico W
– 3 push buttons
– 4 10K resistors.
– 2 1K resistors
– 4 2K2 resistors
– 2 47nF capacitors.
– 1 SD card module or SD card adapter
– 1 SSD1306 Oled show
– 1 giant on a number of small breadboards
– Dupont wires for the breadboard
Extra
– An lively speaker (like a pc speaker) or
– a pair of earplug headphones.
– a 3.5mm contra connector for the headphone or audio system
– an non-obligatory small amplifier so you don’t want an lively speaker
– a pair of small audio system when utilizing the amplifier
– alligator clips for connecting to the headphone or audio system
– Power Bank or USB energy provide
To get this working we’d like a whole lot of drivers for MicroPython. We want drivers for enjoying the sounds, we’d like drivers for the SD card, we’d like drivers for the SSD1306 oled display screen.
I bundled all these drivers on my Github depositry. You can discover them right here:
https://github.com/Lucvolders/MicroPython/tree/major/Libraries
Next to that you might want to know that this audio participant solely performs 8k WAV recordsdata.
I wrote a number of tales on every step that was wanted to return to this venture. I’ll record right here the hyperlinks to every step.
Converting audio recordsdata to an 8K WAV file with Audacity:
http://lucstechblog.blogspot.com/2024/10/audacity-pico-audio-part-1.html
Building the Raspberry Pi Pico audio {hardware} with only a few resistors and capacitors:
http://lucstechblog.blogspot.com/2024/10/audio-on-pico-part-2-hardware.html
Raspberry Pi pico audio taking part in software program:
http://lucstechblog.blogspot.com/2024/10/pico-audio-part-3.html
SD card for the Raspberry Pi Pico ({hardware}):
http://lucstechblog.blogspot.com/2025/01/pico-sdcard-part-1-hardware.html
SD card for the Raspberry Pi Pico (software program):
http://lucstechblog.blogspot.com/2025/01/pico-sd-card-part-2-software.html
I didn’t write a narrative on the SSD1306 oled display screen. But that’s in my e-book: Raspberry Pi pico Simplified 😉 There is a hyperlink to that e-book on the underside of this web page. The driver is nevertheless in my Github depositry.
These tales describe the {hardware} in particulars with breadboard setup. The tales additionally cowl the origin of the MicroPython drivers and accumulate them and set up them. Like mentioned earlier than I bundled all of the drivers in my Github repositry right here:
https://github.com/Lucvolders/MicroPython/tree/major/Libraries
I urge you to learn these tales so you understand what’s going on.
The breadboard setup.
Here is the breadboard setup. There are some expansions potential like including the digital thermometer which was mentioned on this story:
http://lucstechblog.blogspot.com/2024/11/pico-audio-part-4-talking-thermometer.html
Please be aware that you’re wanting on the bottom of the SD card. That is the facet the place the connector is soldered. If you’re utilizing an SD card module be sure that to connect to the suitable pins.
As there is likely to be some confusion from wanting on the above image I’ll present you all of the connections right here.
The Buttons
Button 01 is hooked up with a pull-up resistor to pin GP18
Button 02 is hooked up with a pull-up resistor to pin GP19
Button 03 is hooked up with a pull-up resistor to pin GP20
Audio
Audio left is hooked up to GP02
Audio proper is hooked up to GP03
SSD1306
The oled display screen is powered by VCC (3.3 Volt) and GND
SDA is hooked up to GP09
SCL is hooked up to GP08
SD-Card
The SD card is powered by VCC (3.3 Volt) and GND.
MISO is hooked up with a pull-up resistor to GP12
CS is hooked up to GP13
SCK is hooked up to GP14
MOSI is hooked up to GP15
You can discover all the small print about these connections within the earlier tales on this sequence. Please pay particular consideration to the audio connections to the low-pass filter and the SD card connections.
As the pins the place the {hardware} is hooked up need to be outlined in MicroPython you may as well discover the pin numbers within the MicroPython program.
The audioplayer program
As you’re used to on this weblog, I current the complete code right here which you’ll copy and paste into your favourite MicroPython editor.
''' Audioplayer Plays 8k WAV recordsdata With Oled display screen for selecting audiofiles Audio recordsdata on SD card Button GP18 subsequent quantity Button GP19 earlier quantity Button GP20 play the tune ''' # Import rubbish accumulate import gc import os as os import time import machine from machine import SPI, Pin, Timer import sdcard from wavePlayer import wavePlayer import ssd1306 sda=machine.Pin(8) scl=machine.Pin(9) i2c=machine.I2C(0,sda=sda, scl=scl,freq=400000) print(i2c.scan()) oled = ssd1306.SSD1306_I2C(128, 64, i2c) participant = wavePlayer() spi = SPI(1,sck=Pin(14), mosi=Pin(15), miso=Pin(12)) cs = Pin(13) sd = sdcard.SDCard(spi, cs) os.mount(sd, '/storage') but01=machine.Pin(18, machine.Pin.IN) but02=machine.Pin(19, machine.Pin.IN) but03=machine.Pin(20, machine.Pin.IN) playnow = -1 array=(os.listdir('/storage/Music')) numbers = len(array) print (numbers) oled.fill(0) oled.present() oled.textual content("Raspberry Audio",0,0) oled.textual content("participant",40,10) for i in vary(0, 127): oled.pixel(0 + i, 20, 1) oled.present() strive: whereas True: if (but01.worth()==0): print("button 1 pressed") playnow = playnow + 1 if (playnow == numbers): playnow = 0 tune = "/storage/Music/"+array[playnow] print(sort(tune)) assist= array[playnow] print("Now taking part in " + assist[0:-4]) oled.fill(0) oled.textual content("Raspberry Audio",0,0) oled.textual content("participant",40,10) for i in vary(0, 127): oled.pixel(0 + i, 20, 1) oled.textual content("This tune is :",0,25) oled.textual content(" ",0,35) oled.textual content(assist[0:-4],0,35) oled.present() print(playnow) time.sleep(.5) # check how a lot reminiscence is free gc.accumulate() print(gc.mem_free()) if (but02.worth()==0): #participant.cease() print("button 2 pressed") if (playnow == -1 or playnow ==0): playnow = 0 else: playnow = playnow -1 tune = "/storage/Music/"+array[playnow] print(sort(tune)) assist= array[playnow] print("Now taking part in " + assist[0:-4]) oled.fill(0) oled.textual content("Raspberry Audio",0,0) oled.textual content("participant",40,10) for i in vary(0, 127): oled.pixel(0 + i, 20, 1) oled.textual content("This tune is : ",0,25) oled.textual content(" ",0,35) oled.textual content(assist[0:-4],0,35) oled.present() print(playnow) time.sleep(.5) if (but03.worth() ==0): assist= array[playnow] print("Now taking part in " + assist[0:-4]) oled.fill(0) oled.textual content("Raspberry Audio",0,0) oled.textual content("participant",40,10) for i in vary(0, 127): oled.pixel(0 + i, 20, 1) oled.textual content("Now taking part in:",0,25) oled.textual content(" ",0,35) oled.textual content(assist[0:-4],0,35) oled.present() participant.play(tune) besides KeyboardInterrupt: participant.cease()
All of this code has been defined within the earlier chapters besides a neat trick.
array=(os.listdir('/storage/Music')) numbers = len(array) print (numbers)
The audio recordsdata are saved in a subdirectory on the SD card with the identify Music. This piece of code places the listing entries (the music names) into an array after which prints that array on Thonny’s console. The variety of music tracks is put into the variable quantity. This variable tells us what number of music tracks there are on the SD card.
print("button 1 pressed") playnow = playnow + 1 if (playnow == numbers): playnow = 0 tune = "/storage/Music/"+array[playnow] print(sort(tune)) assist= array[playnow] print("Now taking part in " + assist[0:-4])
Pressing the primary button will increase the playnow variable. That variable factors to the array that holds the listing objects. The array entry is copied into the assistance variable and that’s printed on the oled display screen. This variable entry is the identify of the music observe that’s going to be performed for those who press the third button.
If the elevated quantity is larger because the variety of array entries the quantity is ready again to 0 which is the primary array entry.
The identical is finished for the second button that decreases the variable so walks backwards by way of the array until it reaches 0.
The final button takes the array entry and performs it.
Operating the participant.
First factor to do is saving this program into your Pico and naming it major.py When the Pico reboots MicroPython appears to be like for a program with the identify major.py and routinely begins that program. This method you possibly can run this participant stand-alone with a USB energy provide or, for cell use, with an influence financial institution.
Once began the oled show exhibits the textual content:
Raspberry Audio
Player
This tells that this system is prepared. Press the primary button and the names of the music in your SD card within the subdirectory Music shall be proven one after the other.
By urgent the second button you possibly can scroll backwards by way of the names.
Pressing the third button will play the tune which identify is on the oled display screen.
Any flaws ??
Well sure truly there’s a flaw. Once you begin taking part in a tune you can’t cease it. You’ll have to sit down it out earlier than you possibly can select one other one. A piece round answer could be including one other button and join pin 30 to GND when the button is pressed. Pin 30 is RUN and acts as a reset pin. This would truly reset the pico so it bodily reboots. You can discover construct a reset button right here: https://ift.tt/y2rvCgq
Expansions.
I can suppose of some.
– First potential enlargement is, like mentioned above, including a reset button.
– The participant performs a tune after which waits until you select one other tune and press a button. An enlargement could be the chance to begin taking part in at a sure tune after which the following ones in line would play automated.
– An enlargement could be including a Dallas DS18B20 digital thermometer. You would additionally want to connect one other button that provides you the choice to toggle between the audio participant and the speaking thermometer. You can discover the speaking thermometer on this story : http://lucstechblog.blogspot.com/2024/11/pico-audio-part-4-talking-thermometer.html
– You may add yet one more button that might activate a speaking clock. You can discover the speaking clock on this story: http://lucstechblog.blogspot.com/2024/11/pico-audio-part-5-talking-clock.html
– How about including the speaking clock and have the audio participant play your favourite tune at waking time.
– Remove the buttons (besides a reset button) and use a rotary encoder to stroll by way of the menu objects/songs and so forth and select the merchandise you want.
– Add additional buttons that you need to use as preset buttons for enjoying sure songs. You would add the chance to program these buttons if you change the SD card for one with completely different music.
These are only a few concepts I got here up with in a couple of minutes. I consider you possibly can provide you with a number of of your individual……
Please ship me a mail when you’ve got construct this or one thing that was based mostly on this venture. I’m at all times inquisitive about what my readers provide you with.
Till subsequent time,
have enjoyable
Luc Volders
HI-FI News
by way of Hacker News https://ift.tt/Wa8E2Q1
March 2, 2025 at 04:37PM
-
Product on sale
Audiophile Vinyl Records Cleaning BundleOriginal price was: €83.88.€73.88Current price is: €73.88. incl. VAT -
Product on sale
Easy Start Vinyl Records Cleaning KitOriginal price was: €83.88.€73.88Current price is: €73.88. incl. VAT -
Vinyl Records Cleaner Easy Groove Concentrate€41.94 incl. VAT -
Easy Groove Super Set€238.80 incl. VAT -
Easy Groove Enzycaster – vinyl records prewash cleaner€41.94 incl. VAT -
Easy Groove Extreme MK. II- vinyl records prewash cleaner€54.00 incl. VAT -
Vinyl Records Cleaner – Easy Groove Virgin Concentrate€42.00 incl. VAT -
Easy Groove Spray&Wipe vinyl records cleaner€41.94 incl. VAT









