Hardware and Software for EMG

Hardware for the Workshop

Commercial Hardware

We will use the following commercial hardware for experimentation:

Arduino Board: https://www.arduino.cc/en/Main/arduinoBoardUno
Olimex EMG Shield: https://www.olimex.com/Products/Duino/Shields/SHIELD-EKG-EMG/
Olimex EMG cable: https://www.olimex.com/Products/Duino/Shields/SHIELD-EKG-EMG-PRO/
Gel Electrodes: https://www.olimex.com/Products/Modules/Biofeedback/ECG-GEL-ELECTRODE/

Custom Hardware

We use a custom board with an Arduino-Formfactor that provides analog-digital conversion and bluetooth transmission.

Eagle Schematic and Board in a single zip-file (workshop-adc-bt-v2a.zip).

Software for the Workshop

Firmware for Arduino

/*
  EASY EMG CONTROLLER 
  Francisco Kiss @hcilab-org 2017
  adapted from code by Tom Igoe

  Converts analog stuff to ints and sends them via serial port
 */


// PINS
const int channel1 = A0;
const int channel2 = A3;
const int channel3 = A4;

// VARIABLES
int value1 = 0;
int value2 = 0;
int value3 = 0;

void setup() {
  // START SERIAL	
  Serial.begin(9600); // change this value up to 115200
}

void loop() {
	// READ ANALOG VALUES
	value1 = analogRead(channel1);
	value2 = analogRead(channel2);
	value3 = analogRead(channel3);
	
	// SEND TO SERIAL
	Serial.print(value1);
	//Serial.print(value2);
	//Serial.print(value3);
	Serial.print("\n");

	// WAIT A BIT
	delay(10);                  
}

Firmware for Custom Hardware (ADC-BT)

The microcontroller used in this custom hardware is from the MSP430 familiy (MSP430G2553 / MSP LaunchPad). Using Energia (http://energia.nu/guide/) this hardware can be programmed like an Arduino, using the same code as for the Arduino.

Here is some useful information to get the develoment environment running:

MSP IDE (like Arduino):

Installing:

 

 

Further Information Links:

LaunchPad Board

Examples

MSP430/Arduinio + HC05 Bluetooth module

 

Receiver Software (python)

The python script is based on Python 3.6 x64 (python.org for other versions/OS) and simply reads from a connected serial port. A plotter shows the data as a line graph.

You can find the source code here: SerialPlotter_src.
It requires the following libraries:

  • matplotlib for plotting the graph
  • numpy for feature calculation
  • pyserial for the serial communication

Libraries are available on https://pypi.python.org/pypi. You can use your favorite IDE package installer, install packages manually or install the SerialPlotter module via pip:

  1. Install Python 3.6 (python.org for other versions/OS). Check “Add python to the PATH”.
  2. Download the module: SerialPlotter
  3. Extract and navigate into the directory. It should contain a folder named “SerialPlotter”, “setup.py” and the source code “SerialPlotter_refined.py”.
  4. Start a command line (you may need to run it as admin) and execute: “pip install .” DO NOT forget the dot!
  5. (You can use “–target=”FAV_DIR_HERE” to install the required packages into a directory of your choice)
  6. Check if pip finishes without errors (you need internet connection to download the libraries).
  7. Run the SerialPlotter src code in a console with the appropriate port: “python SerialPlotter_refined.py [port]” (e.g. “COM10” or “/dev/rfcomm0” depending on your OS)

You might need to call python3 binaries if you have python2 installed as well, such as “python3/pip3” instead of “python/pip”.

 

Receiver Software (Processing)

We provide sample code files for Processing 3 (https://processing.org/). It connects to the serial port and reads in values. The signal is then plotted on a simple graph. You can find the src code here: SerialPlotterProcessing.pde. Please change the port in the src code. A list of available ports will be shown if you execute the program.

We also provide a Processing sketch that uses the Arduino library to directly read the analog values from the EMG shield using a stock Arduino UNO (NOT our board) and the Arduino “StandardFirmata”, that needs to be flashed to the device. See here for detailed information: http://playground.arduino.cc/Interfacing/Processing. To use Arduino commands in Processing, you must install the “Arduino (Firmata)” library. You can do so by navigating to “Sketch | Import Library | Add Library” and search for it. Hardware-wise mount the EMG shield to the Arduino and connect it to your laptop. You should be able to run the following code snippet: SerialPlotterProcessingArduino.