Skip to content

Latest commit

 

History

History
124 lines (76 loc) · 3.31 KB

007_sound_tutorials.md

File metadata and controls

124 lines (76 loc) · 3.31 KB

Sound

Table of Contents

Prolog

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.

Create single tone (passive buzzer)

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.

Requirements

  • mandatory 1x passive buzzer (Piezo Buzzer)
  • few cables
  • optional a breadboard

Example

piezo_buzzer.jpg

Circuit

010_circuit_diagram_passive_buzzer.png

Code

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

Create different tones (passive buzzer)

You can use PWM to create different tones! Just use different frequencies.

Requirements

... same as previous example ...

Circuit

... same as previous example ...

Code

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

Play a song (passive buzzer)

The last example is actually a logical conclusion. Do you know Mario?

Requirements

... same as first example ...

Circuit

... same as first example ...

Code

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

Home | Previous | Next