Libdevlpr

Last Updated: July 26, 2021



Current Version: 0.2.1

Overview

Libdevlpr is the Arduino API for the FANTM DEVLPR. It's primarily for interacting connecting the FANTM DEVLPR to other hardware based projects running off the Arduino (e.g. controlling LEDs and motors). For connecting the DEVLPR to a software project (e.g. connecting it to a game), see devlprd.

Libdevlpr is mainly callback oriented, allowing you to call a function at a fixed frequency, and use the incoming EMG data easily. It also gives you access to very basic data processing and filtering that can run on the Arduino, and primative flex detection.

The library is open-source and can be found here.

Installation

Libdevlpr can be installed through Arduino's very own library manager. Just navigate to "Tools/Manage Libraries..." or press ctrl-shift-i, and then search "libdevlpr". After pressing the install button, all that is left is putting #include <Libdevlpr.h> at the top of the sketch.

API

#define FILTER_NONE 0

Uses no filter, ensuring that functions in the API return raw data

#define FILTER_50HZ 1

Filters out the 50 Hz band of the signal, removing power line noise. Use this if you are based in a country where the grid operates at 50 Hz (e.g. most of Europe).

#define FILTER_60HZ 2

Filters out the 60 Hz band of the signal, removing power line noise. Use this if you are based in a country where the grid operates at 60 Hz (e.g. the USA)

class Devlpr(pin=A0, int filterType=FILTER_NONE)

This class is a a one-to-one mapping for each DEVLPR shield plugged into the Arduino. It is the parent of all of the filtering and callback logic in the library.

  • pin indicates the analog pin the DEVLPR is connected to.
  • filterType parameter expects one of the #define'd filters, and will use that filter when fetching any data.
void Devlpr::tick()

Reads a new EMG value into the buffer and checks if any callbacks should be called. A core part of the library, it almost always needs to be called in the Arduino void loop() function on every loop regardless of application. This ensures the freshest data is in the buffer, and that nothing is missed.

unsigned int Devlpr::lastValue(bool filtered=false)

Gets the most recent value in the EMG buffer.

  • filtered causes the function to filter the data using the filter type defined when the Devlpr object was constructed.
int Devlpr::lastValueCentered(bool filtered=false)

Gets the most recent value in the EMG buffer, and then subtracts the average across the buffer. In effect a DC removal filter.

  • filtered causes the function to filter the data using the filter type defined when the Devlpr object was constructed.
unsigned int Devlpr::windowAvg(bool filtered=false)

Gets the average of all readings in the EMG buffer.

  • filtered causes the function to filter the data using the filter type defined when the Devlpr object was constructed.
unsigned int Devlpr::windowPeakAmplitude(bool filtered=false)

Gets the difference between the midpoint of the EMG buffer (the DC offset) and the highest point in the buffer.

  • filtered causes the function to filter the data using the filter type defined when the Devlpr object was constructed.
unsigned int Devlpr::windowPeakToPeakAmplitude(bool filtered=false)

Gets the difference between the lowest and highest value in the EMG buffer. Usually the most reliable way to get a high signal-to-noise representation of a muscle contraction.

  • filtered causes the function to filter the data using the filter type defined when the Devlpr object was constructed.
int Devlpr::scheduleFunction(void (*f)(Devlpr *d), unsigned int millisPer)

Set a function to be called at some millisecond interval. The function accept a pointer to the Devlpr object as its sole arguement.

void Devlpr::setFlexCallback(void (*f)(Devlpr *d), float threshMult=1.5, unsigned int millisCooldown=400)

Set a function to be called whenever a flex is detected. The function accept a pointer to the Devlpr object as its sole arguement. This function almost always needs to be tuned to the specific application via modification to its threshMult and millisCooldown; always do software tuning before using a screwdriver to adjust the gain.

  • threshMult allows for tuning how sensitive the flex detection is, adjusting how hard a flex has to be to be detected.
  • millisCooldown is for debouncing the detection, to reduce the chance that a single muscle contraction is double counted.