EMG Wristband Data Tools
This repo contains two Python tools for an 8-channel UART EMG wristband:
- `tools/emg_collect_label.py`: live serial logger, labeler, plotter, and automatic trial session runner.
- `tools/train_emg_models.py`: trains and tests several neural network sizes on the collected CSV files.
Install
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt
Tkinter is included with most Windows Python installs. If the GUI fails to import `tkinter`, install a Python distribution that includes Tcl/Tk.
UART Format
The collector expects one ASCII CSV row per sample:
sample_idx,ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8
Example:
1024,512,498,503,510,520,507,499,501
Raw samples are saved unchanged. Filtering, scaling, and feature extraction are only used for the live display.
Collect Data
python tools\emg_collect_label.py
Default hotkeys:
- `S`: start logging
- `X`: stop logging
- `A`: start automatic session
- `Esc`: stop automatic session
- `Ctrl+S`: save CSV files
- `1` to `6`: select gesture label
The automatic session cycles through:
rest, thumb_tap, thumb_swipe_left, thumb_swipe_right, index_flex, pinch
Each trial is saved with active-phase row indices in `trials.csv`. The training script uses only that active phase by default.
Train Models
After saving `samples.csv` and `trials.csv`:
python tools\train_emg_models.py --samples data\samples.csv --trials data\trials.csv --epochs 40
The script trains and tests:
- `mlp_tiny`
- `mlp_small`
- `cnn_tiny`
- `cnn_small`
- `cnn_gru`
It prints accuracy, a confusion matrix, parameter counts, and saves the best model to `runs/best_model.pt`.