To convert a brand new ESP32 into a 3-mic beamforming unit using Micropython and normal Python, follow these steps:
-
Gather the necessary hardware:
- ESP32 development board
- Three high-quality microphones (e.g., MEMS or CCM)
- Optional: MIC5217 or similar voltage regulator for power supply
-
Install the necessary libraries:
-
Connect the microphones to the ESP32 pins:
- Mic 1: GPIO12 (ADC1)
- Mic 2: GPIO14 (ADC2)
- Mic 3: GPIO27 (ADC3)
-
Connect the ESP32 to a computer and upload the following Python code:
import machine
import time
import micropython_beamforming as beamforming
# Initialize the beamforming module
beamforming.initialize()
# Set up the microphones
mic1 = machine.ADC(machine.Pin(12))
mic2 = machine.ADC(machine.Pin(14))
mic3 = machine.ADC(machine.Pin(27))
# Initialize the beamforming module with the microphone inputs
beamforming.set_mic_inputs([mic1, mic2, mic3])
# Set up the output speaker
speaker = machine.PWM(machine.Pin(15))
speaker.freq(1600)
# Main loop
while True:
# Capture the audio signals from the microphones and pass them to the beamforming module
audio1 = mic1.read()
audio2 = mic2.read()
audio3 = mic3.read()
signals = [audio1/1676.0, audio2/1676.0, audio3/1676.0]
# Generate the beamforming weights for this frame
weights = beamforming.compute_weights(signals, 90)
# Combine the signals with the generated weights
combined = 0
for I in range(3):
combined += weights[i] * signals[i]
# Write the combined signal to the speaker output
speaker.duty_u16(int(combined*65535))
# Delay between frames
time.sleep_ms(1)
This code sets up the beamforming module, initializes the microphones, and enters the main loop. In the main loop, it captures the audio signals from the microphones, generates the beamforming weights, combines the signals with the weights, and writes the result to the speaker output.
The micropython-beamforming library provides different beamforming algorithms, such as MVDR (Minimum Variance Distortionless Response), and allows for customization of the algorithm parameters.
By following these steps, you should have a working 3-mic beamforming unit based on the ESP32.