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!
howto: Control passive buzzer
- philwilkinson40
- Posts: 63
- Joined: Tue Nov 14, 2017 3:11 am
- Location: Perth, Australia
Re: howto: Control passive buzzer
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
https://micropython-on-wemos-d1-mini.re ... ml#beepers
Re: howto: Control passive buzzer
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
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?
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
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()
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
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.philwilkinson40 wrote: ↑Thu Jan 17, 2019 4:32 pmPWM. 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
Any ideas or thoughts and advices are welcomed...