Sunday, March 8, 2015

MiP™
So I started connecting my Mip to the PC using the cylon.js stuff.

If you don't know what a Mip is, you can read about it here:
http://www.wowwee.com/mip/

I'd like to spare others a lot of pain so here goes my blog :)

First off, if you are using windows, forget trying to use cygwin or the like.

VirtualBox with Linux (I used Ubuntu) is the only thing that seems to work.

Download the latest VirtualBox and VirtualBox Extension Pack. You will need it.
https://www.virtualbox.org/wiki/Downloads

Then download a Ubuntu distribution you can boot from with VirtualBox.
http://www.ubuntu.com/download/desktop/
Make sure you install the extension pack after you install VirtualBox.

Once you got into a terminal window in Ubuntu (when in doubt, press Alt-Ctrl-T, yeah took me a while to figure it out) run the following commands:


$ curl -sL https://deb.nodesource.com/setup | sudo bash -
$ sudo apt-get install -y nodejs
$ sudo apt-get install libbluetooth-dev
$ sudo npm install cylon
$ sudo npm install cylon-mip
$ sudo npm install noble

You should now be able to do the part below and see a UUID. Write the UUID down.
$ sudo cylon-ble-scan
Starting scan.
Peripheral discovered!
  Name: 2B-785E
  UUID: cc360e85785e
  rssi: -80
If you do not get a UUID then the Mip is not turned on or the Bluetooth adapter is not on or working correctly. When in doubt, reboot. Make sure the Ubuntu window shows a little Bluetooth icon atop.

Whenever you want to run Mip commands you must run them from here:

$ sudo nodejs
Now you can go here:
http://cylonjs.com/documentation/platforms/mip/

and copy and paste the following (make sure you replace the uuid part with the uuid you wrote down):

var Cylon = require('cylon');

Cylon.robot({
  connections: { bluetooth: {adaptor: 'central', uuid: 'd03972a24e55', module: 'cylon-ble'}},
  devices: {mip: {driver: 'mip'}},

  work: function(my) {
    my.mip.setHeadLED(2, 2, 2, 2);
    after((2).seconds(), function() {
      my.mip.driveDistance(0, 10, 0, 0);
    });
    after((3).seconds(), function() {
      my.mip.setHeadLED(1, 1, 1, 1);
    });
  }
}).start();
into the nodejs command line terminal. (Make sure there is a '>' and NOT a '$' as the first character on your command line!)

Finally, this javascript file gives you an idea of the supported Mip commands:
That's it for now. Please leave comments for corrections or suggestions. I want to make this as easy as possible for people to get into this. Also, I will try to make some example programs at some point. But I think this is a good start.