breadboard
docs

Example project · Builds & projects

ESP32-S31 Ode to joy

RMT on GPIO0 plays the stock Ode to joy score through a passive buzzer. Enable Sound in Settings to listen; pitches and note lengths follow the driver's integer timing. The score plays once. Enable verbose in Serial to see the stock INFO lines. Unmodified ESP-IDF v6.1.1 on the bounded S31 simulator profile; no physical flashing.

The ESP32-S31 Ode to joy circuit as rendered by the simulator

How it works

ESP-IDF's musical_buzzer example turns a list of notes into sound with the RMT peripheral. RMT normally sends short pulse patterns. Here a custom encoder writes one period of a square wave as a single RMT symbol and sets the loop count to duration × frequency / 1000, so each note repeats for the right length of time. The channel ticks at 1 MHz and drives GPIO0.

A passive buzzer needs exactly this kind of signal. It has no oscillator of its own, so it sounds at whatever frequency the square wave has. Its positive lead is on GPIO0 and its negative lead on ground. Every period is a whole number of RMT ticks, so pitches and note lengths follow the driver's integer timing rather than exact musical values. The score is played once, and then the program ends.

What to watch

Turn on Sound in Settings and press Restart to hear the melody from the beginning. Enable verbose in Serial to see the RMT setup messages and Playing Beethoven's Ode to joy.... Open Scope on GPIO0 to see the square wave change its period with each note.

What's on the bench

  • Buzzer
  • ESP32-S31-Function-CoreBoard-1

How it's wired

  • ESP32-S31-Function-CoreBoard-1 · g0→Buzzer · pos
  • ESP32-S31-Function-CoreBoard-1 · gnd→Buzzer · neg

This project runs prebuilt firmware on the emulated board; open it in the simulator to watch it work and inspect every part live.

Try this

  • Restart the board to hear the score again. It plays once per boot.
  • In Scope, compare a high note with a low one. The higher note has the shorter period, and a longer note simply repeats the same period more times.
  • Count the cycles of one note in Scope over a known time. Dividing cycles by time gives the note's frequency, which you can compare with the pitch you hear.

Related projects