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

Поділитися
Вставка
  • Опубліковано 1 січ 2025

КОМЕНТАРІ • 60

  • @Mr-Steve-Robinson
    @Mr-Steve-Robinson Рік тому +12

    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.

  • @dennistruong6091
    @dennistruong6091 4 місяці тому +3

    This was detailed and insightful yet super easy to understand. Well done

    • @profgallaugher
      @profgallaugher  4 місяці тому +1

      What a kind comment. I appreciate the encouragement. Hack on!

  • @joeblow229
    @joeblow229 Рік тому +2

    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.

  • @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

  • @justin22763
    @justin22763 11 днів тому

    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

    • @profgallaugher
      @profgallaugher  10 днів тому

      My students did something cool like this. Here is their instrictable. www.instructables.com/Matrix-Festive-Timer-CircuitPython-BLE-Tracker/?amp_page=true

  • @cheapnoiseinthehouse5578
    @cheapnoiseinthehouse5578 Рік тому +3

    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.

    • @profgallaugher
      @profgallaugher  Рік тому +1

      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

  • @cheapnoiseinthehouse5578
    @cheapnoiseinthehouse5578 10 місяців тому +1

    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.

  • @DieselDragon
    @DieselDragon 2 місяці тому

    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. 👍)

    • @profgallaugher
      @profgallaugher  2 місяці тому +1

      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.

  • @matthewfogelson9665
    @matthewfogelson9665 10 місяців тому +2

    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  10 місяців тому

      Definitely check out Adafruit Discord for more help. They are great! I am currently on sabbatical.

  • @olafschermann1592
    @olafschermann1592 9 місяців тому +1

    Awesome, how easy

  • @arash2953
    @arash2953 7 місяців тому

    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  7 місяців тому

      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  Рік тому +1

      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

  • @ricardorizzato4719
    @ricardorizzato4719 7 місяців тому

    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.

  • @geckowingman
    @geckowingman Рік тому +1

    where is the audiocore library :(

    • @profgallaugher
      @profgallaugher  Рік тому +1

      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 Рік тому +1

      @@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 :)

  • @michaelzhou5095
    @michaelzhou5095 Рік тому +2

    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  Рік тому +1

      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 10 місяців тому

    Can I use the same code to play different audio files using different buttons?

    • @profgallaugher
      @profgallaugher  10 місяців тому

      As long as you code the buttons and files properly, absolutely.

  • @retrobombstudios1258
    @retrobombstudios1258 Рік тому

    would micropython work in place of circuit?

    • @profgallaugher
      @profgallaugher  Рік тому

      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 Рік тому

      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  Рік тому

      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!

  • @four0string0thumper
    @four0string0thumper 4 місяці тому

    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.

    • @profgallaugher
      @profgallaugher  4 місяці тому

      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.

    • @four0string0thumper
      @four0string0thumper 4 місяці тому

      @@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!

    • @profgallaugher
      @profgallaugher  4 місяці тому +1

      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!

  • @Astrofished
    @Astrofished Рік тому

    Could I use a potentiometer to control the volume as the audio file is playing?

    • @profgallaugher
      @profgallaugher  Рік тому

      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!

  • @draco5991rep
    @draco5991rep 3 місяці тому +2

    The audacity to convert audio files 😧

  • @bhavnahar7309
    @bhavnahar7309 8 місяців тому +2

    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  8 місяців тому +1

      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.

  • @OmTidke-kw2kp
    @OmTidke-kw2kp 8 місяців тому

    Can I play a 10 sec long song on pico.

    • @profgallaugher
      @profgallaugher  8 місяців тому

      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.

  • @Ornitronik
    @Ornitronik Рік тому +1

    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  Рік тому +2

      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!

  • @lekdkengineer2455
    @lekdkengineer2455 Рік тому

    can you make drum pad with pico ?? ..

    • @profgallaugher
      @profgallaugher  Рік тому +1

      Check out the playlist. The DJ board will let you out in whatever sounds you want and play them simultaneously. bit.ly/pico-tutorials

  • @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  Рік тому +1

      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.

  • @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  Рік тому +1

      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 Рік тому +4

      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.