A Python library and example application for interfacing with the MyoMod EMG Armband via Bluetooth Low Energy (BLE).
The myomod_ble package provides a simple async stream interface to the MyoMod armband with built-in data recording.
python emg_viewer.py # Launch GUI example applicationimport 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())Two example applications are provided to demonstrate different use cases:
A minimal command-line example showing basic library usage:
python simple_example.pyThat:
- Connects to a MyoMod device
- Streams combined EMG data
- Accesses recorded data
- Checks for packet loss
A more advanced, PyQt5-based graphical application with real-time visualization:
python gui_example.pyFeatures:
- 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
.npzformat - 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
- Python 3.8 or higher
- MyoMod Armband device
- Bluetooth adapter supporting BLE
-
Create a virtual environment (recommended)
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
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- 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)
- Ensure Windows 10 version 1703 or later for BLE support
- May need to install Visual C++ redistributables for some packages
- macOS 10.14 or later required for BLE support
- May need to grant Bluetooth permissions in System Preferences
Recordings are saved as compressed NumPy archives (.npz):
EMG_Measurements/
└── emg_recording_20231212_143022.npz
File Contents:
start_time: Recording start timestampduration: Total recording duration (seconds)raw_sample_count: Number of raw data packetsfiltered_sample_count: Number of filtered data packetsraw_sample_rate: Raw data sampling rate (1500 Hz)filtered_sample_rate: Filtered data rate (100 Hz)chnA,chnB, ...,chnF: Raw channel data arraysfiltered: Filtered EMG data arrayraw_index,filtered_index: Packet indicesstate: Device state 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
- 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)
# 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"- 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
- High CPU: Check other background processes interfering with Bluetooth
- Path issues: Use absolute paths or verify relative path is correct
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
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 implementationgui_example.py: Full-featured Qt5 GUI with visualization