Tags:
create new tag
view all tags

The Buzzer shield

The Hardware

The buzzer shield implements a passive buzzer with frequencies up to 1 kHz - 3 kHz. By default it uses data line D5 corresponding to GPIO 14 (GPIUO 18 on the ESP32) but can be configured to a different GPIO line.

wemosBuzzer.png

In order to make the device work a solder bridge for the data line must be installed ( see the 4 double solder blobs on the left hand side of the module. One of these pairs of blobs must be connected).

The software

The buzzer needs a frequency passed to it through a GPIO line (by default the upper solder pair blobs connected corresponding to D5 or GPIO 14. To test the device I wrote a very simple micro Python script sending a 500 Hz square wave to it. This can easily be done through the micro Python PWM class.

Here is the code:

https://afnog.iotworkshop.africa/pub/AFNOG/BuzzerShield/firstTest.py.txt

Dave Hylands has written some micro Python buzzer scripts to play ringtone melodies defined in the RTTTL (Ring Tone Text Transfer Language). These scripts are written for the PyBoard and must be modified to run on the WeMos D1 mini which use the ESP8266 CPU. I found another problem in the ESp8266 PWM driver code for micro Python, limiting the maximum frequency to 1 Khz, too low to play the tunes correctly. It turns out however that the driver can run at frequencies up to ~ 2 kHz and simply modifying the limit to 2 kHz solved the problem. Of course micro Python must be recompiled and re-flashed to enable these higher frequencies.

And here are the scripts playing the ringtones: esp8266Buzzer is the main program relying on the RTTTL class defined in rtttl.py and the songs on RTTTL format defined in songs.py:

https://github.com/uraich/MicroPython_IoTDemos/blob/master/drivers/buzzer/espBuzzer.py

https://github.com/uraich/MicroPython_IoTDemos/blob/master/drivers/buzzer/rtttl.py

https://github.com/uraich/MicroPython_IoTDemos/blob/master/drivers/buzzer/songs.py

rtttl.py and songs.py must be uploaded into the lib directory on the WeMos CPU flash with uPyCraft before being able to run espBuzzer.py. espBuzzer.py plays the Entertainer tune but you easily select another tune by changing a line in the source code.

The cayenne version of the buzzer program:

https://github.com/uraich/MicroPython_IoTDemos/blob/master/cayenne/buzzer/cayenneBuzzer.py

connects to Cayenne and waits for a song number to be played. Since Cayenne only knows 2 control widgets: the push button and the slider, using the Cayenne GUI is not that convenient for the selection of songs. I therefore wrote a QT application, connecting to Cayenne and publishing the song number for the cayenneBuzzer.py program.

Here is the code:

https://github.com/uraich/MicroPython_IoTDemos/tree/master/PC/cayenneBuzzer

and this is how the GUI looks like:

QtBuzzer.png

You first select the tune you want to hear. Pushing the "Play tune" button will send the number of the tune in the list to the Cayenne MQTT broker, which will pass it on to the cayenneBuzzer.py program to play it.

-- Uli Raich - 2019-03-22

Comments

Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng QtBuzzer.png r1 manage 22.8 K 2019-05-17 - 15:46 UliRaich  
Texttxt esp8266Buzzer.py.txt r1 manage 0.7 K 2019-04-05 - 15:05 UliRaich  
Texttxt firstTest.py.txt r1 manage 0.2 K 2019-04-05 - 15:05 UliRaich  
Texttxt rtttl.py.txt r1 manage 3.8 K 2019-04-05 - 15:05 UliRaich  
Texttxt songs.py.txt r1 manage 6.2 K 2019-04-05 - 15:05 UliRaich  
PNGpng wemosBuzzer.png r1 manage 101.1 K 2019-03-22 - 14:15 UliRaich  
Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2019-05-17 - UliRaich
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback