johngammel
Posts: 40
Joined: Mon Jan 23, 2017 7:52 pm
Location: Englewood, FL, US

Need a piezo "buzzer" to output various notification tones during python execution

Tue Oct 12, 2021 4:02 pm

I have a continuously running python program doing some monitoring with a Pi. The Pi is headless and in a sealed box. What I'd like is a recommendation for an inexpensive "speaker" that I can add to the python code to output different tones at events such as startup and state changes. Looking at numerous articles looks like a passive piezo is the easiest to code and work with. If that's true looking for a board mounted 3 pin that has any parts such as 4.4K resistor included. Obviously when the system Pi is just running don't want any output/humming/etc. from the "speaker".

Want it to work with a Zero so I think it's something that uses GPIO.PWM. Recommendations on something that's readily available at a reasonable cost with free shipping?

ame
Posts: 3725
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Need a piezo "buzzer" to output various notification tones during python execution

Tue Oct 12, 2021 4:51 pm

There are probably hundreds of articles about doing this. Here's one:
https://peppe8o.com/use-passive-buzzer- ... ython/amp/

You don't need a resistor. Only two pins are required. There won't be any hum.

Pick a passive buzzer from your favourite vendor. They're very cheap. You might even find one locally. Post a link if you'd like independent verification.

User avatar
scruss
Posts: 4364
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Need a piezo "buzzer" to output various notification tones during python execution

Tue Oct 12, 2021 5:56 pm

Look for something called something like "Computer Internal Speaker Buzzer PC Case Buzzer Desktop Speaker Mainboard for Computer Repairing" or "Mainboard Computer PC Beep Code Internal Speaker Buzzer for Arduino". They're very cheap and include a header that will sit on GPIO pins. They look like this:
spkr.jpg
tiny piezo motherboard speaker on a Pico
spkr.jpg (42.96 KiB) Viewed 281 times
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

johngammel
Posts: 40
Joined: Mon Jan 23, 2017 7:52 pm
Location: Englewood, FL, US

Re: Need a piezo "buzzer" to output various notification tones during python execution

Wed Oct 13, 2021 6:36 pm

I'm looking for something more complex than a beep code speaker. But the more articles I review push me to a 3 wire passive speaker. Some articles also have a resistor added.

How about a Pi 3/zero that I can just buy on "A".com that will let me output varying sounds depending on conditions. I think that also means using GPIO.PWM. I'm of course trying to winnow out bad info and just get stuff.

Obviously I'm trying to keep this very simple a don't want to download libraries/OS code. Just want to use straight python.

ame
Posts: 3725
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Need a piezo "buzzer" to output various notification tones during python execution

Wed Oct 13, 2021 8:32 pm

It doesn't get much simpler than a two-wire passive piezo buzzer.

Most speakers also have two wires, not three. And what is the resistor for? Could you link to the articles that you are looking at? Please state which ones appeal to you, and which don't, and why.

If you want to use an actual speaker you will need a small amplifier. Maybe that's why the circuit has three wires. It's hard to tell without seeing the articles you are referring to.

johngammel
Posts: 40
Joined: Mon Jan 23, 2017 7:52 pm
Location: Englewood, FL, US

Re: Need a piezo "buzzer" to output various notification tones during python execution

Thu Oct 14, 2021 1:51 pm

I don't want a speaker. Just simple tones for various code occurrences - I'm even dabbling with a Zero.

Drilling into "A".com reviews I see some pizeo buzzers are sold as passive but are actually active. There should be a product that I can buy inexpensively on "A" that will work with simple code like this:

# import modules
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)

# define the pin we will attach to
GPIO_PIN = 18
GPIO.setup(GPIO_PIN, GPIO.OUT)

# start at 50 hertz
GPFrequency = 50
pwm = GPIO.PWM(GPIO_PIN, GPFrequency)
pwm.start(50)

while(True):
for GPFrequency in range(5000):
pwm.ChangeFrequency(GPFrequency)

ame
Posts: 3725
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Need a piezo "buzzer" to output various notification tones during python execution

Thu Oct 14, 2021 2:00 pm

Isn't that exactly what is described in the article I linked to? Isn't that what is shown in the picture from scruss?

And yes, there may be some active piezo buzzers that are mis-sold as passive buzzers on Ali. I'd be shocked if that was really the case though. Shocked! Hopefully you won't allow yourself to be misled.

You haven't linked to the articles that are confusing you, so I can't clarify anything for you. Buy a passive buzzer (or rescue one from an electronic musical greetings card). It has two wires (not three), and no resistor.

User avatar
scruss
Posts: 4364
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Need a piezo "buzzer" to output various notification tones during python execution

Thu Oct 14, 2021 5:27 pm

johngammel wrote:
Thu Oct 14, 2021 1:51 pm
There should be a product that I can buy inexpensively on "A" that will work with simple code like this:
There is, and I even gave you the description texts to search for. I'm in a different country, hence I'd be linking to items you can't get. But the descriptions are the same.

I doubt that many of these speakers/buzzers/beepers make an audible noise at 50 Hz. They sound very mushy at low frequencies. Example (from which my picture came): https://twitter.com/scruss/status/1364646879758278657
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

johngammel
Posts: 40
Joined: Mon Jan 23, 2017 7:52 pm
Location: Englewood, FL, US

Re: Need a piezo "buzzer" to output various notification tones during python execution

Thu Oct 14, 2021 6:18 pm

These look like they might be the item - found on "A".com:
Cylewet 10Pcs 5V 2 Terminals Passive Electronic Alarm Buzzer Electromagnetic Beeper AC Impedance for Arduino (Pack of 10) CYT1008

There are a few 2021 reviews - several reviews say reaffirm passive. I can get them in just a week. Look OK?

User avatar
scruss
Posts: 4364
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Need a piezo "buzzer" to output various notification tones during python execution

Thu Oct 14, 2021 7:30 pm

probably, but they don't come with wires or headers. These do, and are like the ones I used:
Amazon.com : Computer Internal Speaker Buzzer PC Case Buzzer Desktop Speaker Mainboard for Computer Repairing

Amazon reviews of cheap things like this are essentially noise: real people don't review these things
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

Return to “Python”