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:
- If required update drivers (DPinst64.exe)
- Download Energia
- Unpack and start…
- Copy driver to right directory and change file
- copy <energia directory>\hardware\tools\DSLite\DebugServer\drivers\MSP430.dll to <energia directory>\hardware\tools\msp430\bin\
- edit <energia directory>\hardware\energia\msp430\boards.txt an change the 2 occurrences of rf2500 with tilib
- restart energia and you should be able to upload to the MSP-EXP430G2 with MSP430G2553.
- http://forum.43oh.com/topic/9848-energia-1610r18-windows-7-launchpad-msp430g2553-dont-load-sketch/?p=74156
- configure jumpers for HW serial UART
http://energia.nu/reference/serial/
Further Information Links:
LaunchPad Board
Examples
- http://energia.nu/Tutorial_Blink.html
- http://energia.nu/Tutorial_AnalogInput.html
- http://energia.nu/Tutorial_AnalogReadSerial.html
MSP430/Arduinio + HC05 Bluetooth module
- http://forum.43oh.com/topic/3238-bluetooth-module-msp430-launchpad/
- https://e2e.ti.com/group/launchyourdesign/m/msp430microcontrollerprojects/665685
- http://www.martyncurrey.com/arduino-and-hc-06-zs-040/
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:
- Install Python 3.6 (python.org for other versions/OS). Check “Add python to the PATH”.
- Download the module: SerialPlotter
- Extract and navigate into the directory. It should contain a folder named “SerialPlotter”, “setup.py” and the source code “SerialPlotter_refined.py”.
- Start a command line (you may need to run it as admin) and execute: “pip install .” DO NOT forget the dot!
- (You can use “–target=”FAV_DIR_HERE” to install the required packages into a directory of your choice)
- Check if pip finishes without errors (you need internet connection to download the libraries).
- 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.