PiicoDev Buzzer | Guide For Raspberry Pi

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
let's make some music with the pico dev buzzer module and a raspberry pi we'll get these two connected together run some example code to play some tones and we'll even play some melodies let's do it [Music] i'm using a raspberry pi 4 model b today with a pico dev buzzer a pika dev adapter for raspberry pi and a picket of cable to connect everything together your pi will need to be set up to run like a desktop computer we have a getting started guide for that if you need help plug the adapter onto your pi making sure that the ethernet arrow points towards the ethernet connector on a raspberry pi 3 these connectors are swapped so there will be a usb connector here connect your picodev cable to one of the ports and connect the other end to your buzzer 100 millimeter cables are best for raspberry pi projects to run these examples it's important that these two switches on the front are in their default state that's where both switches are off the two id jumpers on the back of the board should also be open or unsoldered for more information on using picodev modules with these kinds of id switches check out the picodev connection guide and i've mounted everything to this picodev platform to keep it nice and stable power up your pi connect to a network and we'll make sure that we have i squared c enabled first go to preferences raspberry pi configuration and under the interfaces tab make sure that i2c is enabled in the article for this tutorial find the download section to download the example script right click that link save link as and i'm going to save it to a picodev directory in my home directory i'll call it buzzer just for some context navigate to where you downloaded that file and open it in funny and just before we run the script we need to make sure we have picodev installed go to tools manage packages and search for picodev that's with two eyes there it is and just upgrade or install as necessary this script is ready to run so we can just press the green run button or ctrl r to run the script [Music] we had two tones there followed by the same two tones a little bit quieter let's take a look at the code we first import the driver for the pico dev buzzer and we also import a sleep ms function to create a delay in milliseconds we initialize the buzzer as buzz and we initialize it with a volume equal to two there are three volume levels with two being the loudest and zero being the quietest next up we create our tones we call buzz.tone and this takes up to two arguments the first is the frequency of the tone in hertz so this first tone has a frequency of 800 hertz and the second argument is the duration of the tone in milliseconds so this has a half second duration we create a delay and then we create another tone this time at 400 hertz for 500 milliseconds so that's our two tones that high low tone in the middle we call buzz volume 0 so that will set the volume to the lowest level and we do the same thing all over again this time we create our 800 and 400 hertz tones without a duration in buzz.tone this will play the tone continuously until we tell it to stop and we tell it to stop by calling no tone so here we're creating the buzz duration with this sleep function let's remix this code a little bit to create an ascending tone i'll change that 800 to a 300 and change that 400 to a 600 why not let's do the same thing to the other two and press ctrl r to run now let's create a musical melody jump back into the article for this tutorial and find the melodies section and we'll copy out that whole code listing copy that back into funny i'll create a new file paste in all that code and save it as melody let's give it a run with ctrl r nice a short melody looking at the code we perform our usual imports and next up we define some note frequency pairs notes is a python dictionary which is a list of key value pairs here the keys on the left are the names of the notes that we might want to play so here's a d note here's an f here's an a flat and the values are the frequencies for those notes so d has a frequency of 294 hertz that makes it really easy for us to play the frequency of the note that we want by accessing it from this key which has more meaning then we define melody which is a two-dimensional list in python these are the notes that we want to play in our melody and the durations we want to play them for so our first note will be an e and we play that for 500 milliseconds this f down here is played for 250 milliseconds so this is our entire melody we initialize the buzzer as usual and then finally we have a for loop which steps through every element in the melody list extracting the note name and the duration to play that note finally calling buzz.tone with that information and so there you have it a simple way to play a short melody with the pikadev buzzer of course you could then change the definition of this melody to be whatever you like so there you have it a couple of tones and even a simple melody using the pikadev buzzer if you make anything cool out of these starter projects or if you just have some questions let us know on our forums we're full-time makers and here to help until next time thanks for watching [Music]
Info
Channel: Core Electronics
Views: 1,584
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, Programming A Monophonic Buzzer With MicroPython, How To Program A Buzzer For Raspberry Pi, How To Code Piezo Electric Buzzer with Raspberry Pi, Melody, How To Create A Buzzer Melody, How To Use A Buzzer With Raspberry Pi, Monophonic Buzzer, Piezo Electric Buzzer, PiicoDev Buzzer Module, Micropython, PiicoDev, Raspberry Pi
Id: 1PKFvvTRO4w
Channel Id: undefined
Length: 5min 51sec (351 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.