Monday, 9 April 2012

Using the WowWee TriBot wheel encoders.

The TriBot base includes wheel encoders that provide feedback about the actual wheel rotation to the TriBot main chip.

These 3 wheel encoders are connected to the TriBot board with 3 thin 3-wire cables. They take 12V as input and output 12V. This means that you should convert the output to 5v before connecting it to the Arduino, which is a hassle.

However, if you disconnect them from the tribot and power them in 5V, they will work fine and output a nice Arduino-friendly 5V.

So the connection of each wheel encoder to an Arduino is pretty straightforward: ground to ground, +5 to Arduino +5 output, and the wheel encoder output to any Arduino pin (preferably one of the interrupt enabled pins), configured as input.

The wheel encoder connector pinout is:

 |   |
1: Ground
2: Output
3: +5

Saturday, 31 March 2012

BlueTooth Controlled TriBot Base

I used my TriBot-based robot base to play with Android and Bluetooth. Goal: controlling the robot base with an Android phone.

The robot now look like that:

And the result, where you can see that the robot can actually turn and slide in all directions (left pad for sliding, right pad for turning):

How to connect Android to an Arduino?

I bought this very cheap serial/BlueTooth board (CSR Bluetooth chip/CSR BlueTooth chip) from Iteadstudio:

To connect the Android phone to the Arduino using this BlueTooth module, I used the Amarino library.

Setting up the BT module

The HC-06 BT Module is setup at 9600 bps by default. Amarino required it to run at 57200 Bps.

To change the serial connection rate, upload this code to your Arduino, disconnect it from your PC, connect the BlueTooth module to the serail port of your Arduino and restart it.

void setup() {

Using the Amarino Arduino library

The code is strongly inspired by the MultiColorLamp example code.
The two interesting additional points are:
  • Each message is constituted with  values (one for each motor, from -255 to 255). Using several values in a message is undocumented, but straightforward
  • I included a timer to stop motors after half a second without any incoming message. Usefull to prevent  accidents when the Bluetooth get disconnected. Of course it implies that the Android application send messages constantly during to move the robot.


MeetAndroid meetAndroid;

int MOTOR_ENABLE[] = {5,6,7};
int MOTOR_DIR[] = {4,3,2};
int STOP_DELAY=500;

unsigned long lastSignalTime;

int LED = 13;

void setup() {                
  meetAndroid.registerFunction(setMotor, 'm');

  for (int i=0;i<3;i++) {
    pinMode(MOTOR_ENABLE[i], OUTPUT);
    pinMode(MOTOR_DIR[i], OUTPUT);
  pinMode(LED, OUTPUT);

void loop() {
  if (millis()-lastSignalTime>STOP_DELAY)

void setMotor(byte flag, byte numOfValues)
  int values[3];
  for (int i=0;i<3;i++) {
    int v=values[i];
    if (v>0) {
      analogWrite(MOTOR_ENABLE[i], v);
    } else {
      analogWrite(MOTOR_ENABLE[i], -v);

void stopMotor() {
  for (int i=0;i<3;i++)   


Using the Amarino Android Libary

I will not go into the details of the Android application, strongly inspired by MultiColorLamp as well. It displays a joypad, convert thumb positions into motor values (the tricky part), and send them to the Arduino by BlueTooth, using:

private void callAndroid() {
  int[] message = getMotorValues(leftJoyX,leftJoyY,rightJoyX,rightJoyY);
  Amarino.sendDataToArduino(this, DEVICE_ADDRESS, 'm', message);

Where getMotorValues returns an array of 3 integers.