Baby O TTL Serial Communication Motor Control


I am using XBee Series 1 transceivers to control a single motor port on the Baby Orangutan B-328. The speed of the motor varies depending on a user’s input (increment/decrement buttons) and is stored as an integer on the Baby O. I am having trouble writing the code to, more or less, turn the motor ON and OFF (not set or change the speed) when it receives the correct data package (TTL) through the RX line.

Is it possible to employ a function that changes the state of the motor? (i.e. power = !power)
I was using the Arduino Uno with the code:
if (Serial.available > 0){
if ( == ‘D’){
power = !power;

But I can’t seem to get it to function properly in AVR Studio 5.1.

So basically, I’m looking to be able to implement the following code:

if (power == HIGH){
set_m1_speed(int speed);
else {

If you have any thoughts/suggestions/questions, please let me know.



The Pololu AVR Library Command Reference has a section on “Orangutan Serial Port Communication” that you might find relevant. You can see an example of a multi-byte serial protocol implemented for an Orangutan Robot Controller/3pi Robot in the Pololu 3pi Robot User’s Guide section called “Serial slave program”.

- Ryan

Thanks Ryan

The serial slave program really helped out!

Since we’re on the topic of serial communication, I am now working to incorporate a 4-digit, 7-segment LED display from Sparkfun. Uses TTL serial communication and accepts data in 4-byte packets (1 byte per digit).

I want to take readings of the VIN voltage in millivolts and convert each of the four digits into a single byte to send to the LED display.


  1. assign each digit in the VIN reading to a byte and store in a char [array]
    [I’ve tried using the ‘itoa’ command, but I’m fairly sure that I’ll need the correct header file. The header files I’ve found with this command also contain commands for serial communication. Will these interfere with Pololu’s serial communication header file?]

  2. drop the first digit (i.e. 489x) and shift the byte assigned to each digit right (i.e. x489)
    [I’m not supplying more than 7.4 V and I want to conserve battery life]

It seems like a daunting tasks to me, but I don’t mind the effort. Just need help getting pointed in the right direction.

Thanks again in advance!

Something like this should be close to what you want:

const unsigned char numbers[10] = {'0','1','2','3','4','5','6','7','8','9'};
int num = 1234;
unsigned char buffer[4];
unsigned char i;

for (i = 0; i < sizeof(buffer); i++)
    buffer[sizeof(buffer)-1-i] = numbers[num % 10];
    num = num / 10;
serial_send(buffer, sizeof(buffer));

Please note that this code has an effect on the value of num.

- Ryan