Scroll YouTube Shorts Using 2 Channel EMG Signals

by Upside Down Labs in Circuits > Sensors

913 Views, 12 Favorites, 0 Comments

Scroll YouTube Shorts Using 2 Channel EMG Signals

demo.gif

In this tutorial, you are going to scroll the screen on your laptop using 2 Channel EMG signals detected from both of your arms. When you flex your right arm, the screen will scroll up and when you flex your left arm the screen will scroll down.

But before moving forward, let's understand a brief about Electrooculography (EMG):

What is Electromyography (EMG)?

Electromyography is a technique that measures muscle response or electrical activity in response to a nerve’s stimulation of the muscle. We can use this electrical activity to detect neuromuscular abnormalities or create solutions for some crazy real-world problems like making artificial limb for amputees.

Supplies

DIY Neuroscience Kit - Pro (Front).jpg
DIY Neuroscience Kit - Pro (Contents).jpg

HARDWARE:

DIY Neuroscience Kit Pro (Upside Down Labs Store | Amazon India | Robu IndiaTindie | DigiKey)

The kit includes:

  • BioAmp EXG Pill (Assembled)
  • Arduino Uno with USB Cable
  • BioAmp Cable (100cm)
  • 3 x Jumper Cables
  • NuPrep Skin Preparation Gel (25g)
  • Wet Wipes x 10
  • Repositionable Gel Electrodes x 3
  • Boxy Gel Electrodes x 100
  • Gel Electrodes (4 variants, 6pcs each)
  • Muscle BioAmp Band (EMG Band)
  • Brain BioAmp Band (EEG Band)
  • Heart BioAmp Band (ECG)
  • Electrode Gel (30ml)
  • Servo Claw
  • Muscle BioAmp Shield Kit
  • Muscle BioAmp Shield v0.3 (Assembled)
  • BioAmp Cable (100cm)
  • Muscle BioAmp Band (EMG Band)
  • BioAmp AUX Cable
  • Gel Electrodes (4 variants, 6pcs each)
  • STEMMA Cables x 6
  • 9V Snap Cable

SOFTWARE:

Arduino IDE v1.8.X (Legacy IDE)

Visual Studio Code

Python

About DIY Neuroscience Kit Pro:

It is like your Neuroscience Lab in a Box which lets you explore the world of neuroscience by recording various biopotential signals of your body (EEG, EMG, ECG, EOG) and making amazing HCI and BCI projects.

Stack Muscle BioAmp Shield on Arduino Uno

Stacking on Arduino Uno.gif

Stack the Muscle BioAmp Shield on top of Arduino Uno properly.

Configure BioAmp EXG Pill for EMG/ECG

assembly-step2.png

BioAmp EXG Pill is by default configured for recording EEG or EOG but if you want to record good quality ECG or EMG, then it is recommended to configure it by making a solder joint as shown in the image.

Note: Even without making the solder joint the BioAmp EXG Pill is capable of recording ECG or EMG but the signals would be more accurate if you configure it.

Connecting BioAmp EXG Pill

shield-pill-connecton.gif

Connect the BioAmp EXG Pill to the A2 port of Muscle BioAmp Shield via 3-pin STEMMA cable which has JST PH 2.0mm connector on one end and 3 female jumpers on the other end.

Connecting Electrode Cables

cables-connection.gif

Connect one BioAmp cable to BioAmp EXG Pill and another BioAmp cable to Muscle BioAmp Shield by inserting the cable ends into the respective JST PH connectors as shown above.

Skin Preparation

Skin Preparation.gif

We’ll create a 2-channel EMG acquisition system and to do so, we’ll be using both the sensors to record EMG signals from the ulnar nerve of both the hands, Thus, prepare the skin accordingly.

Apply Nuprep Skin Preparation Gel on the skin surface where electrodes would be placed to remove dead skin cells and clean the skin from dirt. After rubbing the skin surface thoroughly, clean it with an alcohol wipe or a wet wipe.

Electrode Placements (option 1)

gel-electrodes-connection.gif
gel-electrodes-connection-2.gif

We have 2 options to measure the EMG signals, either using the gel electrodes or using dry electrode based Muscle BioAmp Band. You can try both of them one by one.

Option 1: Using gel electrodes

  1. Snap the BioAmp Cable connected to BioAmp EXG Pill to gel electrodes.
  2. Peel the plastic backing from electrodes.
  3. Place the IN+ and IN- cables on the left arm near the ulnar nerve & REF (reference) at the back of your left hand as shown below.
  4. Now snap the BioAmp Cable connected to Muscle BioAmp Shield to gel electrodes.
  5. Peel the plastic backing from electrodes.
  6. Place the IN+ and IN- cables on the right arm near the ulnar nerve & REF (reference) at the back of your right hand as shown below.

Note: In this demonstration we are recording EMG signals from the ulnar nerve, but you can record EMG from other areas as well (biceps, triceps, legs, jaw etc) as per your project requirements. Just make sure to place the IN+, IN- electrodes on the targeted muscle and REF on a bony part.

Electrode Placements (Option 2)

band-connection-2.gif
band-connection.gif

Option 2: Using Muscle BioAmp Band

  1. Snap the BioAmp Cable connected to BioAmp EXG Pill on Muscle BioAmp Band in a way such that IN+ and IN- are placed on the left arm near the ulnar nerve & REF (reference) on the far side of the band.
  2. Snap the BioAmp Cable connected to Muscle BioAmp Shield on Muscle BioAmp Band in a way such that IN+ and IN- are placed on the right arm near the ulnar nerve & REF (reference) on the far side of the band.
  3. Now put a small drop of electrode gel between the skin and metallic parts of BioAmp Cables to get the best results.

Complete Tutorial on "How to use Muscle BioAmp Band": https://youtu.be/xYZdw0aesa0

Uploading the Code

Connect Arduino Uno to your laptop using the USB cable (Type A to Type B). Download the GitHub repository given below:

Muscle BioAmp Arduino Firmware: upsidedownlabs/Muscle-BioAmp-Arduino-Firmware

Go to the folder 8_EMGScrolling, open the arduino sketch 8_EMGScrolling.ino in Arduino IDE.

Go to tools from the menu bar, select board option then select Arduino UNO. In the same menu, select the COM port on which your Arduino Uno is connected. To find out the right COM port, disconnect your Arduino UNO board and reopen the menu. The entry that disappears should be the right COM port. Now upload the code.

IMPORTANT: Make sure your laptop is not connected to a charger and sit 5m away from any AC appliances for best signal acquisition.

Testing the Connections

testing.gif

Go to tools from the menu bar, click on serial monitor to open it or click on the icon on the top right corner. Try flexing both of your arms one-by-one. The output values should be 0 at this point.

Press the SW1 button on Muscle BioAmp Shield. Now you’ll see green LED glowing on the LED bar. When you flex your right arm, you’ll get output value 1 on the serial monitor and red LED will glow. Similarly, when you flex your left arm, you’ll get output value 2 and yellow LED will glow.

Running Python Script

Open Visual Studio Code, click on File < Open folder to open the folder 8_EMGScrolling.

Open the terminal, and ensure that the path is configured to the location of the requirement.txt file.

To install all the modules that are required to run the Python script, write the given command in the terminal:

pip install -r requirements.txt


Run the Python script EMG_Scroll.py by writing the given command in the terminal:

python EMG_Scroll.py


Note: The python script will automatically detect the COM port and successfully run the command in the terminal but in case of any error related to COM port then you can manually change the COM port in the python script on line 14 as per the COM port you selected in Arduino IDE.

Scrolling Using EMG Signals

demo-2.gif
demo.gif

In the terminal, you will see Move Now prompt. When you flex your right arm, you’ll see UP in the terminal. Similarly, when you move your left arm, you’ll see DOWN in the terminal.

Now, open YouTube shorts on your laptop and start scrolling using your muscle signals.

Note: What’s happening in the background? Whenever an EMG signal is detected, it acts as a trigger to emulate UP or DOWN key on the keyboard.

Calibrating the Code

Changes in Arduino Sketch

Modify the threshold values on lines 73 and 74. Threshold 1 is for the EMG signals recorded from the Muscle BioAmp Shield, and threshold 2 is for the EMG signals recorded from the BioAmp EXG Pill.

Uncomment line 71 in the Arduino code and navigate to Tools > Serial Plotter. You’ll see two plots showing the EMG signals of both of your arms. Flex your right arm and observe the peak value on the y-axis. If the peak value is around 240, you can set threshold 1 anywhere between 150 to 200. The lower the threshold value, the easier it is to trigger the output as UP or DOWN, and vice versa. Repeat the process to determine the threshold 2 value for your left arm.

After setting the thresholds, comment out line 71.

Changes in Python script

Adjust the latency value on line 51. A higher latency value will make the output less responsive, requiring you to flex and hold longer to scroll through the screen. A lower latency value will make the output more responsive, allowing you to scroll through the screen more easily.

Conclusion

This was just a demonstration to show you how both the sensors (BioAmp EXG Pill & Muscle BioAmp Shield) can be used together to create a 2-channel EXG acquisition system. In this project, we used BioAmp EXG Pill to record EMG signals, but it can also be used to record other biopotential signals as well like ECG, EOG, or EEG.

What are you gonna make with DIY Neuroscience Kit - Pro?

Let us know your feedback in the comments and feel free to ask any questions.

You can also mail us at support@upsidedownlabs.tech for any kind of support while you are making this project.