In Windows I would write a C program that looked something like this:
/*Serial Control Test Program for Windows
V 1.0
Adam Borrell
5/27/08*/
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#include <time.h>
//Function Prototypes
HANDLE openPort(int);
HANDLE comPort;
//Global Variables
int done=0;
DWORD len;
unsigned char buff[1];
int main(){
char input[32];
int i;
printf("Pololu Serial Servo Controller Test Program\n\n");
comPort=openPort(1);//***PUT YOUR COM PORT NUMBER HERE!***
if(done){
printf("Program Terminated!\n");
system("PAUSE");
return -1;
}
printf("Commmands:\n");
printf("F - Forward\n");
printf("R - Reverse\n");
printf("S - Stop\n");
printf("BACKSPACE - Exit\n\n");
while (!done) {//***Simple keyboard interface
*input = getch();
switch(*input){
case 8://backspace
done = 1;
break;
case'f':
case'F':
printf("FORWARD!\n");
buff[0]=128;
WriteFile(comPort,&buff,1,&len,0);
break;
case'r':
case'R':
printf("REVERSE!\n");
buff[0]=129;
WriteFile(comPort,&buff,1,&len,0);
break;
case's':
case'S':
printf("STOP!\n");
buff[0]=130;
WriteFile(comPort,&buff,1,&len,0);
break;
default:
break;
}
}
CloseHandle(comPort);
printf("Program Terminated!\n");
system("PAUSE");
return 0;
}
HANDLE openPort(int portnum){
char port[]="com", pnum[]="Error";
itoa(portnum,pnum,10);
strcat(port,pnum);
HANDLE serial=CreateFile(port,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if(serial==INVALID_HANDLE_VALUE){
if(GetLastError()==ERROR_FILE_NOT_FOUND){
printf("Error, %s Not Found\n\a", port);
done=1;
return;
}
printf("Com Error\n\a");
done=1;
return;
}
DCB dcbSerialParams={0};
dcbSerialParams.DCBlength=sizeof(dcbSerialParams);
if(!GetCommState(serial, &dcbSerialParams)){
printf("Com State Error\n\a");
done=1;
return;
}
dcbSerialParams.BaudRate=CBR_9600;//CBR_baudrate
dcbSerialParams.ByteSize=8;
dcbSerialParams.Parity=NOPARITY;//NOPARITY, ODDPARITY, EVENPARITY
dcbSerialParams.StopBits=ONESTOPBIT;//ONESTOPBIT, ONE5STOPBITS, TWOSTOPBITS
if(!SetCommState(serial, &dcbSerialParams)){
printf("Serial Protocol Error\n\a");
done=1;
return;
}
COMMTIMEOUTS timeouts={0};
timeouts.ReadIntervalTimeout=50;
timeouts.ReadTotalTimeoutConstant=50;
timeouts.ReadTotalTimeoutMultiplier=10;
timeouts.WriteTotalTimeoutConstant=50;
timeouts.WriteTotalTimeoutMultiplier=10;
if(!SetCommTimeouts(serial,&timeouts)){
printf("Timeout Setting Error\n\a");
done=1;
return;
}
return serial;
}
You can download the source here.
I would also load a code like this onto the Orangutan or Baby Orangutan:
/*Serial Control Test Program for Orangutan or Baby Orangutan
V 1.0
Adam Borrell
5/27/08*/
#define F_CPU 20000000//CPU clock for Baby Orangutan
//#define F_CPU 8000000//CPU clock for Orangutan
//***Uncomment ONE of the above lines for the specific device***
#define BAUD 9600//baud rate for UART
#define MYUBRR (F_CPU/16/BAUD-1)//baud rate variable for UART hardware
#include <avr/io.h>
#include <avr/interrupt.h>
unsigned volatile char dataIn,newSerCmd=0;
void USART_Init(unsigned int ubrr){//Initialize USART hardware & settings for Serial Radio
UBRR0H=(unsigned char)(ubrr>>8);//set buad rate
UBRR0L=(unsigned char) ubrr;
UCSR0B=(1<<TXEN0)|(1<<RXEN0)|(1<<RXCIE0);//enable transmitter & receiver, receive complete interrupt
UCSR0C=(3<<UCSZ00);//Set frame format for 8bit with 1 stop
}
ISR(USART_RX_vect){//USART Byte reieved
dataIn=UDR0;//grab copy of serial byte
newSerCmd=1;//indicate new byte received
}
int main(){
DDRB|=(1<<PB1);//setup output pins
DDRD|=(1<<PD5);
USART_Init(MYUBRR);//Initialize USART
sei();//enable global interrupts
while(1){
if(newSerCmd){//if new byte received
switch(dataIn){
case 128://forward
PORTB|=(1<<PB1);
PORTD&=~(1<<PD5);
break;
case 129://reverse
PORTB&=~(1<<PB1);
PORTD|=(1<<PD5);
break;
case 130://stop
PORTB&=~(1<<PB1);
PORTD&=~(1<<PD5);
break;
default:
break;
}
newSerCmd=0;
}
}
return 0;
}
You can download the source here.
The Windows program opens a com port (at 9600 BPS, 8 data bits, no parity, one stop bit), and when you press the F, R, or S keys (upper or lower case) it sends arbitrarily selected byte values out the com port. When you hit backspace the program closes the com port.
The AVR program configures the hardware USART (again for 9600 BPS, 8 data bits, no parity, one stop bit), and sets up the byte received interrupt. When there is a byte received it checks if it has one of the (arbitrary) values corresponding to the key presses in the Windows program, and takes some action. If you pressed F, it sets one of the motors going forward, if you pressed R it sets that motor backwards, and if you pressed S it stops the motor. On the big Orangutan it’s the right motor port, I’m not sure which motor port it is on the Baby Orangutan. There’s no PWM here, the code is directly manipulating the H-bridge pins.
I just tried both and they work for me. They’re not completely commented, but this code I can really answer questions about. Note that there’s a place in the Windows code to specify your com port number, and a place in the AVR code to specify which Orangutan you’re using (really just what clock speed it’s running at).
-Adam
P.S. You’ll still need a serial adapter of some sort.