Help with digital IO for 3pi robot

Hi people. I am trying to use a digital IO from the 3pi robot to light up some LEDs. From what I understand, there are only 3 digital IOs I can use, PD0, PD1, and PC5. However, I am also using serial communication and so PD0 and PD1 are out of questions, which only leaves me PC5. Can anyone help me as to how to configure PC5 to be a GPIO?

You should be able to find a ton of examples online for the chip that runs the robot - the atmega328p. Any examples you find for the atmega168 or 328 will work, plus many examples from other AVR chips.

The answer you are looking for depends on whether you want to use it as an I or O for general purpose IO. It also depends on whether you need to enable pull up or pull down resisters.

In short, you need to set the direction of the pin you are reading or writing to. Then, its really just a matter of reading the register of the port containing the pin.

The data direction register you are interested in is DDRC (Data Direction Register C). The port register you need is PORTC. The pin (bit) you want to manipulate is PORTC5.

DDRC |=(1<< PORTC5); //set pin 5 (6th) on port c as an output.
PORTC |= (1<<PORTC5);// Turn pin 5 on.
PORTC &= ~(1<<PORTC5); //turn pin 5 off.

That should work, assuming no typos.

Make sense?


Don’t forget to remove the PC5 jumper that connects it to the line sensor emitters, and make sure you use an appropriate current-limiting resistor for your LED. The information that Louie gave you will work, but the Pololu AVR library has routines that that are probably a bit easier to use than the low-level AVR registers. Please see the command reference for more information:

The Pololu AVR library download also includes the digital1 example, which uses these digital I/O routines to turn the PD1 LED on and off.

- Ben