Serial Comm to 3pi

I am currently trying to control my 3pi via serial commands from a baby orangutan. I first loaded the slave example into the 3pi and loaded the master example into the baby. I am getting very inconsistent results. Most often the 3pi just beeps and prints Bad cmd, usually with a 30, but other numbers will cycle through. Occasionally it will work and print out Connect and play the music as expected.

I also tried controlling via an Arduino. I can get more consistent results with the Arduino, I can always control and print to the LCD and I can turn the motors on and off with no problem. However, if I try to get the battery level by sending a 0xB1 I get a bad command 13.

Am I doing something wrong? Is there an easy way for me to narrow down the problem area?

Hello,

How is everything connected and powered?

-Paul

When using the baby orang I have 5v going into the Vin, the 3pi is battery operated. When using the arduino I have that powered by a 9v wallwart.

Hello,

The Baby Orangutan is the one that is giving you trouble, so can you say what the 5V power supply is and exactly what all of your connections are for that setup? (Something like “PD3 on the Baby Orangutan is connected through a 50ft phone cable to the negative terminal of the supply, etc…”) A picture would help a lot.

-Paul

Thanks for the help Paul. After playing some more I dumbed down the master example since it looks like it won’t work well with the Baby O, it is looking for button presses and sending stuff out to an LCD which the Baby O doesn’t have. I commented everything out of main() and replaced it with the code at the end. I get very inconsistent results. At first I got it to print start on the 3pi lcd and got all the way to the battery check before it reported a bad command. Now it doesn’t even print start just says bad cmd, sometimes it will get various pieces to work for example start and tune won’t print, just give bad cmd but Motors will print and the motors will turn on. Attached is a picture of how I have it wired up. Power is a USB cable that is connected to my PC, I measured it and it is giving out 5v.

Also, the arduino does not consistently work. I can always get it to drive the motors and work the LCD. But if I try to read the battery I get a bad cmd. I am going through all the cmds to see which work and which don’t. I will report back on what I find.


int main()
{

char buffer[20];

// load the bar graph
load_custom_characters();

// configure serial clock for 115.2 kbaud
serial_set_baud_rate(115200);

slave_clear();
slave_print("Start");

delay_ms(2000);

// play a tune
slave_clear();
slave_print("Tune");
char tune[] = "\xB3 l16o6gab>c";
tune[1] = sizeof(tune)-3;
serial_send_blocking(tune,sizeof(tune)-1);

delay_ms(2000);

slave_clear();
slave_print("Motors");
slave_set_motors(20, 20);
delay_ms(1000);
slave_set_motors(0, 0);

delay(2000);

slave_clear();
slave_print("Auto Cal");
slave_auto_calibrate();

delay(2000);

// get the battery voltage
slave_clear();
slave_print("Get Bat");
serial_send("\xB1",1);
  
// read 2 bytes
int battery_millivolts[1];
if(serial_receive_blocking((char *)battery_millivolts, 2, 100))

delay_ms(2000);

slave_clear();
slave_print("Done");

Hello.

Your picture doesn’t do a very good job of showing your connections, but I only see two wires, neither of which is ground. A lack of a common ground between your Arduino/Baby Orangutan and your 3pi would explain why you’re getting inconsistent results.

- Ben

Hi Ben, thanks for the response, I don’t know why the photo was cropped when I uploaded. I attached a picture of the Baby O. So are you saying I need to add a ground pin on the 3pi and run a wire from there to ground? I hope this isn’t too basic of a question I am new to electronics and am learning as I go.

Ed


Hello,

If you grounds are not connected one way or another, you need to connect them with a wire. That is one of the reasons I kept asking you for how things are connected!

-Paul

Paul and Ben, thanks so much for your help. With the ground now connected everything is working much better.

Ed