This is an old revision of the document!


OpenBCI & ESP32

Master: ACES
Student: Razvan Trombitas

1. Project overview

This project uses an EEG headset with 8 channels, of which only 4 are used, to collect EEG signals. The signals are acquired using an OpenBCI Cyton board and transmitted via Bluetooth using a USB dongle to a serial port. The data is then read in real-time from the serial port and processed using an ESP32 microcontroller. The level of attention, concentration, and stress are determined and sent to Firebase for display on graphs. In addition, the EEG waveforms are plotted in real-time for the 4 channels used. A moving average filter and FFT are also applied to the input signal. The code for the project is written using the Arduino IDE.

In terms of data processing, the project uses a number of mathematical calculations to determine the level of attention, concentration, and stress based on the band power values calculated using the FFT.

The project also uses the moving average filter to smooth the raw EEG signals, to reduce noise and high frequency artifacts. This is a common technique used in EEG signal processing.

2. Hardware

3. Software

The code provided includes WiFi, AsyncTCP, ESPAsyncWebServer, WebSerial, string, SPIFFS, Firebase_ESP_Client, and Arduino TFT libraries. It also includes the use of TokenHelper and RTDBHelper for generating tokens and printing RTDB payloads. The code uses a predefined constant for wifi credentials, Firebase project API key, Authorized Email and Corresponding Password, and RTDB URLs. It also has a number of variables for storing and processing EEG data, including arrays for holding EEG data, band power values, and indices for band power calculation.

Additionally, it uses the ESPAsyncWebServer library to handle web requests and the WebSerial library to handle serial communication. The project also includes the use of the Arduino TFT library to perform FFT on the input EEG signals. This allows for the analysis of the frequency content of the signals, which can provide additional information about the brain activity being recorded. The project uses the following formulas to calculate the levels of attention, concentration, and stress:

Attention = [(Alpha_Power + Gamma_Power) / (Delta_Power + Theta_Power + Alpha_Power + Beta_Power + Gamma_Power)] * 100

Concentration = [Beta_Power / (Delta_Power + Theta_Power + Alpha_Power + Beta_Power + Gamma_Power)] * 100

Stress = [(Delta_Power + Theta_Power) / (Delta_Power + Theta_Power + Alpha_Power + Beta_Power + Gamma_Power)] * 100

These lines of code define the formulas used to calculate the levels of attention, concentration, and stress based on the band power values. The Attention level is calculated by taking the sum of the Alpha and Gamma power and dividing it by the sum of all the band powers. The Concentration level is calculated by taking the Beta power and dividing it by the sum of all the band powers. The Stress level is calculated by taking the sum of Delta and Theta power and dividing it by the sum of all the band powers. The band powers are determined using the following code:

 
for (int i = 0; i < NUM_CHANNELS; i++) {
  for (int j = 0; j < NUM_SAMPLES; j++) {
      float freq = j * SAMPLING_RATE / NUM_SAMPLES;
       if (freq >= DELTA_LOW && freq < DELTA_HIGH) {
        deltaPower[i] += pow(eegData[i][j], 2);
       } else if (freq >= THETA_LOW && freq < THETA_HIGH) {
        thetaPower[i] += pow(eegData[i][j], 2);
       } else if (freq >= ALPHA_LOW && freq < ALPHA_HIGH) {
        alphaPower[i] += pow(eegData[i][j], 2);
       } else if (freq >= BETA_LOW && freq < BETA_HIGH) {
        betaPower[i] += pow(eegData[i][j], 2);
       }
  }
}

Where Alpha_Power, Beta_Power, Gamma_Power, Delta_Power, Theta_Power are the band power values for each frequency band in each channel.

The code uses the Firebase_ESP_Client library to communicate with the Firebase Real-time Database (RTDB) to store and retrieve data. The RTDB stores the EEG data, attention, concentration, and stress levels, which are then displayed on graphs. The FirebaseAuth and FirebaseConfig classes are used to authenticate and configure the connection to the RTDB.

A lot of variables for storing and processing EEG data, including arrays for holding EEG data, band power values, and indices for band power calculation. For calculating attention, concentration, and stress level, the project uses some mathematical calculations using band power values. The code also includes a check for the interval of sending data to firebase, and for this purpose, it uses the millis() function to check the elapsed time since the last data was sent.

4. Results and demonstration

In this project, I used WebSerial for debugging purposes. WebSerial allows the user to view the serial output of the ESP32 in a web browser, which helps in identifying and troubleshooting any issues during the development process. This feature was very helpful in debugging the code and making sure that the data was being transmitted and processed correctly.

5. Conclusions

Overall, this project uses several concepts of signal processing, data visualization, and microcontroller programming to create a real-time EEG monitoring system. The use of EEG technology in combination with microcontroller programming and web technologies allows for the collection, processing, and visualization of brain activity data in a convenient and accessible way.

6. References

iothings/proiecte/2022/open_bci_esp32.1674157966.txt.gz · Last modified: 2023/01/19 21:52 by razvan.trombitas
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0