Artuino to Baby Orangutan Serial connection

I am trying to send some instructions from Arduino to Pololu's Baby Orangutan. Connected it all, got the right software but nothing works. Now I found this ominous line and I am suspicious that this is the root cause of my problem:

"Digital Pins 0-1/Serial In/Out - TX/RX (dark green) - These pins cannot be used for digital i/o (digitalRead and digitalWrite) if you are also using serial communication (e.g. Serial.begin)."

Now, I am trying exactly the above, I am connecting to Baby-O from Arduino's pins 0 and 1. I thought that it would be logical to connect Arduino's RX/TX pins to Baby-O's TX/RX pins. But it seems that it is not logical.

Can somebody please explain.

You can't connect switches or LEDs to pins 0 and 1, if you want to be able to send data to the Serial Monitor.

If the data that you are sending to and getting from pins 0 and 1 is coming only from the Serial.print(), Serial.println(), Serial.write(), or Serial.read() functions, you are OK.

If that is the case, and you are having problems, we'd need to see the code, and how the Arduino and Orangutan are connected.

You did connect grounds together, too, didn't you?

yeah, grounds are connected OK>

I am googling all over the world and it seems that problem is caused by me supplying power to Arduino from USB cable. My Arduino program is using Serial.print() and Serial.read(), while Arduino is connected via USB cable to PC and via pin 0 and 1 (RX/TX) to Baby Orangutan. Now, that seems to be confusing Arduino's UART chip.

If I understand this correctly, I need to supply power to Arduino from battery, not USB and than UART conflict will go away.

Does that sound right?

The problem I think is the multiple connections to the ATMega UART - you have the USB/FTDI (or AT8MU2) chip on the lines, and you have the Orangatan on the same lines. Built in electrical conflict.

Can you talk to the orangatan via newsoftserial instead using other pins? Or run from battery and disconnect USB connection as you say.

I'll do what crossroads suggests and report back.

I am totally down on luck, I tried all the above.

I wrote some new code for Arduino, based on NewSoftSerial. Code simply sends character ‘B’ to Baby-O every 3 sec, from the pin 7. But more of a problem is luck of adequate code for Baby-O. Here are both pieces of code I am using:

Arduino code:

/*
 * There are internal UART / USB / RX/TX conflicts that prevent Arduino from simultaneous
 * reading from pins 0 and 1 (RX/TX) and being connected to USB. In order to bypass that
 * I am trying here NewSoftSerial.h library, by modifying this example:
 * 
 *   http://www.pololu.com/docs/0J44/6.7.1
 *
 * We will be using pin 6 (RX) and pin 7 (TX) on Arduino.
 *
 */
#include <NewSoftSerial.h> 
#include <LiquidCrystal.h>

#define rxPin 6  // pin 6 connects to SMC TX  (not used in this example)
#define txPin 7  // pin 7 connects to SMC RX 

NewSoftSerial mySerial =  NewSoftSerial(rxPin, txPin);

int  intBufferLength = 0;
byte incomingByte    = 'B';    // Arduino receiving incoming serial data into int variable.
char charIn;                   // Arduino receiving incoming serial data into char variable.
char charTag[]       = "len";  // Experimental: making array of characters.
char chrarIn[16];              // Experimental: making empty array of characters.

boolean blnBuffer = false;

// Initialize the library for the LCD display.
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  
  // Set up the LCD:
  lcd.begin(16, 2);
  // Print startup message to LCD.
  lcd.print("NSS-9.6 kbaud");
  delay(2000);                  // waits for a two seconds,

  // initialize software serial object with baud rate of 9.6 kbps
  mySerial.begin(9600);
}

void loop() {

  mySerial.print(0x42, BYTE);     // Transmit 'B' character back to NewSoftSerial.

  delay(3000);                    // Wait a second or two.
}

Baby-O code (with some redundant pieces):

#include <pololu/orangutan.h>  
  
/*  
 * serial1: for for the Orangutan LV, SV, SVP, X2, Baby-O and 3pi robot.
 *
 * This example listens for bytes on PD0/RXD.  Whenever it receives a byte, it
 * performs a custom action.  Whenever the user presses the middle button, it
 * transmits a greeting on PD1/TXD.
 *
 * The Baby Orangutan does not have a green LED, LCD, or pushbuttons so
 * that part of the code will not work.
 *
 * To make this example compile for the Orangutan SVP or X2, you
 * must add a first argument of UART0 to all the serial_* function calls
 * to receive on PD0/RXD0 and transmit on PD1/TXD0.
 * 
 * http://www.pololu.com/docs/0J20 
 * http://www.pololu.com  
 * http://forum.pololu.com  
 */   

// receive_buffer: A ring buffer that we will use to receive bytes on PD0/RXD.
// The OrangutanSerial library will put received bytes in to
// the buffer starting at the beginning (receiveBuffer[0]).
// After the buffer has been filled, the library will automatically
// start over at the beginning.
char receive_buffer[32];

// receive_buffer_position: This variable will keep track of which bytes in the receive buffer
// we have already processed.  It is the offset (0-31) of the next byte
// in the buffer to process.
unsigned char receive_buffer_position = 0;

// send_buffer: A buffer for sending bytes on PD1/TXD.
char send_buffer[32];

// My function added to show some reaction, on Baby-O, to received input:
void on_input_blink_red_x3() {

    red_led(1);              // red LED on
    delay_ms(200);           // waits for a second
    red_led(0);              // red LED off
    delay_ms(200);           // waits for a second

    red_led(1);              // red LED on
    delay_ms(200);           // waits for a second
    red_led(0);              // red LED off
    delay_ms(200);           // waits for a second

    red_led(1);              // red LED on
    delay_ms(200);           // waits for a second
    red_led(0);              // red LED off
    delay_ms(200);           // waits for a second
}

void on_input_blink_red_x2() {

    red_led(1);              // red LED on
    delay_ms(200);           // waits for a second
    red_led(0);              // red LED off
    delay_ms(200);           // waits for a second

    red_led(1);              // red LED on
    delay_ms(200);           // waits for a second
    red_led(0);              // red LED off
    delay_ms(200);           // waits for a second
}

void on_input_blink_red_x1() {

    red_led(1);              // red LED on
    delay_ms(100);           // waits for a second
    red_led(0);              // red LED off
    delay_ms(100);           // waits for a second
}

// wait_for_sending_to_finish:  Waits for the bytes in the send buffer to
// finish transmitting on PD1/TXD.  We must call this before modifying
// send_buffer or trying to send more bytes, because otherwise we could
// corrupt an existing transmission.
void wait_for_sending_to_finish() {

	while(!serial_send_buffer_empty());
}

// process_received_byte: Responds to a byte that has been received on
// PD0/RXD.  If you are writing your own serial program, you can
// replace all the code in this function with your own custom behaviors.
void process_received_byte(char byte) {

	switch(byte) {

		// If the character 'B' is received, turn on the green LED.
		case 'B':
			on_input_blink_red_x3();
			break;

		// If the character 'b' is received, turn off the green LED.
		case 'b':
			on_input_blink_red_x2();
			break;

		// If any other character is received, change its capitalization and
		// send it back.
		default:
			wait_for_sending_to_finish();
			send_buffer[0] = byte ^ 0x20;
			serial_send(send_buffer, 1);
			break;
	}
}

void check_for_new_bytes_received() {

	while(serial_get_received_bytes() != receive_buffer_position) {

		// Process the new byte that has just been received.
		process_received_byte(receive_buffer[receive_buffer_position]);

		// Increment receive_buffer_position, but wrap around when it gets to
		// the end of the buffer. 
		if (receive_buffer_position == sizeof(receive_buffer)-1) {
			receive_buffer_position = 0;
		} else {
			receive_buffer_position++;
		}
	}
}

int main() {

	// Set the baud rate to 9600 bits per second. Each byte takes ten bit
	// times, so you can get at most 960 bytes per second at this speed.
	serial_set_baud_rate(9600);


	// Start receiving bytes in the ring buffer.
	serial_receive_ring(receive_buffer, sizeof(receive_buffer));

on_input_blink_red_x3();

    while(1) {

		// Deal with any new bytes received.
		check_for_new_bytes_received();

		// If the user presses the middle button, send "Hi there!"
		// and wait until the user releases the button.
		if (button_is_pressed(MIDDLE_BUTTON)) {

			wait_for_sending_to_finish();
			memcpy_P(send_buffer, PSTR("Hi there!\r\n"), 11);
			serial_send(send_buffer, 11);

			// Wait for the user to release the button.  While the processor is
			// waiting, the OrangutanSerial library will take care of receiving
			// bytes using the serial reception interrupt.  But if enough bytes
			// arrive during this period to fill up the receive_buffer, then the
			// older bytes will be lost and we won't know exactly how many bytes
			// have been received.
			wait_for_button_release(MIDDLE_BUTTON);
		}
    }
}

Does anybody have a working example of code for serial communication between Arduino and Pololu's Baby Orangutan?

Can you connect newsoft serial to something else to confirm it is actually being sent? Hate to chase a ghost…

I don't know anything about the Baby Orangutan beyond its general description, but for testing I would connect the Baby Orangutan ground to the arduino ground, and the Baby Orangutan rx pin to the arduino rx pin. Then I would send Baby Orangutan commands using the serial monitor and see if the Baby Orangutan did what was asked. If this works, the Baby Orangutan programming is probably ok. Next you might put a serial echo sketch on the arduino, and connect the Baby Orangutan rx to the arduino tx to see if the Baby Orangutan responded to the commands being echoed back from the arduino.