Brainwave Visualization Using ESP32, BioAmpEXG, FastAPI, and Interactive Charts

DevOps & Cloud Engineer — building scalable, automated, and intelligent systems. Developer of sorts | Automator | Innovator
Search for a command to run...

DevOps & Cloud Engineer — building scalable, automated, and intelligent systems. Developer of sorts | Automator | Innovator
Artificial Intelligence has become one of the biggest talking points in software engineering. Every week, a new tool promises to automate deployments, fix production incidents, or replace developers a

You spin up a Kubernetes workload. You connect to PostgreSQL. You add sslmode=require because security matters. And then PostgreSQL replies with: server does not support SSL, but SSL was required Wai

When you first approach Tencent Cloud, it feels familiar if you come from AWS or Azure. There are VPCs, Kubernetes clusters, load balancers, object storage, IAM, everything you would expect. But once

When I first automated Docker builds and deployments, I thought the hard part would be writing the YAML. It was not. The real challenges were versioning, preventing accidental rollbacks, handling envi

For a long time, Docker Compose felt like the perfect solution. Simple YAML, fast local setup, predictable behavior. For a single service or even a small stack, it works beautifully. But at some point, reality catches up. As the application grew, tra...

CodeOps Studies
40 posts
Simple write-ups on day to day code or devops experiments, tests etc.
Monitoring brainwave activity in real time has always fascinated me. I wanted to build something that could collect EEG signals, process them on a lightweight device, and display the results on a clean web dashboard. With an ESP32, a MAX30100 sensor, a small analog EEG input, and a FastAPI backend, I was able to create a portable system that measures Alpha, Beta, and Gamma brainwave bands and visualises them as simple bar graphs.
This article explains how I built the entire pipeline, from data collection to real-time visualisation.
I also wrote a short study based on this and used M5Stack for it:
https://www.researchgate.net/publication/391839761_Short-Term_Neurophysiological_Changes_During_Transcendental_Meditation_A_Pilot_EEG_and_ECG-Based_Study
I wanted a portable and affordable setup that could:
Collect EEG data through a simple analog pin
Compute frequency bands using Fast Fourier Transform
Add additional biometric data from a MAX30100 sensor
Send all readings to a backend server over Wi-Fi
Show clean and simple charts on a dashboard
Make the system completely wireless
The ESP32 Zero 2 WH (or any small ESP32 board) was perfect because it is inexpensive, efficient, and supports both Wi-Fi and continuous sensor sampling.
ESP32 (M5Core2 or Zero 2 WH)
MAX30100 sensor for infrared and red readings, later used ECG Module
EEG analog signal (BioAmpEXG Pill) connected to an ADC pin
Wi-Fi to push data to backend
Power source (USB or portable battery)

MAX30100 SDA → ESP32 SDA pin
MAX30100 SCL → ESP32 SCL pin
EEG analog output → ESP32 ADC pin
Common ground for all components
The MAX30100 is optional for brainwave detection, but I wanted additional IR/RED data to calculate orderliness and signal health. This was the initial choice, but later I switched to AD8232

The ESP32 collects data continuously. Each cycle does the following:
Read raw EEG analog values
Read IR and RED values from MAX30100
Apply Fast Fourier Transform to EEG samples
Extract band powers:
Alpha (8 to 12 Hz)
Beta (12 to 30 Hz)
Gamma (30 to 100 Hz)
Package everything into a JSON payload
Send the JSON data to the FastAPI backend via Wi-Fi
{
"alpha": 42.3,
"beta": 28.1,
"gamma": 10.5,
"orderliness": 0.82,
"ir": 51200,
"red": 50390
}
The backend receives data, stores it, and serves it to the dashboard.
Endpoint for receiving ESP32 JSON data
In-memory store or Redis for fast access
REST endpoint for the dashboard
CORS enabled
Very low latency
from fastapi import FastAPI
from pydantic import BaseModel
class BrainwaveData(BaseModel):
alpha: float
beta: float
gamma: float
orderliness: float
ir: int
red: int
app = FastAPI()
latest_data = BrainwaveData(
alpha=0, beta=0, gamma=0, orderliness=0, ir=0, red=0
)
@app.post("/update")
def update(data: BrainwaveData):
global latest_data
latest_data = data
return {"status": "ok"}
@app.get("/data")
def get_data():
return latest_data

I wanted a clean visualisation with no curves, only bar graphs.
The dashboard uses:
HTML + Bootstrap
Chart.js for bar charts
Auto-refresh using JavaScript
Smooth transitions
Bar graphs work well because brainwave bands are relative.
The magnitude of Alpha versus Beta is the most important insight, and bars make comparison easy.
The dashboard has:
A bar graph for Alpha, Beta, and Gamma
A card showing orderliness
A small panel showing IR and RED values
A refresh interval of 1 second
const ctx = document.getElementById("brainChart");
const chart = new Chart(ctx, {
type: "bar",
data: {
labels: ["Alpha", "Beta", "Gamma"],
datasets: [{
data: [0, 0, 0]
}]
},
options: {
animation: false,
scales: {
y: { beginAtZero: true }
}
}
});
async function refreshData() {
const r = await fetch("/data");
const d = await r.json();
chart.data.datasets[0].data = [d.alpha, d.beta, d.gamma];
chart.update();
}
setInterval(refreshData, 1000);
Here is a graph that I obtained:

ESP32 reads EEG values and MAX30100 values
ESP32 performs FFT and computes band powers
ESP32 sends JSON to FastAPI backend
Dashboard fetches latest data through /data
Chart.js updates the bars in real time
Low-cost EEG is noisy.
I had to apply:
Moving average filters
Calibration
Proper grounding
FFT windowing
To extract accurate brainwave bands, the sampling rate must be stable.
I locked the ESP32 ADC sampling to a consistent interval.
Continuous updates caused stuttering until I disabled animation in Chart.js.
The dashboard provides a clean and real-time visualisation of:
Alpha, Beta, Gamma brain activity
Signal orderliness
Infrared and red biometric data
It works smoothly on both desktop and mobile browsers and updates once every second.
I plan to enhance the system with:
WebSocket streaming instead of polling
A rolling timeline view for long sessions
Support for multiple users
A database for storing and analysing sessions
A machine learning model that detects focus, stress, or calmness
This project showed me how much can be done with simple hardware and a clean backend architecture. By combining an ESP32, BioAmpEXG, FFT analysis, FastAPI, and a lightweight dashboard, it is possible to create a fully portable and real-time brainwave monitoring system.