I2C Seeed Motor Driver on Intel Edison using UPM with Javascript

Outlined below is the method I am using for driving a pair of Seeed I2C motor drivers v1.3 (http://www.seeedstudio.com/wiki/Grove_-_I2C_Motor_Driver_V1.3) using the Intel Edison and the UPM repository for MRAA. 

It is assumed that you are fairly comfortable with using the Intel Edison and Intel XDK. Mainly you should know how to connect to your Edison via a serial connection using Putty or Screen and connect to the Intel XDK to the Edison via wifi. If you are unsure how to do this please go through the getting started documentation for the Edsion.

Installing MRAA and UPM

To install the latest version of MRAA and the UPM repository enter the following into the command line on the Edsion:

echo "src mraa-upm http://iotdk.intel.com/repos/1.1/intelgalactic" > /etc/opkg/mraa-upm.conf
opkg update
opkg install libmraa0
opkg install upm

Wiring up Motor Drivers

To wire up the pair motor driver boards I am connecting both board's SCL and SDA to the SCL and SDA pins on the Edison breakout board (running the SCL and SDA pins to a breadboard and running the connections out to the motor drivers) . Likewise the power and ground run to a common 5v and ground rail on the breadboard. 

One of the boards is set to address 1010, the other is set to 1111 using the switches on the board.

1010 is 0x0a or 10 in hexadecimal and decimal  representation. 
1111 is 0x0f or 15 in hexadecimal and decimal  representation. 

IMPORTANT: If you switch the address on a board that is powered on you must reset the board for the address change to take effect using either the reset switch or doing a power cycle. 

Running motor driver via Javascript 

To run the driver I am using Javascript through the Intel XDK. The sample code below is a stripped down version of the UPM example on their Github.

 var groveMotorDriver_lib = require('jsupm_grovemd'); //require motor driver library

var i2c_addr1 = 15; // set address of board 1 to 15, or 1111 on the switches 
var i2c_addr2 = 10; // set address of board 2 to 10, or 1010 on the switches

// Initiate two I2C Grove Motor Drivers on I2C bus 0
var my_MotorDriver_obj1 = new groveMotorDriver_lib.GroveMD(

var my_MotorDriver_obj2 = new groveMotorDriver_lib.GroveMD(

//Set the states of the motor drivers
my_MotorDriver_obj1.setMotorDirections(groveMotorDriver_lib.GroveMD.DIR_CCW, groveMotorDriver_lib.GroveMD.DIR_CW); //set the directions of the motors on board 1
my_MotorDriver_obj1.setMotorSpeeds(127, 255); //set the speeds of the motors on board 1

my_MotorDriver_obj2.setMotorDirections(groveMotorDriver_lib.GroveMD.DIR_CW, groveMotorDriver_lib.GroveMD.DIR_CCW); //set the directions of the motors on board 2
my_MotorDriver_obj2.setMotorSpeeds(127, 255); //set the speeds of the motors on board 1

In the code above the motors are set to:

Board 1 (1111): Channel 1 speed: 127, Channel 1 direction: clockwise
                          Channel 2 speed: 255, Channel 2 direction: counter-clockwise

Board 2 (1010): Channel 1 speed: 127, Channel 1 direction: clockwise
                            Channel 2 speed: 255, Channel 2 direction: counter-

Where channel 1 is the output in line with the channel switches 


If you receive an error such as:

ERROR: writePacket: mraa_i2c_write() failed: MRAA: Unrecognised error. 

You have either entered an i2c address that does not correspond to the switch settings on your board, have not reset the board after changing the channel switches, or the pins have not been unexported through MRAA. 

The simplest way is to force MRAA to unexport pins is to launch the Arduino IDE and run the blink example. https://software.intel.com/en-us/articles/intel-iot-platforms-blink-led-arduino-ide

TI Sensortag with Intel Edison and gatttool

ROS on Intel Edison using Ubilinux and Porting to Yocto