Avatar The Society of Robotics and Automation is a society for VJTI students. As the name suggests, we deal with Robotics, Machine Vision and Automation

EMG Armband, The Conclusion

Developing an EMG system that can understand human hand motions.

Mentees:

This project is sponsored by Upside Down Labs

up

GitHub Repo: vovw/emgband

What is our project?

We read Electromyography (EMG) data using sensors, amplify it, filter it, perform ADC conversion, and conduct a frequency analysis (FFT) on it. Using the analyzed data, we train an ML model that can understand what hand movement was performed to get those readings.

Hardware Flow

What work has been done?

  • Initially, we attempted to approach this problem from first principles. We implemented the biopotential signal-acquisition board from scratch but encountered some issues.
  • We then pivoted temporarily to using Upside Down Labs’ EXG Pill, which works well. (Add images of the readings)

Signal Processing:

  • The raw signal goes through a bandpass filter to focus on frequencies between 75 and 150 Hz.
  • This filtering helps remove noise and focus on the most relevant part of the EMG signal.

ADC (Analog-to-Digital Converter)

  • Converts the continuous analog signal from the sensor into digital values the microcontroller can process.
  • We utilized the entire 12-bit ADC provided in the ESP32.
  • We later bound the values and mapped them to reduce the 0-4095 range to 0-1000 readings.

Bandpass Filter:

  • A filter that allows signals between two specific frequencies to pass through while blocking others.
  • A bandpass filter which filters the signal and returns a 72.5-725Hz signal is included in the Bio-amp EXG Pill.
  • Additionally, we implemented a Band-Pass Butterworth IIR digital filter generated using filter_gen.py.

Frequency Analysis:

  • The code uses the Fast Fourier Transform (FFT) to convert the time-domain signal into frequency components.
  • This helps identify which frequencies are most prominent in the EMG signal.
  • We used the Cooley-Tukey Algorithm for the Fast Fourier Transform.

FFT

ESP-now

WIP code implimentation - vovw/emgband

  1. ESP-NOW Sender Configuration:
    • The sender code initializes ESP-NOW and sets up a task to periodically send sensor data (ADC readings) to a broadcast address.
    • The sensor data is read from a GPIO pin using the ADC module.
    • The sender registers a peer with a broadcast address and sends data using esp_now_send.
  2. ESP-NOW Receiver Configuration:
    • The receiver code initializes ESP-NOW and registers a callback function to handle incoming data.
    • The receiver adds a peer with a specific MAC address (sender’s address) to receive data.
    • The received data is written to a file in the SPIFFS filesystem for storage and further processing.
  3. File System Integration:
    • The receiver uses the LittleFS file system to store the received data in a file named output.txt.
    • The file system is initialized and a file is created to store the incoming data.

We have successfully implemented ESP-NOW communication between two ESP32 devices. The sender device reads ADC data from a GPIO pin and sends it to the receiver using ESP-NOW. The receiver device receives the data and stores it in a file on the LittleFS file system.

here is the complete flow of how it works

Flow

Storing the Signal

To train our Machine Learning Model, we need to store the readings as data. We initially decided to label two events: Finger Moving and Palm Closing.

We output the data in frequency bins generated by the FFT on the serial port and store it in a .txt file. We wrote a Python script that maps this data from .txt to a CSV format, making it easier to read using pandas in our Model script.

Machine learning

vovw/emgband/ml

We are currently expirementing with different architecture mainly a simple feed forward network and classfication. Depending on the loss curves and which architecture fits the traning data better we will decide to go with that one.

planned ml ML for the EMG system

ml

Updates on weekly basis

Week 1: Fundamentals and Electronic Components

  • Gained understanding of operational amplifiers
  • Studied bandpass filters
  • Explored essential electronic components for bio-amplifiers
  • Introduced to basic neural networks and their implementation

Week 2: Hardware Acquisition and Signal Understanding

  • Received components from Upside Down Labs
  • Focused on understanding EMG bio-amplifier output signals, specifically the EXG Pill
  • Studied open-source documentation and repositories
  • Experimented with basic machine learning papers and algorithms

Week 3: Signal Processing and Machine Learning Foundations

  • Implemented Fast Fourier Transform (FFT) code
  • Worked on Analog-to-Digital Conversion (ADC)
  • Adapted Arduino code for ESP32 platform
  • Studied optimization algorithms:
    • Gradient descent
    • Backpropagation

Week 4: Data Collection and Wireless Communication

  • Developed Python script for:
    • Data collection
    • Data cleaning
    • CSV storage
  • Implemented ESP-NOW protocol for communication between two ESP32 devices:
    • One connected to the computer
    • One connected to the hand band
  • Progress towards creating a wireless EMG band

The following weeks dictate the project flow:

Week 5: Comprehensive Data Collection

  • Gather data for various hand movements:
    • Individual finger movements
    • Clenching and relaxing wrists
    • Thumbs up and thumbs down gestures
  • Focus on data cleaning and preparation

hand

Week 6: Model Development and Embedded Implementation

  • Create a sequential model
  • Train the model on collected data
  • Experiment with different architectures to optimize output
  • Convert the trained model to TensorFlow Lite format
  • Run the model locally on ESP32

Week 7: Hardware Integration and Enclosure

  • Design and create hardware casing to enclose:
    • Three Upside Down Labs Patchy devices
    • Amplifiers
    • ESP32 microcontroller
  • Focus on developing a clean and efficient system emg

Week 8: Web Integration and Future Applications

  • Develop a web server for data visualization and control
  • Explore potential applications of our EMG system