Chords Python script is designed to interface with an Arduino-based bio-potential amplifier, read data from it, optionally log this data to CSV or stream it via the Lab Streaming Layer (LSL), and visualize it through a graphical user interface (GUI) with live plotting.
Note
Flash Arduino code to your hardware from Chords Arduino Firmware to use this python tool.
- Automatic Arduino Detection: Automatically detects connected Arduino devices via serial ports.
- Data Reading: Read data packets from the Arduino's serial port.
- CSV Logging: Optionally logs data to a CSV file.
- LSL Streaming: Optionally streams data to an LSL outlet for integration with other software.
- Verbose Output: Provides detailed statistics and error reporting, including sampling rate and drift.
- GUI: Live plotting of six channels using a PyQt-based GUI.
- Invert: Optionally Invert the signal before streaming LSL and logging
- Timer: Record data for a set time period in seconds.
- Python
pyserial
library (for serial communication)pylsl
library (for LSL streaming)argparse
,time
,csv
,datetime
(standard libraries)pyqtgraph
library (for GUI)PyQt5
librarynumpy
library
-
Ensure you have latest version of Python installed.
-
Create Virtual Environment
python -m venv venv
.\venv\Scripts\activate
-
Install the required Python libraries:
pip install -r chords_requirements.txt
To use the script, run it from the command line with various options:
python chords.py [options]
-p
,--port
: Specify the serial port to use (e.g., COM5, /dev/ttyUSB0).-b
,--baudrate
: Set the baud rate for serial communication. By default the script will first attempt to use 230400, and if that fails, it will automatically fallback to 115200.--csv
: Enable CSV logging. Data will be saved to a timestamped file.--lsl
: Enable LSL streaming. Sends data to an LSL outlet.-v
,--verbose
: Enable verbose output with detailed statistics and error reporting.-t
: Enable the timer to run program for a set time in seconds.
-
CSV Output: The script saves the processed data in a CSV file with a timestamped name.
- The CSV file contains the following columns:
Counter
: The sample counter from the Arduino.Channel1
toChannel6
: The data values from each channel.
- The CSV file contains the following columns:
-
Log Intervals: The script logs data counts every second and provides a summary every 10 minutes, including the sampling rate and drift in seconds per hour.
python gui.py
: Enable the real-time data plotting GUI.
python game.py
: Enable a GUI to play game using EEG Signal.
python heartbeat_ecg.py
:Enable a GUI with real-time ECG and heart rate.
python emgenvelope.py
: Enable a GUI with real-time EMG & its Envelope.
python eog.py
: Enable a GUI with real-time EOG that detects the blinks and mark them with red dot.
python ffteeg.py
: Enable a GUI with real-time EEG data with its FFT.
python keystroke.py
: On running, a pop-up opens for connecting, and on pressing Start, blinks are detected to simulate spacebar key presses.
To run all applications together:
python app.py
Note
Before running, make sure to install all dependencies by running the command:
pip install -r app_requirements.txt
This will launch a Web interface. Use the interface to control the applications:
- Click the
Start LSL Stream
button to initiate the LSL stream. - Then, click on any application button to run the desired module.
ffteeg
: Real-time EEG analysis with FFT and brainwave power calculation.heartbeat_ecg
: Analyze ECG data and extract heartbeat metrics.eog
: Real-time EOG monitoring with blink detection.emgenvelope
: Real-time EMG monitor with filtering and RMS envelope.keystroke
: GUI for EOG-based blink detection triggering a keystroke.game
: Launch an EEG game for 2 players (Tug of War).csv_plotter
: Plot data from a CSV file.gui
: Launch the GUI for real time signal visualization.
- Arduino Not Detected: Ensure the Arduino is properly connected and powered. Check the serial port and baud rate settings.
- CSV File Not Created: Ensure you have write permissions in the directory where the script is run.
- LSL Stream Issues: Verify that the
pylsl
library is installed and configured correctly.
We are thankful to our awesome contributors, the list below is alphabetically sorted.
The audio file used in game.py
is sourced from Pixabay