Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Hackster is hosting Impact Spotlights: Smart Home. Watch now!
Aula πŸ’‘πŸ•ŠοΈAhmad TASKIA
Published Β© MIT

MuscleScroll:EMG-Powered Tab Navigation on Raspberry Pi πŸ”ΊπŸ”»

This innovative project harnesses the power of EMG signals to enable intuitive and seamless navigation between web tabs & other interfaces.

IntermediateFull instructions provided10 hours171
MuscleScroll:EMG-Powered Tab Navigation on Raspberry Pi πŸ”ΊπŸ”»

Things used in this project

Story

Read more

Schematics

H2BR0x-Hardware

H2BR0x-FactSheet

Hex file

Code

Test code

Python
import serial
import struct
import time
import pyautogui
def scroll_up():
    pyautogui.scroll(100) 
    print("Scrolled Up")
def scroll_down():
    pyautogui.scroll(-100)   
    print("Scrolled Down")
ser = serial.Serial(
    port='/dev/ttyS0',
    baudrate=921600,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    timeout=0)  # Setup Serial Connection
ser.flushInput()
while True:
    x = ser.read(4)
    sensor_value = []
    if x and len(x) == 4:
        sensor_value = list(struct.unpack('f', x))
        print(f"Sensor Value: {sensor_value[0]}")
    if sensor_value and sensor_value[0] > 2: 
        scroll_up()
        time.sleep(1)
    elif sensor_value:
        scroll_down()
        time.sleep(1)

Scroll code

Python
import pyautogui
import time
import numpy as np
import serial
import struct

# Setup Serial Connection
ser = serial.Serial(
    port='/dev/ttyS0',
    baudrate=921600,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    timeout=0
)

def process_emg(emg_value):
    threshold = 2 
    if emg_value > threshold:
        return "scroll_up"
    else:
        return "scroll_down"

def scroll_up():
    pyautogui.scroll(100)
    print("Scrolled Up")

def scroll_down():
    pyautogui.scroll(-100)
    print("Scrolled Down")

def moving_average(values, window_size):
    return np.convolve(values, np.ones(window_size)/window_size, mode='valid')

ser.flushInput()
emg_values = []

while True:
    x = ser.read(4)
    if x and len(x) == 4:
        sensor_value = list(struct.unpack('f', x))
        emg_values.append(sensor_value[0])

        if len(emg_values) > 10:  # Use a moving window size of 10
            averaged_value = moving_average(emg_values, 10)[-1]
            print(f"Averaged EMG Value: {averaged_value}")

            action = process_emg(averaged_value)
            if action == "scroll_up":
                scroll_up()
            elif action == "scroll_down":
                scroll_down()
            
            emg_values.pop(0)  # Remove the oldest value to maintain window size
    
    time.sleep(0.1)

H2BR0x-Firmware

Credits

Aula πŸ’‘πŸ•ŠοΈ
58 projects β€’ 223 followers
Electronic Engineering
Contact
Ahmad TASKIA
11 projects β€’ 11 followers
MPhil. Bsc. ELECTRONICS Engineering
Contact

Comments

Please log in or sign up to comment.