Skip to content

Commit f37a603

Browse files
authored
Merge pull request #5 from PayalLakra/bio_amptool
Bio amptool
2 parents a5f5a36 + 1882e26 commit f37a603

File tree

2 files changed

+252
-209
lines changed

2 files changed

+252
-209
lines changed

README.md

Lines changed: 60 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,76 @@
1-
# BioAmp-Tool-Python
1+
## BioAmp-Tool-Python
22

3-
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).
44

55
## Features
66

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.
1312

1413
## Requirements
1514

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
15+
- Python 3.x
16+
- `pyserial` library (for serial communication)
17+
- `pylsl` library (for LSL streaming)
18+
- `argparse`, `time`, `csv`, `datetime` (standard libraries)
2019

2120
## Installation
2221

23-
1. **Clone the repository**:
24-
```bash
25-
git clone https://github.com/upsidedownlabs/BioAmp-Tool-Python.git
26-
```
27-
28-
2. **Install the required Python packages**:
29-
```bash
30-
pip install -r requirements.txt
31-
```
22+
1. Ensure you have Python 3.x installed.
23+
2. Install the required Python libraries:
24+
```bash
25+
pip install pyserial pylsl
26+
```
3227

3328
## Usage
3429

35-
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:
3631

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+
```
4135

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
4337

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.
4543

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`).
4944

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.
66+
67+
### `parse_data(port, baudrate, lsl_flag=False, csv_flag=False, verbose=False)`
68+
69+
Parses data from Arduino and manages logging and streaming.
70+
71+
### `main()`
72+
73+
Handles command-line argument parsing and initiates data processing.
5474

5575
## Data Logging
5676

@@ -69,17 +89,17 @@ python bioamptool.py --detect
6989
- **Sampling Rate**: `250 Hz`
7090
- **Data Format**: `float32`
7191

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.
7393

7494
## Troubleshooting
7595

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.
7999

80100
## Contributors
81101

82102
We are thankful to our awesome contributors, the list below is alphabetically sorted.
83103

84104
- [Payal Lakra](https://github.com/payallakra)
85-
105+

0 commit comments

Comments
 (0)