Skip to main content

EMG controlled Music

In this tutorial, we will show you how to pause and unpause your music without pressing any keys on your laptop keyboard. To do that, we will read the peaks in EMG signals your arm muscles produce when you flex them and use them as a trigger for pausing the music played via Youtube through your computer. Feel free to connect your laptop to a Bluetooth speaker to make the music louder!

Check out an example video of this tutorial being put into action!

EMGmusicgif

The following instructions have been written for use with Windows 10.

Materials Required#

  1. OpenBCI Cyton Board
  2. Skintact sticky electrodes or IDUN Dryode
  3. EMG/ECG Snap Electrode Cables
  4. Computer with downloaded OpenBCI GUI

Step 1: Hardware Assembly.#

Follow the EMG Getting Started Tutorial to connect the electrodes to your body and the Cyton board, and read data from it using the OpenBCI GUI.

Step 2: Software Setup.#

Download and install Python (either version 2 or 3). Python might already be installed on your computer. Type python --version to check if you have Python version 2 or 3 installed. To use this program, you need the following Python packages installed:

  • pylsl: use python -m pip install pylsl from the Python folder in the command line to install it.
  • pyautogui : use python -m pip install pyautogui to install.

Step 3: Stream data using the OpenBCI GUI.#

Follow the networking tutorial on this link to learn how to stream data using LSL from the GUI. For this project, you will need to stream the EMG data from Channel 1 using the Networking Widget. Your Networking settings should look as follows:

info

Important: Make sure your EMG widget is open before you start streaming.

Step 4: Using a Python Script to Read the Data and Execute EMG Command#

The Python script will search for an EMG data stream. Once it finds the stream it will read it and detect any spikes that correspond to muscle flexing. If a flex is detected and 2 seconds have passed since the last one, it will press the space bar, which will make the music stop. The threshold for the time between flexes can be modified as needed to avoid debouncing.

Get the Python script from here by clicking on ‘Raw’ and copying it to a .py file in your Python folder. Once you’re streaming data from the GUI, go to the folder that you stored the script in from your command line, and run it using python.exe <script_name>.py.

Open Youtube and play some music. Every time you flex your arm as shown in the example video, the music will pause or start playing if paused already. By modifying the time_thres and flex_thres parameters in the code you can adjust the time to wait between flexes and the flex strength to your needs.

Try it out and send us a video of your final prototype!