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

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ก.พ. 2023
  • 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...

ความคิดเห็น • 49

  • @Mr-Steve-Robinson
    @Mr-Steve-Robinson ปีที่แล้ว +6

    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  11 หลายเดือนก่อน

      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 6 หลายเดือนก่อน +1

    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.

  • @cheapnoiseinthehouse5578
    @cheapnoiseinthehouse5578 10 หลายเดือนก่อน +2

    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  10 หลายเดือนก่อน +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
      th-cam.com/video/565lpAIWjJM/w-d-xo.html

  • @El_IrregularDX
    @El_IrregularDX 10 หลายเดือนก่อน

    This works great! Also, is it possible to get 2 channel stereo audio?

    • @profgallaugher
      @profgallaugher  10 หลายเดือนก่อน +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

  • @cheapnoiseinthehouse5578
    @cheapnoiseinthehouse5578 4 หลายเดือนก่อน +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.

  • @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  ปีที่แล้ว +1

      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!

  • @arash2953
    @arash2953 หลายเดือนก่อน

    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  22 วันที่ผ่านมา

      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

  • @olafschermann1592
    @olafschermann1592 2 หลายเดือนก่อน +1

    Awesome, how easy

  • @matthewfogelson9665
    @matthewfogelson9665 3 หลายเดือนก่อน +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  3 หลายเดือนก่อน

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

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

  • @christianb7494
    @christianb7494 5 หลายเดือนก่อน

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

    • @profgallaugher
      @profgallaugher  5 หลายเดือนก่อน

      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!

  • @michaelzhou5095
    @michaelzhou5095 ปีที่แล้ว +1

    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!

  • @bhavnahar7309
    @bhavnahar7309 หลายเดือนก่อน +1

    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  หลายเดือนก่อน

      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.

  • @ricardorizzato4719
    @ricardorizzato4719 หลายเดือนก่อน

    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.

  • @raphaebaetiong5504
    @raphaebaetiong5504 4 หลายเดือนก่อน

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

    • @profgallaugher
      @profgallaugher  3 หลายเดือนก่อน

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

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

  • @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 ปีที่แล้ว +3

      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.

  • @retrobombstudios1258
    @retrobombstudios1258 7 หลายเดือนก่อน

    would micropython work in place of circuit?

    • @profgallaugher
      @profgallaugher  7 หลายเดือนก่อน

      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 7 หลายเดือนก่อน

      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  7 หลายเดือนก่อน

      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!

  • @geckowingman
    @geckowingman ปีที่แล้ว +1

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

  • @OmTidke-kw2kp
    @OmTidke-kw2kp 2 หลายเดือนก่อน

    Can I play a 10 sec long song on pico.

    • @profgallaugher
      @profgallaugher  หลายเดือนก่อน

      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.