# ESP32-Beamforming
This project demonstrates how to use an ESP32 microcontroller to create a 3-microphone beamforming system using MicroPython and Python. This system can be used to improve the quality of audio recordings by suppressing noise and focusing on the desired sound source.
## Hardware
You will need the following hardware to build this project:
* ESP32 microcontroller board (e.g., ESP32-DevKitC)
* 3x MEMS microphones (e.g., SPH0645LM4H-B)
* Audio amplifier (e.g., PAM8403)
* Speaker
* Microphone stand or tripod
* Breadboard
* Jumper wires
## Software
You will need the following software to program the ESP32 and run the beamforming algorithm:
* MicroPython firmware for ESP32
* Python 3
* NumPy
* SciPy
* PyAudio
## Setup
1. Install MicroPython on the ESP32.
2. Connect the microphones, amplifier, and speaker to the ESP32 according to the schematic diagram.
3. Install Python 3, NumPy, SciPy, and PyAudio on your computer.
## Code
The following code implements the beamforming algorithm. It uses the ESP32 to record audio from the three microphones and then uses NumPy and SciPy to perform the beamforming calculations. The output of the beamforming algorithm is a single audio signal that is focused on the desired sound source.
```python
import micropython
import time
import esp32
# Define the pins to which the microphones are connected
mic1_pin = 32
mic2_pin = 33
mic3_pin = 34
# Create an instance of the ESP32 ADC class
adc = esp32.ADC(mic1_pin)
# Set the ADC resolution to 12 bits
adc.width(12)
# Set the ADC attenuation to 11dB
adc.atten(11)
# Create a list to store the audio samples
samples = []
# Record audio for 1 second
for i in range(1000):
# Read the ADC value from each microphone
sample = adc.read()
# Append the sample to the list
samples.append(sample)
# Convert the list of samples to a NumPy array
samples = np.array(samples)
# Perform beamforming on the audio samples
beamformed_signal = beamform(samples)
# Play the beamformed signal through the speaker
speaker.play(beamformed_signal)
Usage
To use the beamforming system, simply run the Python code on your computer. The code will automatically connect to the ESP32 and start recording audio. The beamformed signal will be played through the speaker.
Troubleshooting
If you are having trouble getting the beamforming system to work, here are a few things to check:
- Make sure that the microphones, amplifier, and speaker are properly connected to the ESP32.
- Make sure that the MicroPython firmware is installed on the ESP32.
- Make sure that Python 3, NumPy, SciPy, and PyAudio are installed on your computer.
- Make sure that the Python code is running on your computer.
If you are still having trouble, please post a question on the MicroPython forum.
Conclusion
This project demonstrates how to use an ESP32 microcontroller to create a 3-microphone beamforming system using MicroPython and Python. This system can be used to improve the quality of audio recordings by suppressing noise and focusing on the desired sound source.