beautypg.com

C. available i/o on the 3pi's atmegaxx8 – Pololu 3pi Robot User Manual

Page 60

background image

// get the line position

serial_send("\xB6", 1);

int line_position[1];

if(serial_receive_blocking((char *)line_position, 2, 100))

break;

// get the battery voltage

serial_send("\xB1",1);

// read 2 bytes

int battery_millivolts[1];

if(serial_receive_blocking((char *)battery_millivolts, 2, 100))

break;

// display readings

display_levels((unsigned int*)buffer);

lcd_goto_xy(5,0);

line_position[0] /= 4; // to get it into the range of 0-1000

if(line_position[0] == 1000)

line_position[0] = 999; // keep to a max of 3 chars

print_long(line_position[0]);

print(" ");

lcd_goto_xy(0,1);

print_long(battery_millivolts[0]);

print(" mV ");

delay_ms(10);

// if button A is pressed, increase motor1 speed

if(button_is_pressed(BUTTON_A) && speed1 < 127)

speed1 ++;

else if(speed1 > 1)

speed1 -= 2;

else if(speed1 > 0)

speed1 = 0;

// if button C is pressed, control motor2

if(button_is_pressed(BUTTON_C) && speed2 < 127)

speed2 ++;

else if(speed2 > 1)

speed2 -= 2;

else if(speed2 > 0)

speed2 = 0;

// if button B is pressed, do PID control

if(button_is_pressed(BUTTON_B))

slave_set_pid(40, 1, 20, 3, 2);

else

{

slave_stop_pid();

slave_set_motors(speed1, speed2);

}

}

}

while(1);

}

10.c. Available I/O on the 3pi's ATmegaxx8

The easiest way to expand your 3pi’s capabilities is probably to turn your 3pi into a “smart base” that is controlled
by the microcontroller of your choosing, as described in

Section 10.a

. This allows you to connect your additional

electronics to your secondary microcontroller and only requires you to make connections to pins PD0 and PD1 on the
3pi. These two pins are completely unused digital I/O lines that connect to the ATmegaxx8’s UART module when that
module is enabled. You can freely use PD0 and PD1 for general-purpose digital I/O, or you can use them for serial
communication with another microcontroller, a serially-controlled device, or a computer (note that you will need to
convert the signal to RS-232 levels or USB to communicate with a computer).

Pololu 3pi Robot User's Guide

© 2001–2014 Pololu Corporation

10. Expansion Information

Page 60 of 63