Skip to content
PerlinWarp edited this page Sep 6, 2021 · 19 revisions

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

pip install pyomyo

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.FILTERED)
	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()
Clone this wiki locally