Baby Orangutan behaves oddly when ISP cable is unplugged

I’m having an issue with a rebellious little Baby-O. I’ll give you the setup then tell you the issue.

I’m using a Pololu USB AVR Programmer and a Micro Metal Gearmotor with the magnetic encoder pair installed. I have a program running on my Baby-O that reads serial sent through the USB-to-TTL adapter on the programmer and translates it to drive speed, then it sends back information on the last requested speed it got, encoder count etc.

Everything works as expected until I unplug the ISP cable from the Baby-O, at which point things get crazy. The motor starts moving erratically, rapidly changing speed and direction, and the Baby-O starts outputting garbage over the serial connection. So from that it seems like somehow unplugging the ISP is causing the serial connection to become garbage in both directions. When I plug the ISP cable back in, it goes back to behaving itself perfectly. Another strange thing is that when I plugged the ISP cable back in the first time, I got it backwards. But that still caused everything to return to normal.

BUT: when I put a different program on the Baby-O, things seem different.
I modified the “serial1” example program from libpololu-avr to turn the motor on or off rather than turn the LED on or off (full code pasted below), and that yields different results. Again, when the ISP cable is plugged in, we’re golden. When I unplug it though, the motor can still be controlled by sending ‘R’ or ‘r’, but the feedback i get from sending other characters it totally garbled. Seeming to suggest that the serial communication TO the Baby-O is working fine, but FROM is on the fritz. Out of desperation and curiosity, I went ahead and plugged the ISP cable in backwards on this program too to see if it would make everything work again like it had on my other program, and it didn’t. Instead it causes the Baby-O to send “Hi there!” as though the “middle button” (the Baby-O has no buttons) was pressed.

I’ve looked up the issue of AVR behavior changing when the ISP cable is unplugged, and it seems like the consensus is that it’s a power/grounding issue, but I’ve checked all the connections and the reset pin on the Baby-O and everything seems to be in order.

I’m totally at a loss, so any advice or leads would be very helpful!

Thanks!


Modified “serial1” example program:

#include <pololu/orangutan.h>  
  
char receive_buffer[32];

unsigned char receive_buffer_position = 0;

char send_buffer[32];

void wait_for_sending_to_finish()
{
	while(!serial_send_buffer_empty());
}

void process_received_byte(char byte)
{
	switch(byte)
	{
		case 'R':
			set_motors(100,100);
			break;
		case 'r':
			set_motors(0,0);
			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_received_byte(receive_buffer[receive_buffer_position]);

		if (receive_buffer_position == sizeof(receive_buffer)-1)
		{
			receive_buffer_position = 0;
		}
		else
		{
			receive_buffer_position++;
		}
	}
}

int main()
{
	serial_set_baud_rate(115200);

	serial_receive_ring(receive_buffer, sizeof(receive_buffer));

    while(1)
    {
		check_for_new_bytes_received();

		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_button_release(MIDDLE_BUTTON);
		}
    }
}

Hello.

Since your program is working fine when you have the ISP cable connected between your Baby Orangutan and AVR programmer, I do not suspect your code is causing the issue. You mentioned suspecting that power and ground might have been an issue but found nothing wrong with your connections. Can you post pictures of your setup clearly showing the connections between the Baby Orangutan and AVR programmer with the cable NOT connected so that I can double-check your connections?

- Amanda

Hi Amanda, thanks for your help!

Unfortunately it’s challenging to take pictures in my workplace. I’ll describe the connections (hopefully erring on the side of TOO detailed) and if a picture would still be helpful I’ll see what I can do…

So, with the ISP cable unplugged, the following connections exist:

  • USB AVR Programmer
  • Mini USB --> computer
  • TX --> PD0 on Baby-O
  • RX --> PD1 on Baby-O
  • Baby Orangutan
  • PD0 --> TX on AVR
  • PD1 --> RX on AVR
  • VIN --> external 5V 1A source
  • GND pad* --> external ground
  • GND pin --> GND on motor encoder
  • VCC pin --> VCC on motor encoder
  • M1A --> M1 on motor encoder
  • M1B --> M2 on motor encoder
  • PC0 --> OUT A on motor encoder
  • PC1 --> OUT B on motor encoder

*I’m not sure what the correct term is here. I’m referring to one of the two contact plates that are flat on the board next to the GND pin.

Hopefully that’s enough to get an idea of what’s going wrong!
Thanks again,
-Matthew

Solved! This is my first time working with serial communications and I failed to realize that the devices need a common ground. Added connection from AVL programmer GND to Baby-O GND and now it all works perfectly!

Thanks again for your reply Amanda :slight_smile:

Hi, Matthew.

Cool! I am glad you figured out the issue and fixed it; thanks for letting us know.

- Amanda