System Architecture
NeuroFocus has two main components: hardware and firmware. This page explains how they work together.Hardware Architecture
Signal Chain
- Capture electrical brain activity
- Typical signal: 1-100 µV
- Gain: 100x (configured with 100Ω resistor)
- Amplifies weak EEG signals to measurable levels
- High common-mode rejection removes noise
- 24-bit resolution
- Sampling rate: 660 SPS (default)
- External 3.3V reference
- Differential input mode
- Seeed Studio Xiao ESP32-S3
- Handles SPI communication with ADC
- Processes and streams data
- Supports BLE and USB Serial
Power Supply
- Input: USB 5V or battery
- Regulator: TPAP2112K-3.3 LDO
- Output: 3.3V for all components
Firmware Architecture
The V4 firmware uses a component-based design. Each component handles one responsibility.Components
ADS1220Driver- Low-level SPI communication
- ADC initialization and configuration
- Data ready detection
- Raw data reading
- Bluetooth setup and management
- Connection handling
- Data transmission via notifications
- Command reception
- High-level streaming coordination
- Routes data to Serial or BLE
- Manages streaming state
- Processes commands from Serial and BLE
- Unified interface for both sources
- Returns command enums
- Status LED management
- Visual feedback for system state
Data Flow
- ADS1220Driver checks for new data
- EEGStreamer reads raw ADC values
- Data streams to Serial and/or BLE
- CommandHandler processes user commands
- Commands control streaming state
Communication Modes
BLE Mode
When BLE is enabled:- Auto-starts streaming on connection
- Auto-stops on disconnection
- Commands from Serial or BLE
- Data to both Serial and BLE
Serial Mode
When BLE is disabled:- Manual command control only
- Data to Serial only
- Smaller firmware size
- Lower power consumption
Design Patterns
Singleton Pattern- BLEManager uses static instance for callbacks
- EEGStreamer simplifies complex operations
- CommandHandler works with multiple sources
- Components accept dependencies via constructor
Signal Calculations
Electrode to ADC
Input voltage at electrode:V_electrode
After AD8422 amplification:
ADC Output
The ADS1220 converts voltage to a 24-bit signed integer:Expected Values
For typical EEG signals:| Signal (µV) | Amplified (mV) | ADC Value |
|---|---|---|
| 10 | 1.0 | ~2,533,000 |
| 50 | 5.0 | ~12,665,000 |
| 100 | 10.0 | ~25,330,000 |
Memory Management
All components use stack allocation. No dynamic memory means predictable usage and no fragmentation. The BLE stack is managed by the ESP32 library with automatic buffer management.Thread Safety
Key volatile variables:deviceConnected- Modified in ISRcommandAvailable- Modified in callbacklastCommand- Modified in callback
Error Handling
Initialization Failures- Critical failures halt with LED blink pattern
- Non-critical failures log to Serial
- Graceful degradation
- BLE send fails silently if disconnected
- State validation before operations