Program a 3pi robot in C++

Is it possible to program my 3pi robot in C++ using the Atmel Studio 6?

When I create a new project the only option for the pololu template is C!

Hello. Yes, Atmel Studio supports C++ and there is nothing stopping you from using it on our programmable AVR products. Unfortunately, it is not easy to adapt our templates to C++ so you will have to start from scratch and configure Atmel Studio yourself:

  1. Create a new project in Atmel Studio and select the “GCC C++ Executable Project” template provided by Atmel. This can be found in the “C/C++” template category.
  2. In the Device Selection dialog, choose the model of AVR you are trying to program. For a recently-made 3pi, this would be the ATmega328P.
  3. Select Project > Properties… to open up the project properties window so you can properly configure your project to use the AVR libraries.
  4. Under “AVR/GNU Linker > Libraries”, click the little green icon to add the right library for your device. For ATmega328P-based devices like the 3pi, you would type “pololu_atmega328p”.
  5. Under “AVR/GNU C++ Compiler > Optimization”, check “Prepare functions for garbage collection (-ffunction-sections)”.
  6. Under “AVR/GNU Linker > Optimization”, check “Garbage collect unused sections (-Wl,–gc-sections).”

For more information about what these settings are and why you need them, see the “Using the Pololu AVR Library for your own projects” section of the Pololu AVR C/C++ Library User’s Guide.

Here is some fun code to get you started:

#include <pololu/orangutan.h>

class Output
  uint8_t pin;	
  Output(uint8_t pin) : pin(pin) { }
  void operator<<(uint8_t value){ set_digital_output(pin, value); }	

Output led(IO_D1);

int main(void)
    led << 1;
    led << 0;


Thanks a lot!

I have some more questions!

  1. Is it possible to just upload to the robot a compiled hex code with a simple way without using Atmel Studio?

  2. Is there any other lightweight compiler I can use to compile and upload programs to the 3pi robot?

Thanks again!

Yes and yes. You can use the WinAVR package. It contains the avr-gcc compiler and AVRDUDE, a utility for loading programs:

The user’s guide for the USB AVR programmer and the Pololu AVR Programming Quick Start Guide both have sections explaining how to use AVRDUDE. Our AVR library example code comes with Makefiles you can use.

In case you want a more up-to-date compiler, Atmel also releases their toolchain by itself: … ndows.aspx

What do you mean by lightweight?


I mean a compiler with litle system requirments and space. Able to run on a net book with 1GB RAM.

I’ve run the avr-gcc compiler with the avr-libc library on a Raspberry Pi Series 1 with 256 MB of RAM, running Linux, and it worked great.