Lab 8 Building a 4-Key Digital Piano using Sine Wave Output
In this lab we created a 4-key digital piano, where each button press plays a distinct tone (C, D, E, G) using ESP32-S3 and generated sine wave.
Initial Circuit Design
The key idea of this system is to create a digital-to-anolog converter (DAC), which uses certain resistors for the conversion. The value of resistor was selected based on the GPIO pin with low pin having high resistor value.
- GPIO1 - 3.3KΩ + 4.7KΩ
- GPIO2 - 2.2KΩ + 2.2 KΩ
- GPIO3 - 2.2KΩ
- GPIO4 - 1KΩ

With the help of our professor Dr.Mahdi Pedram, after some debugging we were able to generate sine wave in the oscilloscope.

Generating Audio on 4-keys
The hardware timer API for the ESP32 with functions such as timerBegin(), timerAttachInterrupt(), and timerAlarm() were used in the code. Audio output connector which was given in the class was used in the breadboard circuit. Since james and I have setup two different circuit there are some differences in the connection but overall output is same.
Final circuit is shown below,
Demo
First video shows the basic functionality of synthesizer and the second video, James connected it to his guitar rig and experimenting with different effects (professionalism of a pro).
Code
Final code for the lab can be downloaded here.