Python bindings for the Thalmic Labs Myo SDK
Project description
Python bindings for the Myo SDK
Myo-Python is a CFFI wrapper for the Thalmic Myo SDK.
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 myp.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()) - The
myo.init()function provides a few more parameters to control the waylibmyois detected. myo.Feedhas been renamed tomyo.ApiDeviceListener
Projects using Myo-Python
Changes
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
File details
Details for the file myo-python-1.0.3.tar.gz.
File metadata
- Download URL: myo-python-1.0.3.tar.gz
- Upload date:
- Size: 17.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbdacf2fbd543294a03c4d55262b193bae1b8b0aea93202541a5177ec386ba8d
|
|
| MD5 |
4c561e66238a59861b76d34d5afb3581
|
|
| BLAKE2b-256 |
de0c4fd35d8d3840760b1ead18d18c5a96e779b04420e4f50860c1ade3226c56
|