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 but can be configured to a different GPIO line.
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://afnog.iotworkshop.africa/pub/AFNOG/BuzzerShield/esp8266Buzzer.py.txt
https://afnog.iotworkshop.africa/pub/AFNOG/BuzzerShield/rtttl.py.txt
https://afnog.iotworkshop.africa/pub/AFNOG/BuzzerShield/songs.py.txt
--
Uli Raich - 2019-03-22
Comments