Skip to content

Commit 917d5e9

Browse files
committed
Update readme
1 parent 5a4e230 commit 917d5e9

File tree

2 files changed

+72
-55
lines changed

2 files changed

+72
-55
lines changed

README.md

Lines changed: 72 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,103 @@
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 Lab Streaming Layer (LSL). It provides real-time data processing and statistical analysis over 10-second and 10-minute intervals.
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 and processes data packets from the Arduino.
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., COM3, /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
5446

55-
## Data Logging
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.
5658

57-
- **CSV Output**: The script saves the processed data in a CSV file named `packet_data.csv`.
58-
- The CSV contains the following columns:
59-
- `Counter`: The sample counter from the Arduino.
60-
- `Channel1` to `Channel6`: The data values from each channel.
59+
### `log_ten_second_data(verbose=False)`
6160

62-
- **Log Intervals**: The script logs data counts every minute and provides a summary every 10 minutes, including the sampling rate and drift in seconds per hour.
61+
Logs and resets data for the 10-second interval.
6362

64-
## LSL Streaming
63+
### `log_ten_minute_data(verbose=False)`
6564

66-
- **Stream Name**: `BioAmpDataStream`
67-
- **Stream Type**: `EXG`
68-
- **Channel Count**: `6`
69-
- **Sampling Rate**: `250 Hz`
70-
- **Data Format**: `float32`
65+
Logs data and statistics for the 10-minute interval.
7166

72-
Use an LSL viewer (e.g., BrainVision Recorder) to visualize the streamed data in real-time.
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.
74+
75+
## Data Logging
76+
77+
-CSV Output: The script saves the processed data in a CSV file named data_%Y-%m-%d_%H-%M-%S.csv.
78+
79+
The CSV contains the following columns:
80+
-Counter: The sample counter from the Arduino.
81+
Channel1 to Channel6: The data values from each channel.
82+
-Log Intervals: The script logs data counts every minute and provides a summary every 10 minutes, including the sampling rate and drift in seconds per hour.
83+
84+
### LSL Streaming
85+
86+
Stream Name: BioAmpDataStream
87+
Stream Type: EXG
88+
Channel Count: 6
89+
Sampling Rate: 250 Hz
90+
Data Format: float32
91+
Use an LSL viewer (e.g., BrainVision LSL Viewer) to visualize the streamed data in real-time.
7392

7493
## Troubleshooting
7594

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.
95+
- **Arduino Not Detected:** Ensure the Arduino is properly connected and powered. Check the serial port and baud rate settings.
96+
- **CSV File Not Created:** Ensure you have write permissions in the directory where the script is run.
97+
- **LSL Stream Issues:** Verify that the `pylsl` library is installed and configured correctly.
7998

8099
## Contributors
81100

82-
We are thankful to our awesome contributors, the list below is alphabetically sorted.
83-
84-
- [Payal Lakra](https://github.com/payallakra)
101+
We are thankful to our awesome contributors.
85102

103+
@PayalLakra

bioamptool.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def auto_detect_arduino(baudrate, timeout=1):
5555
Automatically detects the Arduino by scanning all available serial ports.
5656
Args:baudrate (int): The baud rate for serial communication.
5757
timeout (int): Timeout for the serial connection attempt.
58-
Returns:str: The port name if Arduino is detected, else None.
5958
"""
6059
ports = serial.tools.list_ports.comports() # Get a list of all available serial ports
6160
for port in ports: # Iterate over each port

0 commit comments

Comments
 (0)