Skip to content

MyoMod/MyoMod-Python-BLE-Interface

Repository files navigation

MyoMod Python BLE Interface

A Python library and example application for interfacing with the MyoMod EMG Armband via Bluetooth Low Energy (BLE).

MyoMod BLE Connection Library

The myomod_ble package provides a simple async stream interface to the MyoMod armband with built-in data recording.

Quick Start

python emg_viewer.py  # Launch GUI example application

Programmatic Usage

import asyncio
from myomod_ble.connection import MyoModBLEClient, EMGDataType

async def run():
   client = MyoModBLEClient()  # or MyoModBLEClient(device_address="XX:XX:XX:XX:XX:XX")
   await client.connect()
   
   # Stream combined raw + filtered data
   async for pkt in client.stream([EMGDataType.COMBINED]):
      print(f"Raw: {pkt.raw}, Filtered: {pkt.filtered}")
      break
   
   # Get recorded data
   data = client.recorded()
   print(f"Recorded {data['raw_sample_count']} raw packets")
   
   await client.disconnect()

asyncio.run(run())

Example Applications

Two example applications are provided to demonstrate different use cases:

1. Simple Console Example (simple_example.py)

A minimal command-line example showing basic library usage:

python simple_example.py

That:

  • Connects to a MyoMod device
  • Streams combined EMG data
  • Accesses recorded data
  • Checks for packet loss

2. GUI Viewer Example (gui_example.py)

A more advanced, PyQt5-based graphical application with real-time visualization:

python gui_example.py

Features:

  • Real-time EMG Visualization: Display 6-channel EMG signals using pyqtgraph (30 FPS)
  • Dual View: Separate tabs for raw (1500 Hz) and filtered (100 Hz) EMG data
  • Built-in Recording: Save EMG data to compressed .npz format
  • Efficient Buffering: Deque-based data management with automatic limiting
  • Clean Example Code: Demonstrates MyoModBLEClient integration with Qt (~350 lines)

What it demonstrates:

  • Qt integration with async BLE operations
  • Real-time plotting with frame rate limiting
  • Recording control and data export
  • Thread-safe signal/slot communication

Installation

Prerequisites

  • Python 3.8 or higher
  • MyoMod Armband device
  • Bluetooth adapter supporting BLE

Setup Instructions

  1. Create a virtual environment (recommended)

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  2. Install dependencies

    pip install -r requirements.txt
  3. Run an example

    python simple_example.py    # Console example
    python gui_example.py       # GUI example

    or

# Setup script
./start_emg_viewer.sh

python simple_example.py    # Console example
python gui_example.py       # GUI example

Platform-Specific Notes

Linux

  • May require additional permissions for BLE access:
    sudo setcap cap_net_raw+eip $(which python)
  • Or run the application with sudo (not recommended for production)

Windows

  • Ensure Windows 10 version 1703 or later for BLE support
  • May need to install Visual C++ redistributables for some packages

macOS

  • macOS 10.14 or later required for BLE support
  • May need to grant Bluetooth permissions in System Preferences

Data Output Format

Recordings are saved as compressed NumPy archives (.npz):

EMG_Measurements/
└── emg_recording_20231212_143022.npz

File Contents:

  • start_time: Recording start timestamp
  • duration: Total recording duration (seconds)
  • raw_sample_count: Number of raw data packets
  • filtered_sample_count: Number of filtered data packets
  • raw_sample_rate: Raw data sampling rate (1500 Hz)
  • filtered_sample_rate: Filtered data rate (100 Hz)
  • chnA, chnB, ..., chnF: Raw channel data arrays
  • filtered: Filtered EMG data array
  • raw_index, filtered_index: Packet indices
  • state: Device state information

Technical Details

BLE Service Information

  • Service UUID: f1f1d764-f9dc-4274-9f59-325fea6d631b
  • Raw EMG UUID: 9c54ed76-847e-4d51-84be-7cf02794de53
  • Filtered EMG UUID: 36845417-f01b-4167-afa1-81b322238fe1
  • Combined EMG UUID: ab92c948-16ed-4ed2-b18e-d4c0a27808fc

Data Specifications

  • Channels: 6 (A, B, C, D, E, F)
  • Sampling Rate: 1500 Hz (raw data)
  • Raw Data: 15 samples per packet per channel
  • Filtered Data: Single value per channel + state
  • Data Format: IEEE 754 32-bit float (little-endian)

Troubleshooting

Application Won't Start

# Install dependencies
pip install -r requirements.txt

# Check Python version (3.8+ required)
python --version

# Test myomod_ble installation
python -c "from myomod_ble.connection import MyoModBLEClient"

BLE Connection Issues

  • Device not found: Ensure MyoMod Armband is powered on
  • Connection fails: Check Bluetooth is enabled
  • Linux permissions: May need BLE access rights
    sudo setcap cap_net_raw+eip $(which python)
  • Permission errors on Linux: Run with appropriate privileges or set capabilities

Performance Issues (GUI Example)

  • High CPU: Check other background processes interfering with Bluetooth

Data Recording Issues

  • Path issues: Use absolute paths or verify relative path is correct

Project Structure

MyoMod-Python-BLE-Interface/
├── myomod_ble/
│   ├── __init__.py
│   └── connection.py          # MyoModBLEClient core library
├── simple_example.py          # Console example (~50 lines)
├── gui_example.py             # PyQt5 GUI example (~350 lines)
├── requirements.txt           # Python dependencies
├── start_emg_viewer.sh        # Setup and launch script
├── README.md                  # This file

Library Architecture

MyoModBLEClient (myomod_ble/connection.py):

  • Async BLE connection and streaming
  • Built-in chunked data recording
  • Packet index tracking for loss detection
  • Support for raw, filtered, and combined data types
  • Automatic device discovery

Example Applications:

  • simple_example.py: Minimal async implementation
  • gui_example.py: Full-featured Qt5 GUI with visualization

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published