-
Notifications
You must be signed in to change notification settings - Fork 32
Getting started
This tutorial assumes you have the Myo dongle pictured below.
PyoMyo uses the dongle included to communicate with the Myo. PyoMyo communicates to the dongle over serial which then sends BLE packets to the Myo.
Plug the blue dongle into your PC and slide the Myo up to your forearm, if the Myo is charged the motion will cause it to turn on and light the onboard LEDs.
The git repo includes the library and some examples to plot some EMG values from the Myo, open a terminal and run the commands below:
git clone https://github.com/PerlinWarp/pyomyo.git
# Install pyomyo and its only dependency pyserial.
pip install pyomyo
cd pyomyo/examples
# Make sure to run this command in Command prompt / bash NOT git bash
python plot_emgs.py
The Myo should vibrate and a plot of the live EMG values should be displayed on your screen.
Try tensing muscles in your hand and watch the values change.
Once you're ready to move on click inside the terminal and press CTRL + C
to exit.
If this did not work, see Common Problems.
pyomyo includes a very simple classifier (simple_classifier.py
) that can be used in real time. dino_jump.py
shows how we can use that to generate keypresses to play games. When the classifier is running, clicking inside the pygame window and pressing a numerical key from 0 to 9 will label the data from the Myo as a class from 0 to 9 and save them in the data/
directory as numpy arrays.
To get started open dino_jump.py
in your favorite text editor and read the tutorial at the top.
Try the tutorial out and experiment, you could:
- Try different gestures out to trigger the jump.
- Try training data on one hand, then moving the Myo or switching hands to see if it still works.
- Try adding more keypresses to the dino_handler and expand the code to work on other games, like space invaders.
Here is a basic example of using the PyoMyo in a multithreaded way to print out EMG readings:
import multiprocessing
from pyomyo import Myo, emg_mode
# ------------ Myo Setup ---------------
q = multiprocessing.Queue()
def worker(q):
m = Myo(mode=emg_mode.RAW)
m.connect()
def add_to_queue(emg, movement):
q.put(emg)
m.add_emg_handler(add_to_queue)
def print_battery(bat):
print("Battery level:", bat)
m.add_battery_handler(print_battery)
# Orange logo and bar LEDs
m.set_leds([128, 0, 0], [128, 0, 0])
# Vibrate to know we connected okay
m.vibrate(1)
"""worker function"""
while True:
m.run()
print("Worker Stopped")
# -------- Main Program Loop -----------
if __name__ == "__main__":
p = multiprocessing.Process(target=worker, args=(q,))
p.start()
try:
while True:
while not(q.empty()):
emg = list(q.get())
print(emg)
except KeyboardInterrupt:
print("Quitting")
quit()
Try plugging in the dongle and moving the Myo, if the LEDs are on, they are listening for your dongle. Note: Unless sent a power off command, the Myo never turns off. If it does turn off, charging it will cause it to turn on. The Myo does sleep, but putting it on or moving it should turn it back on.
The Myo should be placed at the thickest part of your forearm, with the bar status LED is facing down towards your hand. See Myo Placement for more details.
If the LEDs turn orange and the Myo vibrates, you should see readings coming though.
Try making a fist and squeezing, you should see some change in values.
To make the EMG signals easier to interpret, try changing the EMG mode. From:
m = Myo(mode=emg_mode.RAW)
To:
m = Myo(mode=emg_mode.PREPROCESSED)
Squeezing your fist should now increase the values printed.
Help is available on the discord in the pyomyo channel, which can be joined using this link.