Arduino : Twig/Grove I2C Motor Driver Library

Since it’s a bit tedious to hammer out the whole I2C communication in code again every single time, I went ahead and wrote a small library for the Twig I2C Motor Driver from Seeed, based on the original Arduino Stepper library.

Listing 1 shows a small code example of how to use the Arduino library. Since the code is pretty much self-explanatory, I’ll spare myself any further explanation here.

Listing 1:

#include <Wire.h>
#include <TwigMotor.h>
#define STEPS 48

// create an instance of the TwigMotor class, specifying
// number of steps and I2C address
TwigMotor stepper(STEPS, 0x28);

void setup()
{
// set the speed of the motor to 100 RPMs
stepper.setSpeed(0x28,100);
}

void loop(){
// move 100 steps forward
stepper.step(0x28,100,FORWARD);
delay(1000);
// move 100 steps backward
stepper.step(0x28,100,BACKWARD);
delay(1000);
}

The exact specification and more information about the Twig I2C Motor Driver can be found in the Seeed Wiki.

You can download the Twig I2C Motor Shield library here:
https://github.com/mariolukas/TwigMotor-Library

UPDATE: With Arduino IDE versions lower than 022 you may run into problems.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.