Page 1 of 1

howto: Control passive buzzer

Posted: Wed Jan 16, 2019 10:28 pm
by roost
Hello,

I am quite new to Micropython and i can't figure out how to control a passive buzzer (https://www.aliexpress.com/item/GREATZT ... f4ece250eb) from Micropython.

I found out the PWM class, but this only supports up to 1khz.
On arduino i can just use the tone() library.

My question is, how can i get this to work in Micropython?

Thanks!

Re: howto: Control passive buzzer

Posted: Thu Jan 17, 2019 4:32 pm
by philwilkinson40
PWM. This tutorial should give you a helping hand if you have an esp board. Esp boards do have a lower frequency limit, if you need higher try the pyboard.
https://micropython-on-wemos-d1-mini.re ... ml#beepers

Re: howto: Control passive buzzer

Posted: Thu Jan 17, 2019 5:36 pm
by dhylands
This post has a link to some code I put together that works on the pyboard: viewtopic.php?f=14&t=2172&p=12291

Re: howto: Control passive buzzer

Posted: Mon Jan 21, 2019 11:25 am
by roost
Thanks for the answers!

It is working now. I am using a esp8266 btw, so not a pyboard.

The example on https://micropython-on-wemos-d1-mini.re ... ml#beepers is working. But there is one problem. If i set the beeper.freq to 0, there is a clicking sound. How can i fix this?

Re: howto: Control passive buzzer

Posted: Mon Jan 20, 2020 11:42 am
by koufdell
one solution i used is to make the buzzer init then deinit when needed
example with magnetic reed switch
from machine import Pin , PWM
import utime
# O closed 1 open

al = Pin(4,Pin.IN,Pin.PULL_UP)

while True :
if al.value() == 1 :
beeper = PWM(Pin(14, Pin.OUT), freq=440, duty=512)
utime.sleep(1)
beeper.deinit()

Re: howto: Control passive buzzer

Posted: Thu Feb 17, 2022 7:06 am
by prathode
philwilkinson40 wrote:
Thu Jan 17, 2019 4:32 pm
PWM. This tutorial should give you a helping hand if you have an esp board. Esp boards do have a lower frequency limit, if you need higher try the pyboard.
https://micropython-on-wemos-d1-mini.re ... ml#beepers
Hi, I would like to know if there is any way to use buzzer without PWM. I am using an I2C expander (pcal6416a) which is connected b/w buzzer and ESP32. I am new to this so have no idea how to use PWM with i2c expander (pcal6416a) to initiate buzzer with it.

Any ideas or thoughts and advices are welcomed...

Re: howto: Control passive buzzer

Posted: Thu Feb 17, 2022 3:57 pm
by scruss
prathode wrote:
Thu Feb 17, 2022 7:06 am
how to use PWM with i2c expander (pcal6416a) to initiate buzzer with it.
The pcal6416a doesn't support PWM. The best you could do is toggle a port on it as fast as you can. This is unlikely to sound good.