Parallax Ultrasonic Sensor and Orangutan Jr

That’s quite a microcontroller CV you’ve got there. Now I feel silly for going into such detail before.

Anyway, some AVRs have JTAG support, but the ATMega168 has Atmel’s own flavor of in-circuit debugger called debugWIRE, which you need their special programmer to access. Personally I’ve never used it.

You could hook in a MAX232 board, or you could use your Pololu USB programmer itself to handle the serial level shifting. The programmer has two chips, an ATMega48 with code to emulate a serial AVRISP programmer, and a CP2102 USB to TTL level serial adapter. The jumper on the programmer connects the adapter’s RX pin either to the ATMega48’s TX pin, or to that set of user-accessable TTL level TX, RX, and ground pads.

So basically you could connect the programmer’s (really the adapter’s) TX and RX pins to your Baby Orangutan’s RX and TX pins, and communicate serially over the same com port you use to program, just not at the same time. The programming header should even take care of the ground connection (although real AVRISP’s have a nasty tendency of resetting your (my) board at the worst possible time when you leave them connected).

The down side to this is that 1) you have to close the programmer window (but not AVRStudio itself) and connect your terminal program each time you want to talk to a program you just downloaded, and 2) you need to move the jumper, or make some kind of physical switch to switch the RX line from program to talk.

By the way, whatever you decide to do, here’s some code to setup and test your Baby O’s USART (make sure it’s set to run off its 20MHz external oscillator, or change F_CPU to 8000000 in the code if it’s running of of its internal 8MHz clock):

#define F_CPU 20000000//CPU clock
#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>

volatile unsigned char newSerCmd=0;
volatile unsigned char serCmd;

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<<RXEN0)|(1<<TXEN0);//enable reciever & transmitter, recieve interrupt
	UCSR0B|=(1<<RXCIE0);
	UCSR0C=(3<<UCSZ00);//Set frame format for 8bit with 1 stop
}

void USART_Trans (unsigned char data){//Transmit a byte of data over USART
	while(!(UCSR0A&(1<<UDRE0)));//wait for transmition to complete
	UDR0=data;
}

ISR(USART_RX_vect){//USART Byte reieved
	serCmd=UDR0;
	newSerCmd=1;
}

int main(){
	USART_Init(MYUBRR);

	USART_Trans('H');
	USART_Trans('i');
	USART_Trans(0X0D);//Carriage Return

	sei();//enable global interrupts

	while(1){
		if(newSerCmd){
			USART_Trans('T');
			USART_Trans('e');
			USART_Trans('s');
			USART_Trans('t');
			USART_Trans(0X0D);//Carriage Return
			newSerCmd=0;
		}
	}

	return 0;
}

-Adam

P.S. Oh man, if the USB to Serial programmer broke out all of the ATMega48 pins I would so get one just to use the MCU itself with built in serial<->USB. Oh well, maybe on the Baby X2…