Hey folks, Paul Bernhardt here with this week’s #MyoCraft. Today, we’re going to talk about how to use your Myo armband to control something hooked up to an Arduino board. We’ll do this via MyoDuino (available in the Myo Market) running on a PC. This is going to be mostly hardware focused, and obviously you’ll need an Arduino (and some kind of arduino project in mind) to use it. Let’s go!

Requirements

Before we get started, you’ll need the following items.

  1. A Myo armband running the latest firmware
  2. An Arduino board like the Uno
  3. The Arduino software/IDE
  4. A Windows PC
  5. An Arduino project you want to to gesture-enable. We hooked our board up to a bunch of LEDs.
  6. The MyoDuino project. You will also need the Microsoft Visual C++ Runtime, if you don't already have that installed.

Getting set up

The instructions for using this are in the PDF that comes with MyoDuino. What we’re going to do is basically have your PC act as a bridge between the Arduino board and your Myo armband. Just follow along!

  1. Open up the Arduino SDK and add the MyoDuino/Arduino/Myo Controller folder as a library

    Adding the Myo library

  2. Import the MyoController example

    Examples

  3. Tweak the example, or tweak your setup.

    Our Arduino Uno all hooked upOur Ardunio Uno all hooked up

What I mean by that is if you look at the sample, SimpleOutputFromPoses, you will see that it is very, well… simple:

#include <MyoController.h>

#define FIST_PIN 4
#define WAVEIN_PIN 5
#define WAVEOUT_PIN 6
#define FINGERSSPREAD_PIN 7
#define DOUBLETAP_PIN 8

MyoController myo = MyoController();

void setup() {

  pinMode(FIST_PIN, OUTPUT);
  pinMode(WAVEIN_PIN, OUTPUT);
  pinMode(WAVEOUT_PIN, OUTPUT);
  pinMode(FINGERSSPREAD_PIN, OUTPUT);
  pinMode(DOUBLETAP_PIN, OUTPUT);

  myo.initMyo();
}

void loop()  
{
   //Serial.println("HI");
   myo.updatePose();
   switch ( myo.getCurrentPose() ) {
    case rest:
      digitalWrite(FIST_PIN,LOW); 
      digitalWrite(WAVEIN_PIN,LOW);
      digitalWrite(WAVEOUT_PIN,LOW);
      digitalWrite(FINGERSSPREAD_PIN,LOW);
      digitalWrite(DOUBLETAP_PIN,LOW);
      break;
    case fist:
      digitalWrite(FIST_PIN,HIGH);
      break;
    case waveIn:
      digitalWrite(WAVEIN_PIN,HIGH);
      break;
    case waveOut:
      digitalWrite(WAVEOUT_PIN,HIGH);
      break;
    case fingersSpread:
      digitalWrite(FINGERSSPREAD_PIN,HIGH);
      break;
    case doubleTap:
      digitalWrite(DOUBLETAP_PIN,HIGH);
      break;
   } 
   delay(100);
}

It is set up to use pins 4-8, with one pin for each hand pose. When a new pose is detected, that pin is set to HIGH. When the “rest” pose is detected (which happens between every pose), all the pins are set to LOW. You can either set up your Arduino so that those pins do something, or modify what pins get activated to suit your project.

Go Time!

Ain’t no time like go time. Let’s run our sketch.

  1. Upload your sketch to your Arduino via USB. Leave the Arduino connected.
    Upload

  2. Make sure you are wearing your Myo armband, it’s connected to your computer, and you are synced.

  3. Launch MyoDuino/bin/MyoDuino.exe and set the COM port to the one your Arduino is on (you can see this in Tools->Ports in the Arduino IDE). It’s up to you whether you want locking to be on or off.

    MyoDuino Input Window

Now you should be staring at a terminal window. It will tell you which arm you are wearing the armband on and the current gesture (for debugging purposes). Make sure this window is in the foreground, and start making poses!


The "Pose Window IRL," hacked together by Thalmic's own Jake Chapeskie!

Easy peasy. This was a pretty simple hack, but it’s a good place to start. From here, you could obviously go crazy with complicated Arduino setups, but you could also modify the source code of MyoDuino itself. You could then do things like enabling specific motion gestures to expand your control options. You could  tweak the locking behaviour so it won’t lock you out in the middle of a pose. You could also build your own “edge” behaviour, like you see in Myo Scripts (Indeed, as it stands this will keep setting the relevant pin to HIGH over and over as long as you hold a pose, which may not be ideal for your application).

But, it’s up to you! If you made a sweet hack, using Arduino or something else, let us know at MyoCraft@thalmic.com.

Otherwise, see you next week!

Newsletter

Enter your email address and get all latest content delivered to your inbox every now and then.