Orangutan X2 Serial Help

Hello everyone,

I am kind of a new user with the X2 and want to communicate serially my computer using the hardware uart.
I have tried the orangutan libs with no result so i am trying first to determine the problem with a simpler program.
I am using this code from the forum that i think checks ok with the datasheet (MYUBRR=130 and datasheet suggests 129 for 20mhz 9600baud but i tried changing it manually and still got nothing)
I connected tx and rx (pd1 and pd0 respectively to my computer(laptop) via a usb-serial converter and have checked the connections)

When i connect the terminal instead of receiving HELLO i get scrambled symbols and cant figure out what im doing wrong.
The terminal settings are 8bit 1 stop no parity no flow control

Thank you for your help

#define BAUD 9600
#define F_CPU 20000000UL
#define MYUBRR F_CPU/16/BAUD-1

#include <avr/io.h>
#include <util/delay.h>

void USART_Init(unsigned int ubrr){
   UBRR0H=(unsigned char)(ubrr>>8);//set baud rate at 9600
   UBRR0L=(unsigned char) ubrr;
   UCSR0B=(1<<RXEN0)|(1<<TXEN0);//enable reciever & transmitter
   UCSR0C=(3<<UCSZ00);//Set frame format for 8bit with 1 stop

void USART_Trans (unsigned char data){
   while(!(UCSR0A&(1<<UDRE0)));//wait for transmit empty

int main (void){
   USART_Trans (72);
   USART_Trans (69);
   USART_Trans (76);
   USART_Trans (76);
   USART_Trans (79);




What are you using for a USB-to-serial adapter? Is there a reason you want to send your serial data directly from the ATmega644 rather than via the X2’s USB connection with its built-in serial functionality?

- Ben


It reports as a Prolific-usb-serial adapter.
I want to interface a motor controller that reports its stats (Alltrax motor controller for an electrathon) (voltage, amperage etc) via a serial port it has so that is why i need the serial port directly, and wanted to verify I knew how to communicate serially first and had working code.

What would you recommend? Does the code look alright? Should i try to communicate without the adapter to a desktop PC with a max232?

I don’t know about your particular USB-to-serial adapter, but a little bit of googling around leads me to believe it might be a USB-to-RS-232-serial adapter, which would explain why it isn’t working right. RS-232 is inverted serial, and it typically is at levels that are out of spec for digital signals (e.g. -12V to 12V). You need a converter that outputs non-inverted TTL serial, such as our USB-to-serial adapter, as that’s the interface the UART module on AVRs expects. Do you know if your adapter is RS-232 or TTL?

- Ben

Hello, thank you for answering so fast.
Googling a bit i found my adapter is based on the Prolific PL-2303 which indeed is a USB-RS232 adapter.
If i use a MAX232 between the serial end and the Orangutan would it work?
Like this laptop usb—> usb-r232adapter —> max232—> orangutan uart
so its ttl–> ttl -rs232 ---->rs232 ttl —> ttl
Or am i thinking crazy?
If not i will try on my desktop pc with just a max232 directly to the serial.

The only thing i want to verify is if the serial configuration in the program is ok before trying to interface the motor controller where i will have little feedback to guide me as it uses a strange communication protocol which someone just reversed engineered.

Thank you for your help i will try these and report back if i need more help.

Yeah, you should be able to use a max232 between your USB-to-serial adapter (or PC serial port) and the Orangutan X2. It will function both as a level-shifter and inverter.

It’s more like:

serial through a virtual COM port via the USB interface -> USB - RS-232 -> RS-232 - TTL -> TTL serial

Which motor controller are you trying to talk to?

- Ben

Thank you for your help Ben, using the MAX232 between the adapter and the X2 did indeed work.
The problem was indeed my confusion between RS232 and TTL levels.

The motor controller is an alltrax 4834 that drives an etek motor for an electrathon, the throttle is controlled by a 0 to 5kohms potentiometer, the serial is only to read stats such as voltage and current consumption.

Thanks again,