Python bindings for the Thalmic Labs Myo SDK.
Project description
Announcements
[Oct 15, 2018] Thalmic Labs have announced the discontinuation of the Myo armband. Software that used to be accessible on the Thalmic downloads page can be found on the GitHub releases page.
[Jun 28, 2018] Myo-Python 1.0 has been released. It comes with a number of API changes. If you have been following an older tutorial, you might have the new version installed but use code that worked with the old version.
Check the Migrating from v0.2.x section below.
Python bindings for the Myo SDK
Myo-Python is a CFFI wrapper for the Thalmic Myo SDK. Minimum required Python version is 3.5.
Table of Contents
Documentation
The documentation can currently be found in the docs/ directory in the
GitHub Repository.
Example
Myo-Python mirrors the usage of the Myo C++ SDK in many ways as it also
requires you to implement a DeviceListener that will then be invoked for
any events received from a Myo device.
import myo
class Listener(myo.DeviceListener):
def on_paired(self, event):
print("Hello, {}!".format(event.device_name))
event.device.vibrate(myo.VibrationType.short)
def on_unpaired(self, event):
return False # Stop the hub
def on_orientation(self, event):
orientation = event.orientation
acceleration = event.acceleration
gyroscope = event.gyroscope
# ... do something with that
if __name__ == '__main__':
myo.init(sdk_path='./myo-sdk-win-0.9.0/')
hub = myo.Hub()
listener = Listener()
while hub.run(listener.on_event, 500):
pass
As an alternative to implementing a custom device listener, you can instead
use the myo.ApiDeviceListener class which allows you to read the most recent
state of one or multiple Myo devices.
import myo
import time
def main():
myo.init(sdk_path='./myo-sdk-win-0.9.0/')
hub = myo.Hub()
listener = myo.ApiDeviceListener()
with hub.run_in_background(listener.on_event):
print("Waiting for a Myo to connect ...")
device = listener.wait_for_single_device(2)
if not device:
print("No Myo connected after 2 seconds.")
return
print("Hello, Myo! Requesting RSSI ...")
device.request_rssi()
while hub.running and device.connected and not device.rssi:
print("Waiting for RRSI...")
time.sleep(0.001)
print("RSSI:", device.rssi)
print("Goodbye, Myo!")
Migrating from v0.2.x
The v0.2.x series of the Myo-Python library used ctypes and has a little
bit different API. The most important changes are:
- The
Hubobject no longer needs to be shut down explicitly - The
DeviceListenermethod names changed to match the exact event name as specified by the Myo SDK (eg. fromon_pair()toon_paired()) Hub.run(): The order of arguments is reversed (handler, duration_msinstead ofduration_ms, handler)myo.init(): Provides a few more parameters to control the waylibmyois detected.myo.Feed: Renamed tomyo.ApiDeviceListener
Projects using Myo-Python
- Myo Matlab
- hayanalibhatti/Finger-Movement-Classification-via-Machine-Learning-using-EMG-Armband-for-3D-Printed-Robotic-Hand
Changes
v1.0.4 (2019-04-29)
- Remove myo.quaternion, it was a leftover and the Quaternion class was actually in myo.types.math
- move myo.types.math and myo.types.macaddr to myo package instead
- myo.types package is now a stub for backwards compatibility
- Depend on
enum34package instead ofnr.types.enumwhich has been removed innr.types>=2.0.0 - Update the error message of a
ValueErrorraised inmyo.init()
v1.0.3 (2018-06-28)
Event.mac_addressnow returnsNoneif the event's type isEventType.emg(#62)Hub.run()now acceptsDeviceListenerobjects for its handler parameter. This carries over toHub.run_forever()andHub.run_in_background().- Replace requirement
nr>=2.0.10,<3in favor ofnr.types>=1.0.3
v1.0.2 (2018-06-09)
- Fix
Event.warmup_result(PR #58 @fribeiro1)
v1.0.1 (2018-06-09)
- Fix
Event.rotation_on_arm(#59)
v1.0.0 (2018-06-03)
- Rewrite using CFFI
This project is licensed under the MIT License.
Copyright © 2015-2018 Niklas Rosenstein
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file myo-python-1.0.5.tar.gz.
File metadata
- Download URL: myo-python-1.0.5.tar.gz
- Upload date:
- Size: 21.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36e1e2c182ebeb39d7fbb55618bdc86355fa379c72a0f4918624d83e0e0996c8
|
|
| MD5 |
db785bfb580a62e45b6320984c6f69c2
|
|
| BLAKE2b-256 |
bb5b76aa8418a18c198472b7b9e61a9b5d9e80205e31aeefe5b2260acc97bfb0
|
File details
Details for the file myo_python-1.0.5-py3-none-any.whl.
File metadata
- Download URL: myo_python-1.0.5-py3-none-any.whl
- Upload date:
- Size: 23.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b61c9b37134131cfcc2fc96405c17b4b054a3a9082f65f60ae515dd7e8c4212
|
|
| MD5 |
af90305db91f30cbae48194cb0a62c47
|
|
| BLAKE2b-256 |
e3c30c5ad5d2d05f4b59dc77f13872c726793e3c19cfefba1a75c23a376d4fe9
|