Play piano on a physical piezo-electric passive buzzer using a serial-connected MCU.
- Computer application
- Graphical piano interface and serial controller
- Configurable number of piano octaves
- Microcontroller mpy script
- Receives note data and controls the buzzer
- User-defined MCU pin via REPL on Linux
preview.mp4
-
Copy the OS-appropriate mcu.py as the main script on the board.
# example using mpremote, copying the linux script mpremote cp mpy/mcu_linux.py :main.py -
Configure the GPIO pin used for the buzzer:
- Linux
- Open the REPL after flashing the script.
- The program will prompt you to choose a GPIO pin.
- Enter the number of the pin connected to the passive piezo buzzer.
- Windows
- On Windows, the serial port cannot be shared between the REPL and the running script, so GPIO selection must be hardcoded.
- The script defaults to GPIO pin 2.
- To use a different pin, edit mcu_windows.py before copying it to the board.
- Linux
-
The microcontroller is now ready to receive note data from the virtual piano.
- Run the main script or executable. A GUI window will open and prompt you for the following information:
- Number of octaves to display on the virtual piano (starting from octave 3)
- Serial port, for example:
- Linux:
/dev/ttyACM0 - Windows:
COM3
- Linux:
- After clicking
DONE, the application will attempt to connect to the microcontroller. - If the connection is successful, the virtual piano interface will appear. The application is then ready to send note data to the microcontroller.
| Dependency | Version | Notes |
|---|---|---|
| Python | 3.13.11 | |
| PyQt6 | 6.10.2 | GUI |
| Pygame | 2.6.1 | Virtual piano framework |
| Pyserial | 3.5 | Sending data to MCU |
| Mpremote | 1.27 | Sending script to MCU |
| Colorama | 0.4.6 | stdout coloring (debug) |
# Linux
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python main.py# Windows (Powershell)
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
python main.py# Linux
pyinstaller \
--onefile \
--add-data "misc:misc" \
--add-data "game/assets:game/assets" \
--name "buzzer_piano" \
main.py
chmod +x dist/buzzer_piano# Windows (Powershell)
pyinstaller `
--onefile `
--noconsole `
--icon=misc\buzzer.icon `
--add-data "misc;misc" `
--add-data "game\assets;game\assets" `
--name "buzzer_piano" `
main.py