howto: Control passive buzzer

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
roost
Posts: 6
Joined: Wed Jan 16, 2019 10:15 pm

howto: Control passive buzzer

Post by roost » Wed Jan 16, 2019 10:28 pm

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!

User avatar
philwilkinson40
Posts: 63
Joined: Tue Nov 14, 2017 3:11 am
Location: Perth, Australia

Re: howto: Control passive buzzer

Post by philwilkinson40 » 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

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: howto: Control passive buzzer

Post by dhylands » Thu Jan 17, 2019 5:36 pm

This post has a link to some code I put together that works on the pyboard: viewtopic.php?f=14&t=2172&p=12291

roost
Posts: 6
Joined: Wed Jan 16, 2019 10:15 pm

Re: howto: Control passive buzzer

Post by roost » Mon Jan 21, 2019 11:25 am

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?

koufdell
Posts: 4
Joined: Fri Oct 11, 2019 9:17 pm

Re: howto: Control passive buzzer

Post by koufdell » Mon Jan 20, 2020 11:42 am

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()

prathode
Posts: 5
Joined: Tue Feb 01, 2022 1:16 pm

Re: howto: Control passive buzzer

Post by prathode » Thu Feb 17, 2022 7:06 am

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...

User avatar
scruss
Posts: 360
Joined: Sat Aug 12, 2017 2:27 pm
Location: Toronto, Canada
Contact:

Re: howto: Control passive buzzer

Post by scruss » Thu Feb 17, 2022 3:57 pm

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.

Post Reply