You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A python tool to record data from BioAmp hardware.This project is designed to read data from an Arduino via a serial connection, process the data, and stream it using the Lab Streaming Layer (LSL) protocol. It also logs the processed data to a CSV file for further analysis.
3
+
The BioAmp Tool is a Python script designed to interface with an Arduino-based bioamplifier, read data from it, and optionally log this data to CSV or stream it via the Lab Streaming Layer (LSL).
4
4
5
5
## Features
6
6
7
-
- Auto-detects connected Arduino devices.
8
-
- Reads and processes data packets from Arduino.
9
-
- Streams data via LSL for real-time analysis.
10
-
- Logs data to a CSV file, including counters and channel data.
11
-
- Calculates and logs sampling rate and drift.
12
-
- Handles missing samples and prints relevant errors.
7
+
-**Automatic Arduino Detection:** Automatically detects connected Arduino devices via serial ports.
8
+
-**Data Reading:** Reads ModularEEG P2 format data packets from the Arduino's serial port.
9
+
-**CSV Logging:** Optionally logs data to a CSV file.
10
+
-**LSL Streaming:** Optionally streams data to an LSL outlet for integration with other software.
11
+
-**Verbose Output:** Provides detailed statistics and error reporting.
13
12
14
13
## Requirements
15
14
16
-
- Python 3.7 or higher
17
-
-[pySerial](https://pypi.org/project/pyserial/)
18
-
-[pylsl](https://pypi.org/project/pylsl/)
19
-
-An Arduino device capable of sending serial data packets
1. **Connect your Arduino** to your computer via USB.
30
+
To use the script, you can run it from the command line with various options:
36
31
37
-
2. **Run the script** with the desired options:
38
-
```bash
39
-
python bioamptool.py --detect
40
-
```
32
+
```bash
33
+
python bioamp_tool.py [options]
34
+
```
41
35
42
-
3. **View the output** on your console, which will include minute-by-minute data counts, 10-minute summaries, sampling rate , any detected errors or drift.
36
+
### Options
43
37
44
-
## Command-line Options
38
+
-`-p`, `--port` <port>: Specify the serial port to use (e.g., COM5, /dev/ttyUSB0).
39
+
-`-b`, `--baudrate` <baudrate>: Set the baud rate for serial communication (default is 57600).
40
+
-`--csv`: Enable CSV logging. Data will be saved to a file with a timestamped name.
41
+
-`--lsl`: Enable LSL streaming. Sends data to an LSL outlet.
42
+
-`-v`, `--verbose`: Enable verbose output with detailed statistics and error reporting.
45
43
46
-
- `-d, --detect`: Auto-detect the Arduino COM port.
47
-
- `-p, --port`: Specify the COM port (e.g., `COM3` on Windows or `/dev/ttyUSB0` on Linux).
48
-
- `-b, --baudrate`: Set the baud rate for serial communication (default is `57600`).
49
44
50
-
Example:
51
-
```bash
52
-
python bioamptool.py --detect
53
-
```
45
+
## Script Functions
46
+
47
+
### `auto_detect_arduino(baudrate, timeout=1)`
48
+
49
+
Detects an Arduino connected via serial port. Returns the port name if detected.
50
+
51
+
### `read_arduino_data(ser, csv_writer=None)`
52
+
53
+
Reads and processes data from the Arduino. Writes data to CSV and/or LSL stream if enabled.
54
+
55
+
### `start_timer()`
56
+
57
+
Initializes timers for 10-second and 10-minute intervals.
58
+
59
+
### `log_ten_second_data(verbose=False)`
60
+
61
+
Logs and resets data for the 10-second interval.
62
+
63
+
### `log_ten_minute_data(verbose=False)`
64
+
65
+
Logs data and statistics for the 10-minute interval.
Parses data from Arduino and manages logging and streaming.
70
+
71
+
### `main()`
72
+
73
+
Handles command-line argument parsing and initiates data processing.
54
74
55
75
## Data Logging
56
76
@@ -69,17 +89,17 @@ python bioamptool.py --detect
69
89
-**Sampling Rate**: `250 Hz`
70
90
-**Data Format**: `float32`
71
91
72
-
Use an LSL viewer (e.g., BrainVision Recorder) to visualize the streamed data in real-time.
92
+
Use an LSL viewer (e.g., BrainVision LSL Viewer) to visualize the streamed data in real-time.
73
93
74
94
## Troubleshooting
75
95
76
-
- **Arduino Not Detected**: Ensure your Arduino is properly connected and recognized by your system. Use the `--detect` option to automatically find the Arduino port.
77
-
- **Invalid Data Packets**: If you see messages about invalid data packets, check the data format and synchronization bytes being sent from the Arduino.
78
-
- **Zero LSL Stream Utilization**: If the LSL stream shows 0% utilization, verify the stream is properly set up and data is being pushed to the outlet.
96
+
-**Arduino Not Detected:** Ensure the Arduino is properly connected and powered. Check the serial port and baud rate settings.
97
+
-**CSV File Not Created:** Ensure you have write permissions in the directory where the script is run.
98
+
-**LSL Stream Issues:** Verify that the `pylsl` library is installed and configured correctly.
79
99
80
100
## Contributors
81
101
82
102
We are thankful to our awesome contributors, the list below is alphabetically sorted.
0 commit comments