- Prolog
- Create single tone (passive buzzer)
- Create different tones (passive buzzer)
- Play a song (passive buzzer)
Since you have made the first experiences with the GPIO pins (incl. PWM), let's use the knowledge and create acoustic signals (as well as a song).
Please note that the pin assignment of your ESP microcontroller can be different! Adapt the circuit and the value of the corresponding constants.
In fact, in this example, you're just creating a noisy tone with a passive buzzer. Be a little careful and try to be considerate of the people and animals nearby.
- mandatory 1x passive buzzer (Piezo Buzzer)
- few cables
- optional a breadboard
Example
# create new subdirectory
$ mkdir -p ~/Projects/ESP/examples/sound
# create script
$ touch ~/Projects/ESP/examples/sound/passive_buzzer_simple.py
Source Code for
passive_buzzer_simple.py
Check your circuit and copy the script to the microcontroller as main.py
.
# copy file into pyboard as main.py
(venv) $ rshell -p [SERIAL-PORT] cp examples/sound/passive_buzzer_simple.py /pyboard/main.py
# start repl
(venv) $ rshell -p [SERIAL-PORT] repl
Start with keys Control
+ d
. To leave the REPL, press keys Control
+ x
.
You can use PWM
to create different tones! Just use different frequencies.
... same as previous example ...
... same as previous example ...
# create script
$ touch ~/Projects/ESP/examples/sound/passive_buzzer_tones.py
Source Code for
passive_buzzer_tones.py
Check your circuit and copy the script to the microcontroller as main.py
.
# copy file into pyboard as main.py
(venv) $ rshell -p [SERIAL-PORT] cp examples/sound/passive_buzzer_tones.py /pyboard/main.py
# start repl
(venv) $ rshell -p [SERIAL-PORT] repl
Start with keys Control
+ d
. To leave the REPL, press keys Control
+ x
.
The last example is actually a logical conclusion. Do you know Mario?
... same as first example ...
... same as first example ...
# create script
$ touch ~/Projects/ESP/examples/sound/passive_buzzer_tones.py
Source Code for
passive_buzzer_sound.py
Check your circuit and copy the script to the microcontroller as main.py
.
# copy file into pyboard as main.py
(venv) $ rshell -p [SERIAL-PORT] cp examples/sound/passive_buzzer_sound.py /pyboard/main.py
# start repl
(venv) $ rshell -p [SERIAL-PORT] repl
Start with keys Control
+ d
. To leave the REPL, press keys Control
+ x
.