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);
}
}
}