Skip to content
PerlinWarp edited this page Sep 20, 2021 · 18 revisions

First install pyomyo, which should also install it's only dependency pyserial.

pip install pyomyo
Myo Dongle

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.

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.

Myo placed on the forearm.

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.