Linux Pololu Orangutan Tutorial

Introduction

The Pololu Orangutan is the only complete, affordable ($79) robot controller that can be programmed with the C programming language. This is a really good thing, because almost all programmers have experience with C, and because C is a great language: it is much easier to use than assembly and much more powerful than educational languages such as BASIC or LOGO. This page is targeted at Linux users, who will be delighted to know that gcc is fully compatible with the MEGA8 microcontroller at te heart of the Orangutan. In a step-by-step tutorial, we will see how to get started working with the Orangutan under Linux.

A bit of experience with soldering, the ability to install programs on your Linux computer, and some C programming experience will be required to follow the steps here. It will cost you about $130 and 50M of disk space, and you'll be up and running about four hours after you unpack the electronics.

1. Order electronic parts

Order the Orangutan Robot Controller from Pololu. Also order the ATAVRISP-ND programmer for $29 from Digi-key. In addition to the programmer, you will need some other electronics. I recommend two battery holders that hold 3 AAA cells, such as part 2480K-ND, six Nickel Metal-Hydride (NiMH) batteries (Digi-key is out of stock right now; check your local computer store), and a NiMH battery charger. You can go with cheaper Nickel-Cadmium batteries, but the NiMH cells will give many more hours of enjoyable robot programming. A wired power connection using a wall adaptor is also possible, if you are building a stationary robot (like a robot arm). Order a row of female header (929974-01-36-ND) to make a power plug. Make sure you have wire, solder, heat-shrink tubing, and a soldering iron on hand to wire up the power connection (and future robot circuitry!)

2. Assemble power supply

Solder the two battery packs together (in series) and connect them to a two-by-one piece of female header, using heat-shrink to insulate all connections. You might want to use hot-glue in various places to provide strain relief.

picture of assembly

3. Plug in Orangutan

Read through the instructions for the Orangutan. After familiarizing yourself with the board, plug in your power supply and turn on the switch. You should see the lights go on, and a welcome message will appear on the screen. (Note: I found the lights to be painfully bright, but a little permanent marker fixed that problem.)

4. Plug in AVR Programmer

Skim through the manual that comes with the AVR Programmer. You will need to replace the pre-installed ten-pin header with the included six-pin header (actually, you can leave both cables attached, as long as you don't try to use them simultaneously.) Attach the programmer to the header on the Orangutan and to your computer's serial port as shown. The LED on the programmer will cycle through several colors and stop on green if everything is okay.

5. Install software

You'll need a computer running linux to get gcc running; you could probably also set this stuff up under cygwin. I used Slackware 10, but the same instructions should work on any modern linux system.

Get the latest binutils from ftp://ftp.gnu.org/gnu/binutils/. Install with

./configure --target=avr --prefix=/usr/local/atmel
make
make install

Get the latest gcc-core from ftp://ftp.gnu.org/gnu/gcc/. Install with

export PATH=/usr/local/atmel/bin:$PATH
./configure --target=avr --prefix=/usr/local/atmel --enable-language=c
make
make install

Get the latest avr-libc. This package is base code for the AVR, so it needs to know the location of the AVR gcc and binutils. Edit the PREFIX line of the file doconf to refer to /usr/local/atmel, then install with

./doconf
./domake install

Get the latest Uisp, the program you will use to access the AVRISP. Install with

./configure
make
make install

6. Try a simple program

Save this code as blink.c:

#include <avr/io.h>

/* at 8 MHz we get 1us per 8 instructions */
inline void delayus() { asm volatile("nop\nnop\nnop\nnop\n"
                                     "nop\nnop\nnop\nnop"); }

void delayms(uint16_t millis) {
  uint16_t loop;
  while ( millis ) {
    loop = 100;
    while (loop) {
      /* 20us of delays */
      delayus(); delayus(); delayus(); delayus(); delayus();
      delayus(); delayus(); delayus(); delayus(); delayus();
      loop --;
    }
    millis--;
  }
}

int main(void) {
  DDRD |= 1<<PD1; /* set PD1 to output */
  while(1) {
    PORTD |= 1<<PD1; /* LED on */
    delayms(100);
    PORTD &= ~(1<<PD1); /* LED off */
    delayms(900);
  }
  return 0;
}

And save this as Makefile:

CC=/usr/local/atmel/bin/avr-gcc
CFLAGS=-g -Os -Wall -mcall-prologues -mmcu=atmega8
OBJ2HEX=/usr/local/atmel/bin/avr-objcopy 
UISP=/usr/local/bin/uisp 
TARGET=blink
PORT=/dev/ttyS0

program : $(TARGET).hex
	$(UISP) -dprog=stk500 -dserial=$(PORT) --erase -dpart=atmega8
	$(UISP) -dprog=stk500 -dserial=$(PORT) --upload -dpart=atmega8 \
		if=$(TARGET).hex -v=2
	$(UISP) -dprog=stk500 -dserial=$(PORT) -dpart=atmega8 \
		--wr_fuse_l=0xe4
%.obj : %.o
	$(CC) $(CFLAGS) $< -o $@

%.hex : %.obj
	$(OBJ2HEX) -R .eeprom -O ihex $< $@

clean :
	rm -f *.hex *.obj *.o

You should change the definition of PORT to your serial port. It is most likely either /dev/ttyS0 or /dev/ttyS1. If you have a USB-serial adapter, it will be something like /dev/tts/USB0. More information on USB-serial adapters for linux. With the programmer plugged in, type make. Your LED should now start to blink!

Further reading

Finally, much of this page was inspired by Guido Socher's 2002 article on avr-gcc. It's slightly out of date now but still contains a lot of useful details that I haven't gone into here.