Тёмный

Feel the noise on a Raspberry Pi Pico - learn to play .wav and .mp3 files in CircuitPython 

John Gallaugher
Подписаться 8 тыс.
Просмотров 21 тыс.
50% 1

We'll learn that you can attach an audio jack to a Raspberry Pi Pico and Pico W with simple alligator clips, then get sound to play from the Pico through the speaker. We'll learn to do this for wav files and for mp3 files. We'll write re-usable routines that you can copy & paste any time you want to play these types of files in your own builds. We'll learn how to use Audacity to create .wav and .mp3 files that will play via CircuitPython. And we'll learn how to use Python's ternary operator to write shorter, more efficient code. Crank up the Big Learning - this one goes to 11!
Part of Prof. John Gallaugher's University Physical Computing course. For more info, see gallaugher.com/physical-compu...

Опубликовано:

 

21 фев 2023

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 46   
@Mr-Steve-Robinson
@Mr-Steve-Robinson Год назад
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.
@profgallaugher
@profgallaugher Год назад
Glad it was helpful!
@manuelr7121
@manuelr7121 Год назад
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
@joeblow229
@joeblow229 7 месяцев назад
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.
@olafschermann1592
@olafschermann1592 4 месяца назад
Awesome, how easy
@profgallaugher
@profgallaugher 4 месяца назад
Thank you! Cheers!
@arash2953
@arash2953 2 месяца назад
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 ?
@profgallaugher
@profgallaugher 2 месяца назад
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
@El_IrregularDX
@El_IrregularDX Год назад
This works great! Also, is it possible to get 2 channel stereo audio?
@profgallaugher
@profgallaugher Год назад
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
@christopherlyons7613
@christopherlyons7613 Год назад
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.
@profgallaugher
@profgallaugher Год назад
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.
@matthewfogelson9665
@matthewfogelson9665 5 месяцев назад
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
@profgallaugher
@profgallaugher 5 месяцев назад
Definitely check out Adafruit Discord for more help. They are great! I am currently on sabbatical.
@Ornitronik
@Ornitronik Год назад
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
@profgallaugher
@profgallaugher Год назад
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!
@ricardorizzato4719
@ricardorizzato4719 2 месяца назад
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.
@christianb7494
@christianb7494 7 месяцев назад
Could I use a potentiometer to control the volume as the audio file is playing?
@profgallaugher
@profgallaugher 7 месяцев назад
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!
@bhavnahar7309
@bhavnahar7309 3 месяца назад
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?
@profgallaugher
@profgallaugher 3 месяца назад
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.
@michaelzhou5095
@michaelzhou5095 Год назад
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?
@profgallaugher
@profgallaugher Год назад
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!
@profgallaugher
@profgallaugher Год назад
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
@michaelzhou5095
@michaelzhou5095 Год назад
@@profgallaugher Thanks a lot!will give it a try when my SD card module is shipped.🤝
@profgallaugher
@profgallaugher Год назад
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.
@michaelzhou5095
@michaelzhou5095 Год назад
⁠@@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!
@raphaebaetiong5504
@raphaebaetiong5504 5 месяцев назад
Can I use the same code to play different audio files using different buttons?
@profgallaugher
@profgallaugher 5 месяцев назад
As long as you code the buttons and files properly, absolutely.
@bennattz
@bennattz Год назад
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.
@profgallaugher
@profgallaugher Год назад
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!
@bennattz
@bennattz Год назад
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.
@lekdkengineer2455
@lekdkengineer2455 Год назад
can you make drum pad with pico ?? ..
@profgallaugher
@profgallaugher Год назад
Check out the playlist. The DJ board will let you out in whatever sounds you want and play them simultaneously. bit.ly/pico-tutorials
@geckowingman
@geckowingman Год назад
where is the audiocore library :(
@profgallaugher
@profgallaugher Год назад
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!
@geckowingman
@geckowingman Год назад
@@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
@geckowingman
@geckowingman Год назад
figured it out haha works great thank you so much :)
@retrobombstudios1258
@retrobombstudios1258 8 месяцев назад
would micropython work in place of circuit?
@profgallaugher
@profgallaugher 8 месяцев назад
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.
@retrobombstudios1258
@retrobombstudios1258 8 месяцев назад
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?
@profgallaugher
@profgallaugher 8 месяцев назад
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!
@OmTidke-kw2kp
@OmTidke-kw2kp 3 месяца назад
Can I play a 10 sec long song on pico.
@profgallaugher
@profgallaugher 3 месяца назад
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.
Далее
Spin Up a Raspberry Pi Pico Using a Potentiometer
12:47
PicoMite: Running BASIC on a Raspberry Pi Pico
19:29
Просмотров 145 тыс.
Советы на всё лето 4 @postworkllc
00:23
I Built 3 SECRET Rooms In School!
33:34
Просмотров 10 млн
ТЫ С ДРУГОМ В ДЕТСТВЕ😂#shorts
01:00
My NEW Raspberry Pi Music Streamer
8:13
Просмотров 73 тыс.
What is VGA and How to Use it With a Raspberry Pi Pico
18:28
Hacking my garage door with the Raspberry Pi Pico W
11:50
DIY Raspberry Pi Zero Internet Radio
11:25
Просмотров 56 тыс.
Советы на всё лето 4 @postworkllc
00:23