PiicoDev Buzzer | Raspberry Pi Pico Guide

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
i'm going to show you how to play tones and even melodies with your picodev buzzer from a raspberry pi pico we'll get these two connected and get it working let's get started [Music] you'll of course need a raspberry pi picker with the pin soldered facing down a pikadev buzzer and expansion board for raspberry pi pico and a picket of cable to connect everything together before we get started just make sure both these switches are in the off position that's the farthest to the left you can see here that the switches are closest to the numbers not the on on the back side make sure these two pads are unsoldered this will be how your buzzer arrives from the factory plug your pico into the expansion board making sure the usb connector is on the same side as the two pin battery connector connect the cable and connect your buzzer to the other end and i've just mounted everything to this pikadev platform to keep it nice and stable connect to your computer with a usb cable in the download section of the article find the three files we need to download right click and save link as i'm saving these to a picodev directory in my documents we'll be working with thony for this tutorial if you've never programmed a pico anthony before check out our getting started guide for that open thoni navigate to where you saved your files and connect to your pico click the first file hold shift click the last file right click and upload to this will upload all the files to our pico and if we open main we can see what we're about to run the script is ready to go so press ctrl d to reboot your pico and listen for the buzzer taking a look at the script we import the buzzer driver package and we also import a function to create a delay sleep ms we initialize our picodev buzzer as buzz and we initialize it with the volume parameter 2 that's the loudest setting then we call buzz.tone and this takes up to 2 arguments the first is the frequency of the tone in hertz and the second is the duration of the tone in milliseconds so here we create an 800 hertz tone for half a second we sleep for half a second and then we create a 400 hertz tone for 500 milliseconds and this is the low tone that we hear so we have a high tone and then a low tone after a longer delay we change the volume to the quieter setting we set it to zero and then we play those same two tones again for the same durations this time however we're passing only the frequency into tone and in this case the tone will sound continuously until we call no tone so by sleeping for 500 milliseconds and calling no tone we create the same effect as if we had just called buzz tone with both arguments and again we create a high tone and a low tone let's change these tones i'll go from say 300 to maybe 600 [Music] and we'll do the same again now when we run the script now we have like an ascending sequence to our tone because we're playing a low tone to a high tone return to the article and we'll go to the melodies example now copy all of this code and paste it into main i'll just highlight everything in main and paste over it and let's give it a run clearly this is an example to play a melody we do our normal imports here we're creating a python dictionary called notes and this is a definition of name and frequency pairs so the f note is 349 hertz in this dictionary next we create a two-dimensional list called melody which is the sequence of notes to play for given durations so here our first note is an e played for 500 milliseconds our third note is c4 played for 500 milliseconds this rest note is defined as 0 hertz and so that just means play nothing for 500 milliseconds if you pass tone 0 for the frequency it will play silence so we have our melody defined as all of these notes and durations we set up our buzzer as usual and then we have a for loop where we loop through the melody list starting at the top working all the way to the bottom we extract the note name we extract the duration and then we play that note for that duration so for the first note in the melody note name is e and so we access our notes dictionary with for the e entry so we go to our notes dictionary grab the e entry and that is 330 hertz so this first argument resolves as 330 hertz and the duration we extracted is just that 500 milliseconds and so you'll notice there are some different duration notes here this f for example only plays for 250 milliseconds that's how we can create that faster beat there you have it some useful examples for getting started with the pico dev buzzer we can play basic notes and we can even play melodies if you make something cool from these startup projects or if you just have some questions let us know on the forums we're full-time makers and here to help catch you next time [Music] you
Info
Channel: Core Electronics
Views: 3,461
Rating: undefined out of 5
Keywords: How To Program A Melody For A Piezo Electic Buzzer With MicroPython, How To Code A Piezo Electic Buzzer With MicroPython For Raspberry Pi Pico, Programming A Monophonic Buzzer With MicroPython, How To Program A Buzzer For Raspberry Pi Pico, How To Code Piezo Electric Buzzer with Raspberry Pi Pico, Melody, How To Create A Buzzer Melody, How To Use A Buzzer With Raspberry Pi Pico, Monophonic Buzzer, Piezo Electric Buzzer, PiicoDev Buzzer Module, Micropython, PiicoDev, Raspberry Pi Pico
Id: bJVNKOmJQM8
Channel Id: undefined
Length: 5min 28sec (328 seconds)
Published: Wed Nov 17 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.