That video is so clear and so thorough - I'm making a lighthouse for kids and wanted to add sound (of an imaginary lighthouse keeper) - it worked first time. Thank you so much, John.
This is just what I was looking for; a way to play short audio clips with a Pi Pico! :) I'm going to replace the 'beep' when I turn on my computer with the sound that plays when you get an item in Metroid.
wow thank you very much ie been waiting for this tutorial FOREVER !! because i have alot of picos and love audio but could not unersand how to play thanks
My students did something cool like this. Here is their instrictable. www.instructables.com/Matrix-Festive-Timer-CircuitPython-BLE-Tracker/?amp_page=true
Really nice video. What would be the simplest way to change sample rate? I would like to save sounds at lower sample rates to save space and play them at different pitches.
Glad you like it. Here is a lesson showing how to use free audacity software to change the sample rate. Be sure that the code matches the sample rate or you’ll get an error. Good luck! Disco Button Funk up any room with MQTT, CircuitPython, and a Raspberry Pi Pico W ua-cam.com/video/565lpAIWjJM/v-deo.html
I am using this library for a bop it style game. However, there is a loud pop at the start and end of every sound. Do you know why this happends and how to resolve it? I'm using wav files.
Often wondered if it was possible to use the Pico for audio playback, and now I know! Many thanks for the tutorial! 😇👍 Also, a simple way of converting audio to the right format for Linux users: 🐧 * Install _ffmpeg_ if you don't already have it: [sudo] apt-get install ffmpeg * cd to the directory where your source file is located, * Run _ffmpeg -i ./[FileName].mp3 -vn -acodec libmp3lame -ac 1 -ar 22050 -ab 16Ki -f mp3 ./[DesiredOutputFileName].mp3_ (For WAV, replace „libmp3lame“ with „pcm_s16le“ and „.mp3“ with „.wav“. You can use an MP3 input for WAV output & vice-versa. 👍)
Glad you liked it. I’ve been converting the CircuitPython playlist to PyCharm starting with the CircuitPlayground lessons. I will get to the Pico ones, soon. It’s a constant juggle between this course & my SwiftUI course. I teach both each semester and need to keep them fresh so more coming soon.
How would one play .flac files? Is it possible? Can the files be stereo too? How hard would it be to create a menu system? Skim id3 tags, sort into artists and albums, songs etc. Select song to play. I assume lists would be needed. Obviously external storage would be needed and, an amp. Could we do all this with I2S to an amp too? Bonus if a display and controls can be added. Sorry, a lot of questions
First I want to thanks you for this channel your trainings are awesome... I was wondering if these projects are working on Raspberry zero as well ? For instance the audio output project ?
Audio can be a bit tricky because there isn’t an audio out port on the zero, which is why I usually use a pi 2 in class. However I’ve switched to a Pico since it’s even easier to use. Feel free to check out the fully playlist at http:://bit.ly/circuitpython-tutorials
So glad you like it. Stereo is a bit more complicated. You can house audiomixer docs.circuitpython.org/en/latest/shared-bindings/audiomixer/index.html if you scroll through the playlist you’ll see a primer on using audiomixer. I hope to have a new video on this at some point in the coming weeks. Here is the Adafruit doc on audiomixer docs.circuitpython.org/en/latest/shared-bindings/audiomixer/index.html
Only get this: MPY: soft reboot Traceback (most recent call last): File "", line 3, in ImportError: no module named 'digitalio' I tried to install all libraries, but I'm missing something.
It is built in when you install CircuitPython so you won’t have a module to drag into lib. To find the avail modules that are built in for your board you can enter the following at the REPL prompt help(“modules”) You can also find a matrix listing them for each board at docs.circuitpython.org/en/latest/shared-bindings/support_matrix.html Also if you scroll down when you find the .uf2 at CircuitPython.org you’ll also see a list of built ins for that board. Good luck!
@@profgallaugher Thank you for the reply I followed everything and It all makes much more sense! thank you im trying to run the program but no audio out unfortunate hopefully i can get it to work tomorrow
It’s great to have mp3 audio output working on Pico (best part is that I can have TFT animation+SFX both working on a battery pack). Now the high frequency bursts noise at beginning of mp3 audio is annoying… anyway to avoid that? Do I need to add a LPF circuit on the pin?
Yes, the pops are annoying. I haven’t found any way around this. Some have suggested trying AuduoMixer and lowering the volume briefly in the intro. I haven’t explored this to see if it’s really an option or not. Let me know if you find a solution. I may look into audiomixer as I build out the “Disco Button” I just posted about on Instagram and Mastodon. Would be nice to have pop-free music for this. Cheers!
Michael. It turns out audiometer doesn't support mp3s, but will play wavs. In my "Disco Button" project, I'm switching to wavs & audiometer. This seems to get rid of the pop and crackle, improving playback. Since I've added an SD card, I can use wavs without problems. I haven't created a full tutorial on this, but likely will at some point, but you might be able to go through this code to get a sense of how this works. Audiometer is created to be able to play multiple sounds simultaneously, but here I'm using it to play a single wav, but since it's smoother this is likely a better choice. Cheers! github.com/gallaugher/disco-button/blob/main/demo_of_wav_audio_mixer_no_pops
I've been learning a lot about this stuff these past few days. I was getting random ticks when using AudioMixer - both when a song was actively playing as well as when it stopped. They weren't in the proper place, either. I found that if I reduced the frequency rate using Audacity from 22050 to 16000 the ticks went away & the AudioMixer technique worked perfectly. This seems like a really good technique to use. I'll definitely do a lesson on this once my schedule clears up. Good luck with the SD card. This is also a real advantage in getting decent sound projects working on the Pico. Cheers & Hack On! BTW: If you want a "Make Something Awesome" sticker, DM me with a mailing address. I send them out to different folks each week, free of charge.
@@profgallaugher Good to know!I have got my SD working now. But with PWMAudioOut, both wav and mp3 having pops randomly. Will give lower sample rate a try. Haven’t played with Audacity before, good opportunity to learn. BTW, I am outside US so probably we can only do online comm😛, but thank you nonetheless!
MicroPython uses different code, different installation procedures, etc. I work with CircuitPython for the reasons mentioned at the start of the video series - well supported, easier to use, etc.
I find CP much easier and straight forward. It's also super-well supported & there's lots of great help on Adafruit's Discord channel. You can start here to see the content I've created that will take you through motor use with CircuitPython: bit.ly/circuitpython-tutorials. And the first lesson in that series mentions why I work with CP & choose that for my university courses. Good luck!
How are you adding files to the Circuitpy storage? I create the folder and paste my wav in there as depicted in the video, but when the pi is unplugged and plugged back in they are gone.
Hi. Just drag the files over. They should copy. If you are losing files try ejecting the volume before unplugging it. What type of computer are you using? Macs with Sonoma show an error when copying but you can ignore it. Copying is a bit slower due to a Sonoma bug but still works. Try Eject and see if that works. Also Adafruit Discord is a great place to go for additional support.
@@profgallaugher Thanks so much for your response. I am indeed on Sonoma although I've not seen any error messages when copying. I've been ejecting the volume but the same behaviour occurs consistently. I've tried using flash nuke, and also tried older versions of circuitpy all with the same result. Thank you for pointing out the Adafruit discord, I will definitely jump in there. Also thanks for all your tutorials, it has been a great resource!
One thing you can try in addition to nuke is wiping out the file system & starting an install from scratch. Get into the REPL, then import storage, then: storage.erase_filesystem() This will wipe out your board & put a code.py with a single print statement, empty lib, sd, folders and an empty settings.toml. You don't need the sd or settings unless you're doing stuff with an external SD card or wifi, respectively, but you can keep them there. They're not very big & the reformat puts them on. Once you do that, reinstall the libraries you need. I've been using circup which is a huge benefit to doing this quickly. Then try things out. My guess is that's the first advice Adafruit Discord will give, but expect more good input if this doesn't work (hopefully it will). It seems file systems have been getting corrupted on Sonoma if folks unplug the board while writing happens. The eject before unplugging should theoretically fix things, but I've forgotten to do this plenty of times & had to erase the board & reinstall regularly. Oh - and thanks so much for your kind words on the channel!
I'm getting the sound but it's so low my speaker is 1w 8ohm how can i increase the volume i have to put the speaker on my ear to listen Do I need a speaker with it's own power supply?
Yes. That’d definitely help. You can see the hamburger speaker I use in class. It’s only about $8 and can be easily clipped to a board. Look in the playlist for full examples.
Lots of ways to do this. Songs don’t have a fixed size / length, but the longer the song recorded with a higher fidelity, the more space it’ll take up. But if you scroll through the list you’ll also see how you can add an SD card to the Pico and then you’ll be able to play gigabytes of sound files.
Is it possible to read an analog port and record it in a .wav file? I have been working with the library but I am having errors because I don't know what is happening with version 8 and the audioio module. Thank you very much and I hope you can help me
I've never tried this, but I'd check with folks on the Adafruit Discord Channel. The support there is great & there are likely folks who have worked with audio input. See adafru.it/discord. Good luck!
How about using the 'Adafruit STEMMA Speaker - Plug and Play Audio Amplifier - JST PH 2mm' (#3885) speaker? Assuming the hook up would be the same as you show. Not sure what this sounds like but it does have volume control and a low price. However, it's NOT battery powered but it will work with any 3-5V supply (assume it doesn't require much current and could be powered directly from Vout on your board). How would this compare to a hamburger speaker? Thanks.
The speaker is STEMMA and not STEMMA QT so I’ve avoided it. That might be a good alternative for some projects. I have used this one successfully for some projects. www.adafruit.com/product/3885 I’m finding many folks have speakers with 3.5 mm audio plugs so the two alligator clip method works well. I’ve also ordered 50 breadboard friendly jacks that will likely be useful for many of my students’ builds. Do let us know how the other speaker works for you.
I tried it on my Pi Pico, but there is no sound, only a hum. I don't know what I did wrong. I would appreciate it if you could comment the code (for the wav file player) for me.
Make sure your sound file is formatted as mentioned. If it’s not mono or 22khz or smaller you’ll run into probs. You can also try other pins to see if your pin is an issue. Try other wires, as well. Finally you can check your speaker by trying some of the other code in the playlist that also uses sound. Good luck!
It's working now! I redo the wiring, then use the audio settings you recommended (Mono, 22050 Hz, and 16-bit PCM), and it now works. Thank you very much.
That video is so clear and so thorough - I'm making a lighthouse for kids and wanted to add sound (of an imaginary lighthouse keeper) - it worked first time. Thank you so much, John.
Glad it was helpful!
This was detailed and insightful yet super easy to understand. Well done
What a kind comment. I appreciate the encouragement. Hack on!
This is just what I was looking for; a way to play short audio clips with a Pi Pico! :)
I'm going to replace the 'beep' when I turn on my computer with the sound that plays when you get an item in Metroid.
wow thank you very much ie been waiting for this tutorial FOREVER !! because i have alot of picos and love audio but could not unersand how to play thanks
Could you make a video using a pico to scan a rfid to make the pico turn on a string of leds and play a sound. For example a magic band reader
My students did something cool like this. Here is their instrictable. www.instructables.com/Matrix-Festive-Timer-CircuitPython-BLE-Tracker/?amp_page=true
Really nice video. What would be the simplest way to change sample rate? I would like to save sounds at lower sample rates to save space and play them at different pitches.
Glad you like it. Here is a lesson showing how to use free audacity software to change the sample rate. Be sure that the code matches the sample rate or you’ll get an error. Good luck! Disco Button Funk up any room with MQTT, CircuitPython, and a Raspberry Pi Pico W
ua-cam.com/video/565lpAIWjJM/v-deo.html
I am using this library for a bop it style game. However, there is a loud pop at the start and end of every sound. Do you know why this happends and how to resolve it? I'm using wav files.
Often wondered if it was possible to use the Pico for audio playback, and now I know! Many thanks for the tutorial! 😇👍
Also, a simple way of converting audio to the right format for Linux users: 🐧
* Install _ffmpeg_ if you don't already have it: [sudo] apt-get install ffmpeg
* cd to the directory where your source file is located,
* Run _ffmpeg -i ./[FileName].mp3 -vn -acodec libmp3lame -ac 1 -ar 22050 -ab 16Ki -f mp3 ./[DesiredOutputFileName].mp3_
(For WAV, replace „libmp3lame“ with „pcm_s16le“ and „.mp3“ with „.wav“. You can use an MP3 input for WAV output & vice-versa. 👍)
Glad you liked it. I’ve been converting the CircuitPython playlist to PyCharm starting with the CircuitPlayground lessons. I will get to the Pico ones, soon. It’s a constant juggle between this course & my SwiftUI course. I teach both each semester and need to keep them fresh so more coming soon.
How would one play .flac files? Is it possible? Can the files be stereo too?
How hard would it be to create a menu system? Skim id3 tags, sort into artists and albums, songs etc. Select song to play. I assume lists would be needed. Obviously external storage would be needed and, an amp. Could we do all this with I2S to an amp too? Bonus if a display and controls can be added.
Sorry, a lot of questions
Definitely check out Adafruit Discord for more help. They are great! I am currently on sabbatical.
Awesome, how easy
Thank you! Cheers!
First I want to thanks you for this channel your trainings are awesome...
I was wondering if these projects are working on Raspberry zero as well ? For instance the audio output project ?
Audio can be a bit tricky because there isn’t an audio out port on the zero, which is why I usually use a pi 2 in class. However I’ve switched to a Pico since it’s even easier to use. Feel free to check out the fully playlist at http:://bit.ly/circuitpython-tutorials
This works great! Also, is it possible to get 2 channel stereo audio?
So glad you like it. Stereo is a bit more complicated. You can house audiomixer docs.circuitpython.org/en/latest/shared-bindings/audiomixer/index.html if you scroll through the playlist you’ll see a primer on using audiomixer. I hope to have a new video on this at some point in the coming weeks. Here is the Adafruit doc on audiomixer docs.circuitpython.org/en/latest/shared-bindings/audiomixer/index.html
Only get this:
MPY: soft reboot
Traceback (most recent call last):
File "", line 3, in
ImportError: no module named 'digitalio'
I tried to install all libraries, but I'm missing something.
where is the audiocore library :(
It is built in when you install CircuitPython so you won’t have a module to drag into lib. To find the avail modules that are built in for your board you can enter the following at the REPL prompt
help(“modules”)
You can also find a matrix listing them for each board at docs.circuitpython.org/en/latest/shared-bindings/support_matrix.html
Also if you scroll down when you find the .uf2 at CircuitPython.org you’ll also see a list of built ins for that board. Good luck!
@@profgallaugher Thank you for the reply I followed everything and It all makes much more sense! thank you im trying to run the program but no audio out unfortunate hopefully i can get it to work tomorrow
figured it out haha works great thank you so much :)
It’s great to have mp3 audio output working on Pico (best part is that I can have TFT animation+SFX both working on a battery pack). Now the high frequency bursts noise at beginning of mp3 audio is annoying… anyway to avoid that? Do I need to add a LPF circuit on the pin?
Yes, the pops are annoying. I haven’t found any way around this. Some have suggested trying AuduoMixer and lowering the volume briefly in the intro. I haven’t explored this to see if it’s really an option or not. Let me know if you find a solution. I may look into audiomixer as I build out the “Disco Button” I just posted about on Instagram and Mastodon. Would be nice to have pop-free music for this. Cheers!
Michael. It turns out audiometer doesn't support mp3s, but will play wavs. In my "Disco Button" project, I'm switching to wavs & audiometer. This seems to get rid of the pop and crackle, improving playback. Since I've added an SD card, I can use wavs without problems. I haven't created a full tutorial on this, but likely will at some point, but you might be able to go through this code to get a sense of how this works. Audiometer is created to be able to play multiple sounds simultaneously, but here I'm using it to play a single wav, but since it's smoother this is likely a better choice. Cheers!
github.com/gallaugher/disco-button/blob/main/demo_of_wav_audio_mixer_no_pops
@@profgallaugher Thanks a lot!will give it a try when my SD card module is shipped.🤝
I've been learning a lot about this stuff these past few days. I was getting random ticks when using AudioMixer - both when a song was actively playing as well as when it stopped. They weren't in the proper place, either. I found that if I reduced the frequency rate using Audacity from 22050 to 16000 the ticks went away & the AudioMixer technique worked perfectly. This seems like a really good technique to use. I'll definitely do a lesson on this once my schedule clears up. Good luck with the SD card. This is also a real advantage in getting decent sound projects working on the Pico. Cheers & Hack On! BTW: If you want a "Make Something Awesome" sticker, DM me with a mailing address. I send them out to different folks each week, free of charge.
@@profgallaugher Good to know!I have got my SD working now. But with PWMAudioOut, both wav and mp3 having pops randomly. Will give lower sample rate a try. Haven’t played with Audacity before, good opportunity to learn. BTW, I am outside US so probably we can only do online comm😛, but thank you nonetheless!
Can I use the same code to play different audio files using different buttons?
As long as you code the buttons and files properly, absolutely.
would micropython work in place of circuit?
MicroPython uses different code, different installation procedures, etc. I work with CircuitPython for the reasons mentioned at the start of the video series - well supported, easier to use, etc.
Thankyou so much for your quick reply.Just one more thing.I am using micropython for servos leds ect.would i benefit by switching over to circuit?
I find CP much easier and straight forward. It's also super-well supported & there's lots of great help on Adafruit's Discord channel. You can start here to see the content I've created that will take you through motor use with CircuitPython: bit.ly/circuitpython-tutorials. And the first lesson in that series mentions why I work with CP & choose that for my university courses. Good luck!
How are you adding files to the Circuitpy storage? I create the folder and paste my wav in there as depicted in the video, but when the pi is unplugged and plugged back in they are gone.
Hi. Just drag the files over. They should copy. If you are losing files try ejecting the volume before unplugging it. What type of computer are you using? Macs with Sonoma show an error when copying but you can ignore it. Copying is a bit slower due to a Sonoma bug but still works. Try Eject and see if that works. Also Adafruit Discord is a great place to go for additional support.
@@profgallaugher Thanks so much for your response. I am indeed on Sonoma although I've not seen any error messages when copying. I've been ejecting the volume but the same behaviour occurs consistently. I've tried using flash nuke, and also tried older versions of circuitpy all with the same result. Thank you for pointing out the Adafruit discord, I will definitely jump in there.
Also thanks for all your tutorials, it has been a great resource!
One thing you can try in addition to nuke is wiping out the file system & starting an install from scratch. Get into the REPL, then import storage, then: storage.erase_filesystem()
This will wipe out your board & put a code.py with a single print statement, empty lib, sd, folders and an empty settings.toml. You don't need the sd or settings unless you're doing stuff with an external SD card or wifi, respectively, but you can keep them there. They're not very big & the reformat puts them on. Once you do that, reinstall the libraries you need. I've been using circup which is a huge benefit to doing this quickly. Then try things out. My guess is that's the first advice Adafruit Discord will give, but expect more good input if this doesn't work (hopefully it will). It seems file systems have been getting corrupted on Sonoma if folks unplug the board while writing happens. The eject before unplugging should theoretically fix things, but I've forgotten to do this plenty of times & had to erase the board & reinstall regularly. Oh - and thanks so much for your kind words on the channel!
Could I use a potentiometer to control the volume as the audio file is playing?
Yes but you’ll need to use AudioMixer. See tutorials later in the playlist. I’m sure Adafruit has some good examples of this, too. Cheers!
The audacity to convert audio files 😧
I'm getting the sound but it's so low my speaker is 1w 8ohm how can i increase the volume i have to put the speaker on my ear to listen
Do I need a speaker with it's own power supply?
Yes. That’d definitely help. You can see the hamburger speaker I use in class. It’s only about $8 and can be easily clipped to a board. Look in the playlist for full examples.
Can I play a 10 sec long song on pico.
Lots of ways to do this. Songs don’t have a fixed size / length, but the longer the song recorded with a higher fidelity, the more space it’ll take up. But if you scroll through the list you’ll also see how you can add an SD card to the Pico and then you’ll be able to play gigabytes of sound files.
Is it possible to read an analog port and record it in a .wav file? I have been working with the library but I am having errors because I don't know what is happening with version 8 and the audioio module. Thank you very much and I hope you can help me
I've never tried this, but I'd check with folks on the Adafruit Discord Channel. The support there is great & there are likely folks who have worked with audio input. See adafru.it/discord. Good luck!
can you make drum pad with pico ?? ..
Check out the playlist. The DJ board will let you out in whatever sounds you want and play them simultaneously. bit.ly/pico-tutorials
How about using the 'Adafruit STEMMA Speaker - Plug and Play Audio Amplifier - JST PH 2mm' (#3885) speaker? Assuming the hook up would be the same as you show. Not sure what this sounds like but it does have volume control and a low price. However, it's NOT battery powered but it will work with any 3-5V supply (assume it doesn't require much current and could be powered directly from Vout on your board). How would this compare to a hamburger speaker? Thanks.
The speaker is STEMMA and not STEMMA QT so I’ve avoided it. That might be a good alternative for some projects. I have used this one successfully for some projects. www.adafruit.com/product/3885 I’m finding many folks have speakers with 3.5 mm audio plugs so the two alligator clip method works well. I’ve also ordered 50 breadboard friendly jacks that will likely be useful for many of my students’ builds. Do let us know how the other speaker works for you.
I tried it on my Pi Pico, but there is no sound, only a hum. I don't know what I did wrong. I would appreciate it if you could comment the code (for the wav file player) for me.
Make sure your sound file is formatted as mentioned. If it’s not mono or 22khz or smaller you’ll run into probs. You can also try other pins to see if your pin is an issue. Try other wires, as well. Finally you can check your speaker by trying some of the other code in the playlist that also uses sound. Good luck!
It's working now! I redo the wiring, then use the audio settings you recommended (Mono, 22050 Hz, and 16-bit PCM), and it now works. Thank you very much.