North (formerly Thalmic Labs), the creator of the Myo armband, was acquired by Google in June 2020. Myo sales ended in October 2018 and Myo software, hardware and SDKs are no longer available or supported. Learn more.

#MyoCraft: How to pair effortlessly with Bluetooth Smart

#MyoCraft: How to pair effortlessly with Bluetooth Smart

Welcome back to this week’s #MyoCraft! This time, we’re going to talk about how you can use a really neat feature of Bluetooth Smart (aka Bluetooth LE) for seamless pairing with the Myo armband.

Traditionally, Bluetooth pairing has been… a bit of a pain. In the ideal case, the two devices you were pairing both had a keyboard and you would use them to input a random PIN. This was a key part of the Bluetooth security model and would confirm that the correct devices were connecting together. In the real world, however, most users ended up pairing dumb devices like a Bluetooth headset or stereo gateway. Since there was no way to enter a PIN on those, the user had to remember whichever number had been selected by the manufacturer. Naturally, it would be something extremely “secure”. Like 0000 or 1234.

A needless hassle, basically. That’s why with Bluetooth Smart the pairing process was simplified greatly. You can build an app such that a user simply picks from a list of compatible devices and connects immediately. That’s nice, but even then it may require you to build more UI than you really want to.

Enter the tap:

Attach to Adjacent Demo

The “tap” detection is based on the huge increase in signal strength you get from two Bluetooth radios being very close together. It’s also trivial take advantage of with a Myo armband. Check out our Android sample BackgroundService:

 * Copyright (C) 2014 Thalmic Labs Inc.
 * Distributed under the Myo SDK license agreement. See LICENSE.txt for details.


import android.content.Intent;  
import android.os.IBinder;  
import android.util.Log;  
import android.widget.Toast;

import com.thalmic.myo.AbstractDeviceListener;  
import com.thalmic.myo.DeviceListener;  
import com.thalmic.myo.Hub;  
import com.thalmic.myo.Myo;  
import com.thalmic.myo.Pose;

public class BackgroundService extends Service {  
    private static final String TAG = "BackgroundService";

    private Toast mToast;

    // Classes that inherit from AbstractDeviceListener can be used to receive events from Myo devices.
    // If you do not override an event, the default behavior is to do nothing.
    private DeviceListener mListener = new AbstractDeviceListener() {
        public void onConnect(Myo myo, long timestamp) {

        public void onDisconnect(Myo myo, long timestamp) {

        // onPose() is called whenever the Myo detects that the person wearing it has changed their pose, for example,
        // making a fist, or not making a fist anymore.
        public void onPose(Myo myo, long timestamp, Pose pose) {
            // Show the name of the pose in a toast.
            showToast(getString(R.string.pose, pose.toString()));

    public IBinder onBind(Intent intent) {
        return null;

    public void onCreate() {

        // First, we initialize the Hub singleton with an application identifier.
        Hub hub = Hub.getInstance();
        if (!hub.init(this, getPackageName())) {
            showToast("Couldn't initialize Hub");

        // Disable standard Myo locking policy. All poses will be delivered.

        // Next, register for DeviceListener callbacks.

        // Finally, scan for Myo devices and connect to the first one found that is very near.

    public void onDestroy() {
        // We don't want any callbacks when the Service is gone, so unregister the listener.


    private void showToast(String text) {
        Log.w(TAG, text);
        if (mToast == null) {
            mToast = Toast.makeText(this, text, Toast.LENGTH_SHORT);
        } else {

The key bit is the hub.attachToAdjacentMyo() call. Once you’ve called that function, the user just has to tap the LED of their Myo armband to the back of their phone, and your app will get an onConnect event.

You should make sure you both tell your user to do this at the appropriate time, and tell them again when it worked. You can see we are doing this with a Toast in the Android sample, but there are a number of approaches you can take that don’t require any kind of complicated UI.

Also worth noting that, though this was an Android example, the same function exists on iOS. On Mac or PC, the pairing is handled for you by Myo Connect so you don’t need to worry about it.

That’s it for this week! Don’t forget to send us your submissions for #MyoCraft to, or directly to me on Twitter (@thalmicdev).

See you next time!

You've successfully subscribed to The Lab!