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!
The following instructions have been written for use with Windows 10.
- OpenBCI Cyton Board
- Skintact sticky electrodes or IDUN Dryode
- EMG/ECG Snap Electrode Cables
- Computer with downloaded OpenBCI GUI
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.
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 pylslfrom the Python folder in the command line to install it.
- pyautogui : use
python -m pip install pyautoguito install.
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:
Important: Make sure your EMG widget is open before you start streaming.
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
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!