Robot rebuild

After last week’s accident with the motor driver board it was time for a re-think. After a bit of research I opted for a couple of Pololu Baby Orangutan boards to drive each side of the robot. They use the same motor controller as the Sparkfun breakout but also have their own voltage regulator and an ATMega328 on-board.

Baby O's on PermaProto

Baby O’s on PermaProto

They just need motor voltage and ground plus some means of communicating with the outside world. I opted to configure them as I2C slaves – hence the extra pins in the photo linking to the two BabyO boards and finally connecting the I2C bus to 4K7 resistors.

Testing and programming...

Testing and programming…

Pololu have excellent instructions on programming the boards from within the Arduino environment. They do need a programmer – unless you put the Arduino bootloader on them – but that’s all fairly straightforward.

Each board has it’s own I2C address (I used 0X10 and 0x11 as the 7 bit addresses of “Left” and “Right”). Initially I was going to store these in EEPROM then I would only need maintain one sketch for motor control – there must be a fuse bit that causes EEPROM to reset when the board is programmed though as the value I stored seemed to revert to 0xFF whenever a new sketch was uploaded).

Using the Pololu motor library for Arduino means that programming the boards is a doddle.

I2C Slave Motor Controller - 2 x Pololu Baby Oragutan "B" boards
#define F_CPU=20000000L

#include <Wire.h>
#include <OrangutanMotors.h>

const byte slaveAddress = 0x10; // Left
//const byte slaveAddress = 0x11; // Right

const int led = 1; // Red LED which we'll use to indicate receipt of a message

// Blink LED if message received...
long ledOffTime;
byte ledOn;
const byte ledDuration = 10;

// the setup routine runs once when you press reset:
void setup() {
 // Start with motors off (should be default)

 // initialize the digital pin as an output.
 pinMode(led, OUTPUT); 
 // Join I2C bus
 // Routine to do all of the work...

void receiveEvent(int n) {
 int value;
 // process 2 byte messages
 if ( n==2 ) {
   value =;
   value <<= 8;
   value |=;
   // Set motor speed
 // discard any junk
 while (Wire.available() > 0) {;
 ledOn = 1;
 ledOffTime = millis() + ledDuration;

// turn off LED when told to
void loop() {
 if ( ledOn && millis() > ledOffTime ) {
 ledOn = 0;

That’s all there is to it, I just have to remember to make sure the slave address is correct. All I need to do is to send an integer motor speed value to left or right motor controller. The value goes from -255 for full reverse, through 0 (stop) to 255 for full speed ahead.

Motor board inside robot

Motor board inside robot

The white (SDA) and yellow (SCK) wires are the I2C bus – have some shorter ones on order so will be replacing the ones on the board when I get them.

More testing

More testing

Time to start putting things together. Here’s the sensor board from the front:

Ultrasonic sensor and stepper

Ultrasonic sensor and stepper

The cheapo Chinese built stepper motor and driver board I had before were OK but this combination of BigEasy stepper driver and a Pololu stepper motor (more expensive but probably still made in China) is much more reliable. I could even get a mounting kit too:


Attaching sensor board to stepper motor

Attaching sensor board to stepper motor

Nearly there...

Nearly there…

I now have the battery for the Pi and ATmega slung under the top platform using good old ‘laccy’ bands. Putting it altogether we have:

Looking like a robot.

Looking like a robot.

So that’s a Raspberry Pi in a case with an ATmega328 on the very top. Pi both powers and controls  the 328 through a mini USB-FTDI breakout and has an Edimax nano wifi adaptor for communicating with the rest of the world.

I2C takes 2 pins to control compass module and both motor controllers. In addition I need 2 pins for stepper (direction and step), 1 pin to detect when the stepper is at it’s end stops, 1 pin for the ultrasonic sensor and 1 pin for the obligatory LED.

That’s the hardware side done for now so I can finally get on with the software side. First up I’d just like a functional web based control so I can drive this thing about a bit – the full-on autonomous stuff will have to wait a bit longer and I’ll need some kind of web interface anyway. I’m liking the look of pyjs and I think their draggable 2D Input Box would make for an intuitive way of steering the robot and varying it’s speed.



This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

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