Trouble using Pololu USB programmer as serial interface

I am trying to make the Orangutan controller interface with a computer via Orangutan USB programmer. I assume from the programmer description (since the manual is vague on this), that by moving the jumper I change it into a serial-USB interface. Now I try to write code for this and I find that all serial output code examples involve the standart UART ports PB0 and PB1, while the programmer connects to PB4 and PB5. :frowning:
Please tell me if there is a way to use pins PB4 and PB5 to communicate via the programmer. Alternatively, if I need to use pins PB0 an PB1, point me to the connection instructions.

It sounds like you’re talking about trying to use the USB programmer as a serial interface with only the 6-pin programming cable connected, is this correct? While that would be INCREDIBLY convenient, it’s not quite how things work. I don’t think there are any serial connection instructions on the website beyond the brief mention of USB to Serial Adapter Mode in the user’s guide, so lets make some up now.


The Pololu Orangutan USB Programmer has two main chips. The one on the left is a CP2102 USB to Serial adapter, the same chip used in the Pololu USB to Serial Adapter board. It interfaces over a USB connection with the virtual serial port drivers on your computer, and provides a TTL level serial interface. The chip on the right is an ATMega48 microcontroller, programmed to emulate an AVRISP programmer. It is connected to the USB to Serial Adapter chip on the left, and the six pin programming header on the right.

For reasons of compatibility (i.e. tricking most any software into thinking that it’s connecting to an AVRISP programmer) it makes sense not to try to add extra features that use the programming chip, like pass-through modes of communication. Also, the programmer communicates with the target device (your Orangutan) over an SPI interface, which is a little different from the UART serial connection your computer serial port (real or virtual) uses.

As I mentioned before, Pololu sells that same USB to Serial adapter chip on a board all by itself for $20, so it would be very nice to have direct access to it. When you move that blue jumper up from the position pictured you’re physically disconnecting the serial RX line of the USB to serial adapter chip from the programmer emulator chip, and connecting it to the pin labeled “PC’s RX” in that set of three pins at the top center of the picture.

The way to use the programmer board as a USB to Serial adapter is to connect those three pins (GND, PC’s RX, PC’s TX) to your Orangutan. The programmer’s GND pin should go to one of the Orangutan’s ground pins, and normally the programmer’s RX pin would go to PD1, the Orangutan’s TX line, with the programmer’s TX pin connected to PD0, the Orangutan’s RX line. I’m not sure what example code you’re referring to, but I assume that’s what you meant to write. If you’re emulating a serial protocol in the Orangutan’s software (“bit-banging”) rather than using the built-in UART hardware, you can make these connection to whatever pins you want to use.

So, I hope that answers your question. Any luck getting your computer and Orangutan talking?

-Adam

P.S. If you’re going to leave the programming cable connected, you don’t need to wire up a second ground connection.

1 Like

Adam,

Thank you for the advice - this is a valuable addition to the manual.
I managed to make the computer and uC talk one way (uC to PC), but it is not working the other way. For this test I use uart_test.c from Orangutan library on Sourceforge. Can it be a hardware issue, or purely code?

Hmm, it could be a couple of things, even just a bad wire, but I don’t think it’s anything wrong with the program. The good news is that you’ve cleared most of the hurdles, or you wouldn’t be able to see the text printed by your Orangutan in the first place. I’m assuming it gets up to the point in the program where it asks you to “Enter some text and ENTER:”, but doesn’t send you anything back as you type?

Are you sure that the “PC’s TX” pin is connected to PD0 on the Orangutan? What terminal program are you using to talk to your Orangutan? Since you can see text I’m assuming you were able to select the right com port, and configure the settings to 9600 bps, 8 bits, no parity, and 1 stop bit. You should also make sure that the “handshaking” or “flow control” option is set to “none”.

Even though I don’t think it’s a problem with the program, you could try this very simple, standalone serial test code (assuming your Orangitan is running at 8MHz). It basically configures the UART for 9600 bps, says “Hello”, then waits for you to send it lower-case ASCII characters. Whenever it receives a character it sends back the character capitalized. If you send it bytes other than lower-case ASCII characters you will get weird things back, play around with it. It’s very similar to the Orangutan-Lib test, but much less code and all in one place for you to see.

//#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);//enable transmitter & receiver
   UCSR0B|=(1<<RXCIE0);//enable receive complete interrupt
   UCSR0C=(3<<UCSZ00);//Set frame format for 8bit with 1 stop
}

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

ISR(USART_RX_vect){//USART Byte reieved
   dataIn=UDR0;//grab copy of serial byte
   newSerCmd=1;//indicate new byte received
}

int main(){
   USART_Init(MYUBRR);//Initialize USART

   USART_Trans('H');//Say Hello
   USART_Trans('e');
   USART_Trans('l');
   USART_Trans('l');
   USART_Trans('o');
   USART_Trans(13);//carrage return

   sei();//enable global interrupts

   while(1){
      if(newSerCmd){//if new byte received
         USART_Trans(dataIn-32);//return received byte-32 (capitalized)
         newSerCmd=0;
      }
   }
   return 0;
}

Any luck?

-Adam

Adam,

Thank you very much for the advice. It took me some time to test it because my robot was taken apart for upgrade.
Your code works as expected. However the Orangutan-lib code still failed on the receiving side. Maybe I did not use it properly though. Anyways, I set up my MC for serial communications and ready to proceed with the rest of the project.