EMG-GUI
Real-time acquisition and visualization of OpenBCI EMG signals with Python.
EMG-GUI is a multithreaded Python package built with BrainFlow, Qt, and ModernGL. It displays raw and filtered EMG traces from OpenBCI boards alongside a live spectrogram, with support for recording and playback.
Contents
- Installation
- Practical Examples
- Configuration
- Recording and Markers
- API Reference
- Architecture
- Contributing
- Planned Features
- Tech Debt
- Acknowledgements
- Videos
1. Installation
Requirement: Python 3.9, 3.10, 3.11, 3.12, 3.13, or 3.14.
Choose your operating system and follow the steps in order.
🍎 macOS
-
Install EMG-GUI:
pip install emg-gui
-
Serial OpenBCI boards only — set
serial_portin your script'sOpenBCIConfig. Use the board's/dev/cu.*device path. BrainFlow does not support/dev/tty.*device paths on macOS.
🪟 Windows
-
Install EMG-GUI in PowerShell:
pip install emg-gui
-
Serial OpenBCI boards only — set
serial_portin your script'sOpenBCIConfig. Use the board's assigned port name, such asCOM3.
🐧 Linux — Ubuntu / Debian
-
Install the system dependencies. For Debian and Ubuntu:
sudo apt update sudo apt install \ libgl-dev \ libegl-dev \ libxcb-icccm4 \ libxcb-keysyms1 \ libxcb-xinerama0 \ libxcb-xkb1 \ libxkbcommon-x11-0
-
Install EMG-GUI:
pip install emg-gui
-
Serial OpenBCI boards only — configure port access. Debian and Ubuntu users can join the
dialoutgroup, then sign out and back in for the change to take effect:sudo usermod -aG dialout "$USER"
Set
serial_portin yourOpenBCIConfigin your script to the board's device path, such as/dev/ttyUSB0or/dev/ttyACM0.
Graphics troubleshooting: If the application reports an OpenGL context error, check that your graphics driver provides OpenGL 3.3 or later.
2. Practical Examples
Each script opens raw and filtered EMG traces alongside a live spectrogram. Run it with Python, then click Stream Data to begin. Close the window to exit.
- Synthetic data: try the interface without hardware.
- OpenBCI Cyton: connect a serial board.
- Playback: view a bundled or personal recording.
- Configuration: board types, connection options, and mains frequency.
- Recording and markers: save signals and label movement intervals.
- API reference: methods and properties for use in your own code.
Synthetic data
Source: examples/synthetic_board.py
from emg_gui import (
ConsoleLogger, EMGVisualizerWindow, MainsFrequency,
OpenBCIBoard, OpenBCIBoardType, OpenBCIConfig,
)
def main():
logger = ConsoleLogger()
board = None
try:
config = OpenBCIConfig(board_type=OpenBCIBoardType.SYNTHETIC)
board = OpenBCIBoard(logger=logger, config=config)
EMGVisualizerWindow.run(
logger=logger, board=board, mains_frequency=MainsFrequency.FIFTY_HZ
)
finally:
if board is not None:
board.release()
logger.release()
if __name__ == "__main__":
main()
OpenBCI Cyton
Source: examples/cyton_board.py
Set serial_port to your board's port: for example, /dev/ttyUSB0 on Linux,
/dev/cu.usbserial-… on macOS, or COM3 on Windows. Ports are not detected automatically.
from emg_gui import (
ConsoleLogger, EMGVisualizerWindow, MainsFrequency,
OpenBCIBoard, OpenBCIBoardType, OpenBCIConfig,
)
def main():
logger = ConsoleLogger()
board = None
try:
config = OpenBCIConfig(
board_type=OpenBCIBoardType.CYTON_SERIAL,
serial_port="/dev/ttyUSB0",
polling_interval_ms=40,
turn_off_srb=True,
)
board = OpenBCIBoard(logger=logger, config=config)
EMGVisualizerWindow.run(
logger=logger, board=board, mains_frequency=MainsFrequency.FIFTY_HZ
)
finally:
if board is not None:
board.release()
logger.release()
if __name__ == "__main__":
main()
Playback
Source: examples/playback_recording.py
No board connection is needed. Set board_type to the board used for the
recording; it determines the playback sampling rate. The bundled example uses SYNTHETIC.
from importlib.resources import files
from emg_gui import (
ConsoleLogger, EMGVisualizerWindow, MainsFrequency,
OpenBCIBoardType, PlayBackConfig, PlaybackRecording,
)
def main():
logger = ConsoleLogger()
board = None
try:
recording = files("emg_gui.data") / "train" / "top_fist" / "file_1.csv"
# For your own recording, use its path instead:
# recording = "/home/user/recordings/session.csv"
config = PlayBackConfig(
board_type=OpenBCIBoardType.SYNTHETIC,
file_path=str(recording),
polling_interval_ms=40,
)
board = PlaybackRecording(logger=logger, config=config)
EMGVisualizerWindow.run(
logger=logger, board=board, mains_frequency=MainsFrequency.FIFTY_HZ
)
finally:
if board is not None:
board.release()
logger.release()
if __name__ == "__main__":
main()
File format: numeric, tab-separated rows without a header. Each row is one sample; columns contain EMG channels followed by one marker column. Use zeros in the marker column when there are no markers. Relative paths resolve from your working directory. Playback outputs zeros after the last sample; stop and restart streaming to replay from the beginning.
Configuration
OpenBCIConfig and PlayBackConfig are immutable. Create a new configuration
and data-source instance to change their settings.
OpenBCIConfig
| Parameter | Default | Purpose |
|---|---|---|
board_type: OpenBCIBoardType |
Required | Select the board and its sampling rate/channel layout. |
polling_interval_ms: int |
40 |
Interval between data reads; does not change the board's sampling rate. |
turn_off_srb: bool |
False |
Send SRB-disabling channel commands for a compatible Cyton setup. Leave disabled for other board types. |
serial_port: str |
"" |
Serial device path or COM port. |
ip_address: str |
"" |
Board/network address. |
ip_port: int |
0 |
Network port. |
ip_protocol: int |
0 |
BrainFlow IP protocol value. |
mac_address: str |
"" |
Device MAC address, when required. |
serial_number: str |
"" |
Device serial number, when required. |
timeout: int |
0 |
BrainFlow discovery/connection timeout. |
other_info: str |
"" |
Additional board-specific connection information. |
Connection fields are passed directly to BrainFlow. Supply the fields required by your board's connection instructions.
OpenBCIBoardType
| Connection | Enum members |
|---|---|
| Serial / dongle | CYTON_SERIAL, CYTON_DAISY_SERIAL, GANGLION_DONGLE |
| Native Bluetooth | GANGLION_NATIVE |
| Wi-Fi | CYTON_WIFI, CYTON_DAISY_WIFI, GANGLION_WIFI |
| Generated data | SYNTHETIC |
PlayBackConfig
| Parameter | Default | Purpose |
|---|---|---|
board_type: OpenBCIBoardType |
Required | Board whose sampling rate matches the recording. |
file_path: str |
"" |
Path to the recording; supply an existing file. |
polling_interval_ms: int |
40 |
Playback read interval; samples per read follow the board's sampling rate. |
EMGVisualizerWindow.run(logger, board, mains_frequency)
Pass a ConsoleLogger, an OpenBCIBoard or PlaybackRecording, and either
MainsFrequency.FIFTY_HZ or MainsFrequency.SIXTY_HZ for mains-noise removal.
Use the enum members, not the numbers 50 or 60. This call creates the Qt
application and blocks until the window closes. Run it on the main thread;
release the board and logger afterwards, as shown above.
Recording and markers
For a live or synthetic board:
- Click Stream Data, then choose a dataset split and label in the dropdowns.
- Click Record to begin collecting raw EMG and marker samples.
- Click Start Movement and Stop Movement to mark an activity interval.
- Click Recording to stop and save, before stopping the stream or closing the window.
Files are saved relative to your working directory as
data/<split>/<label>/<timestamp>__<label>.csv. Create the destination directory
before saving; for example, for split train and label top_fist:
from pathlib import Path
Path("data/train/top_fist").mkdir(parents=True, exist_ok=True)
Splits are train, validate, and test; label choices come from the bundled
dataset folders. Saved files contain raw signals and a final marker column,
not the filtered display traces. Reset clears the display buffer.
Playback supports viewing existing recordings; recording and saving during
playback are not implemented.
API reference
The GUI handles these operations for you. Use them directly when acquiring data without the window; avoid concurrent reads while the GUI is streaming.
Method on board |
Behavior |
|---|---|
start_stream() / stop_stream() |
Start/stop acquisition or playback. Repeating the current state raises RuntimeError. |
get_data() |
Return a NumPy array shaped (EMG channels + 1, samples), with markers in the last row. Live reads consume available buffered samples. |
extract_emg_data(data) |
Return only the EMG rows. |
start_recording() / stop_recording() |
Enable/disable accumulation; these calls do not read samples or save a file. |
record(data) |
Append a get_data() batch while recording is enabled. Call this on each read when working without the GUI. |
insert_start_marker() / insert_stop_marker() |
Mark movement start/end with 1.12345 / 2.12345. |
write_to_csv(datasplit, folder) |
Save accumulated batches to the directory described above and clear them. Requires collected data and an existing directory. |
release() |
Stop a live stream and release its board session. |
Recording and movement methods also raise RuntimeError on repeated
start/stop transitions. On PlaybackRecording, record(), write_to_csv(),
and release() do nothing; movement methods change state without editing file markers.
| Read-only property | Meaning |
|---|---|
emg_channel_count |
Number of EMG channels, excluding the marker channel. |
sampling_rate |
Board sampling rate in Hz. |
polling_interval_ms |
Configured interval between reads. |
is_streaming |
Whether acquisition/playback is started. |
is_recording |
Whether recording is enabled. |
is_active |
Whether a movement interval is active. |
ConsoleLogger() provides info(message), error(message), and release().
You may pass your own logger with these three methods. A custom data source
must provide the methods and properties listed above; see the
DataSource contract.
3. Architecture
See the architecture guide for the component overview, directory layout, data flow, and thread interactions.
4. Contributing
Contributions are welcome! See CONTRIBUTING.md for the development and linting workflow, planned features, and tech debt.
Report reproducible problems through GitHub Issues, including your operating system, Python and package versions, and the full error output.
5. Acknowledgements
4.1 BrainFlow
This project uses BrainFlow for biosignal acquisition and hardware integration. BrainFlow provides a uniform API for acquiring, parsing, and analyzing EEG, EMG, ECG, and other biosensor data across a wide range of supported boards, including OpenBCI devices. BrainFlow is distributed under the MIT License.
4.2 ModernGL Spectrogram
This project uses nickcercone/spectrogram as a reference for parts of its ModernGL spectrogram rendering implementation. The referenced project demonstrates real-time audio spectrogram visualization using ModernGL and is distributed under the MIT License.
4.3 Text Rendering
This project adapts the code in How to render text with PyOpenGL? by exiled (question) and Rabbid76 (answer) for its ModernGL text renderer. The referenced contributions demonstrate text rendering with PyOpenGL and are distributed under the CC BY-SA 4.0 License.
Videos
Watch demos and tutorials on EMGAbility on YouTube.
Metadata
Release files for emg-gui 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| emg_gui-0.1.7.tar.gz | 2.4 MB | With provenance | Details for emg_gui-0.1.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| emg_gui-0.1.7-py3-none-any.whl | Python 3 | none | any | Details for emg_gui-0.1.7-py3-none-any.whl |
Total release size: 4.8 MB
Release files / emg_gui-0.1.7.tar.gz
| Download URL | emg_gui-0.1.7.tar.gz |
|---|---|
| Size | 2.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
845f7fcb98537893341d964c0786a1f2ed7fe64ebf90335dcec762f748cf5d43
|
|
BLAKE2b-256 checksum How to use checksums |
437e48f1da11e2117df4bf366374121d917c8b98c75110c041bd93b06472c90b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.
Transparency logRelease files / emg_gui-0.1.7-py3-none-any.whl
| Download URL | emg_gui-0.1.7-py3-none-any.whl |
|---|---|
| Size | 2.4 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3442276a2d8ac4cbed06540835bc6236f91fdec501bea5e3fe4f4381fc7ac590
|
|
BLAKE2b-256 checksum How to use checksums |
1faccc9b3e5df8698b99cc08ea34583ad84aed6dc7b2272556ec121f76d9bdaa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.
Transparency logSecurity for emg-gui 0.1.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for emg_gui-0.1.7.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.