- Introduction
- Features
- Hardware Requirements
- Pin Configuration
- Software Dependencies
- Installation
- Usage
- Waveform Types
- Control Modes
- Function Descriptions
- Flowchart
- Customization
- Troubleshooting
- Contributing
This project implements a versatile waveform generator using an ESP32 microcontroller. It generates various types of waveforms with adjustable parameters such as frequency, amplitude, and phase. Additionally, it features sweep and burst modes for more complex signal generation.
- Generate five types of waveforms: Sine, Square, Sawtooth, Triangle, and Pulse
- Adjustable frequency (1-1000 Hz)
- Adjustable amplitude
- Adjustable phase
- Stereo/Mono output mode
- Frequency sweep mode
- Burst mode
- Real-time parameter control via potentiometers and buttons
- I2S output for high-quality audio generation
- ESP32 development board
- 5 x 10k potentiometers
- 4 x push buttons
- I2S DAC (e.g., UDA1334A, PCM5102, or similar)
- Breadboard and jumper wires
Component | ESP32 Pin |
---|---|
Waveform Select Button | GPIO 2 |
Stereo/Mono Mode Button | GPIO 4 |
Sweep Mode Button | GPIO 5 |
Burst Mode Button | GPIO 15 |
Frequency Potentiometer | GPIO 34 (ADC1_CH6) |
Amplitude Potentiometer | GPIO 35 (ADC1_CH7) |
Phase Potentiometer | GPIO 32 (ADC1_CH4) |
Sweep Rate Potentiometer | GPIO 33 (ADC1_CH5) |
Burst Duration Potentiometer | GPIO 36 (ADC1_CH0) |
I2S BCLK | GPIO 26 |
I2S WCLK | GPIO 25 |
I2S DOUT | GPIO 22 |
- Arduino IDE
- ESP32 board support package
- ESP32 I2S library
- Install the Arduino IDE from the official website.
- Add ESP32 board support to Arduino IDE:
- Go to File > Preferences
- Add the following URL to the "Additional Boards Manager URLs" field:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
- Go to Tools > Board > Boards Manager
- Search for "esp32" and install the "ESP32 by Espressif Systems" package
- Clone or download this repository to your local machine.
- Open the
waveform_generator.ino
file in Arduino IDE. - Select your ESP32 board from Tools > Board menu.
- Select the correct port from Tools > Port menu.
- Click the Upload button to compile and upload the code to your ESP32.
- Connect the potentiometers, buttons, and I2S DAC to the ESP32 according to the pin configuration.
- Power up the ESP32 and I2S DAC.
- Use the buttons to select the desired waveform and modes:
- Waveform Select Button: Cycle through available waveform types
- Stereo/Mono Mode Button: Toggle between stereo and mono output
- Sweep Mode Button: Toggle frequency sweep mode on/off
- Burst Mode Button: Toggle burst mode on/off
- Adjust the potentiometers to control various parameters:
- Frequency Potentiometer: Set the base frequency (1-1000 Hz)
- Amplitude Potentiometer: Set the waveform amplitude
- Phase Potentiometer: Adjust the phase of the waveform
- Sweep Rate Potentiometer: Control the speed of frequency sweeping (when sweep mode is enabled)
- Burst Duration Potentiometer: Set the duration between bursts (when burst mode is enabled)
- The generated waveform will be output through the I2S DAC.
- Sine Wave: A smooth, periodic oscillation
- Square Wave: A signal that alternates between two fixed voltage levels
- Sawtooth Wave: A wave that ramps upward and then sharply drops
- Triangle Wave: A wave that ramps up and down symmetrically
- Pulse Wave: Similar to a square wave, but with an adjustable duty cycle (currently set to 10%)
When enabled, the frequency of the waveform will periodically sweep up and down around the base frequency set by the frequency potentiometer. The sweep rate is controlled by the sweep rate potentiometer.
When enabled, the waveform will be generated in short bursts. The duration between bursts is controlled by the burst duration potentiometer.
Initializes serial communication, configures input pins, and sets up the I2S driver.
The main program loop that continuously updates waveform parameters and generates the waveform.
Reads the state of buttons and potentiometers to update the waveform parameters.
Generates the waveform based on the current parameters and outputs it via I2S.
flowchart TD
A[Start] --> B[Setup]
B --> C[Initialize Serial]
C --> D[Configure Pins as Input]
D --> E[Configure I2S]
E --> F{I2S Driver Installed?}
F -->|No| G[Print Error & Halt]
F -->|Yes| H{Set I2S Pins?}
H -->|No| I[Print Error & Halt]
H -->|Yes| J[Print Success]
J --> K[Main Loop]
K --> L[Initialize Default Params]
L --> M[Update Waveform Params]
M --> N{Burst Mode?}
N -->|Yes| O{Burst Active?}
O -->|Yes| P[Generate Waveform]
O -->|No| Q[Check Burst Timer]
Q -->|Expired| R[Activate Burst & Reset Timer]
Q -->|Not Expired| S[Output Silence]
N -->|No| P
P --> T[Write to I2S]
S --> T
T --> M
You can customize the waveform generator by modifying the following aspects of the code:
- Adjust the frequency range by changing the mapping in
updateWaveformParams()
. - Modify the sweep range by adjusting the calculation in
generateWaveform()
. - Change the burst duration or pattern in the
loop()
function. - Add new waveform types by extending the switch statement in
generateWaveform()
.
- If you don't hear any output, check the I2S DAC connections and ensure the amplitude is set high enough.
- If the waveform sounds distorted, try reducing the amplitude or adjusting the I2S configuration.
- If buttons or potentiometers don't seem to work, double-check the pin connections and ensure they are properly pulled up/down.
Contributions to this project are welcome. Please fork the repository and submit a pull request with your improvements.