Header image by kjfitzpat

Did you know you can use multiple Myo armbands at the same time?

No

No, not like that. I mean one on each arm, or a few people wearing one or two each. It's pretty easy to build an application that supports this as well. Let's take a look at the multiple-myos.cpp sample that comes bundled with the Myo SDK. I've included the relevant bits below, with the comments and main method stripped out. It's also available online here.

  
 



void onPair(myo::Myo* myo, uint64_t timestamp, myo::FirmwareVersion firmwareVersion){
            knownMyos.push_back(myo);
            std::cout << "Paired with " << identifyMyo(myo) << "." << std::endl;
        }
        void onPose(myo::Myo* myo, uint64_t timestamp, myo::Pose pose) {
            std::cout << "Myo " << identifyMyo(myo) << " switched to pose " 
               << pose.toString() << "." << std::endl;
        }
        void onConnect(myo::Myo* myo, uint64_t timestamp, myo::FirmwareVersion firmwareVersion) {
            std::cout << "Myo " << identifyMyo(myo) << " has connected." << std::endl;
        }
        void onDisconnect(myo::Myo* myo, uint64_t timestamp) {
            std::cout << "Myo " << identifyMyo(myo) << " has disconnected." << std::endl;
        }
        size_t identifyMyo(myo::Myo* myo) {
            for (size_t i = 0; i < knownMyos.size(); ++i) {
                if (knownMyos[i] == myo) {
                    return i + 1;
                }
            }
            return 0;
        }
        std::vector knownMyos;

The key thing is the onPair implementation and the identifyMyo function. When a new Myo armband is paired, the Myo object itself is pushed into our knownMyos vector. Any time we need to determine which specific Myo armband an event belongs to, we look it up with the identifyMyo function, which returns a number that uniquely identifies it.

This works because the myo object is unique for the life of your hub. If you compared two myo objects together and they are the same, they are the same Myo armband.

Note that "for the life of your hub" is key. If you restart your application, you will get new Myo objects, so it's not persistent.

This example was done with the OSX and Windows SDK, but similar capabilities exist in the others (Android, iOS, and Unity) as well as lot of unofficial ones. One place you can't use multiple Myo armbands though is Myo Script. Sorry! Hopefully someday, but not right now.

That's it for this #MyoCraft! Don't forget to send us your ideas!

Otherwise, see you next week!

Newsletter

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