Boe- Bot for Arduino- program malfunctioning
lotsofdotts
Posts: 7
Hello, I'm a newbie to robotics. This is the first Arduino project I've done. Right now, I'm working on a basic program that tells the two servos on my robot to go forward for 2 seconds, turn left in place for 1 second, turn right in place for 1 second, and then go backward for 2 seconds. I will attach the code below.
When I test the program while it's propped up on a small box (so it won't drive off the table), it works fine. The wheels both go forward, then turn one way, turn the other way, and go backwards. I also have a tone at the beginning (under void setup) so I know when the program starts. The problem is when I unplug the robot from the programming cord ( usb to serial). The wheels go forward for 1.5 to 2 seconds, and then it plays the start-up tone and the wheels go forward again. This cycle, forward and beep, continues indefinitely, even though it's under the setup function.
I checked the batteries to see if it was a brownout problem, and they're all fine. Hopefully somebody here can give me some suggestions as to what the problem might be.
When I test the program while it's propped up on a small box (so it won't drive off the table), it works fine. The wheels both go forward, then turn one way, turn the other way, and go backwards. I also have a tone at the beginning (under void setup) so I know when the program starts. The problem is when I unplug the robot from the programming cord ( usb to serial). The wheels go forward for 1.5 to 2 seconds, and then it plays the start-up tone and the wheels go forward again. This cycle, forward and beep, continues indefinitely, even though it's under the setup function.
I checked the batteries to see if it was a brownout problem, and they're all fine. Hopefully somebody here can give me some suggestions as to what the problem might be.
// Robotics with the BOE Shield - ForwardLeftRightBackward
// Move forward, left, right, then backward for testing and tuning.
#include <Servo.h> // Include servo library
Servo servoLeft; // Declare left and right servos
Servo servoRight;
void setup() // Built-in initialization block
{
tone(4, 3000, 1000); // Play tone for 1 second
delay(1000); // Delay to finish tone
tone(4, 4500, 3000);
delay(3000);
servoLeft.attach(13); // Attach left signal to pin 13
servoRight.attach(12); // Attach right signal to pin 12
// Full speed forward
servoLeft.writeMicroseconds(1700); // Left wheel counterclockwise
servoRight.writeMicroseconds(1300); // Right wheel clockwise
delay(2000); // ...for 2 seconds
// Turn left in place
servoLeft.writeMicroseconds(1300); // Left wheel clockwise
servoRight.writeMicroseconds(1300); // Right wheel clockwise
delay(1000); // ...for 0.6 seconds
// Turn right in place
servoLeft.writeMicroseconds(1700); // Left wheel counterclockwise
servoRight.writeMicroseconds(1700); // Right wheel counterclockwise
delay(1000); // ...for 0.6 seconds
// Full speed backward
servoLeft.writeMicroseconds(1300); // Left wheel clockwise
servoRight.writeMicroseconds(1700); // Right wheel counterclockwise
delay(2000); // ...for 2 seconds
servoLeft.detach(); // Stop sending servo signals
servoRight.detach();
}
void loop() // Main loop auto-repeats
{ // Empty, nothing needs repeating
}
Comments
Please describe your setup, and provide a picture, if possible.
The fact that it works with the USB connected, but not when USB is unplugged, sounds like it's a problem with Arduino power, regardless of how you tested the individual batteries. Be sure to power the servos from an AAx4 battery pack, not just a 9V battery for the Arduino. Be sure the ground connections for all battery packs are shared with the Arduino. The Parallax BOE Shield takes care of all of this for you, so if you're not using it now, the shield might be something you'll want to invest in.
In addition to the LEDs connected to the mini breadboard (see picture above for the layout), I also have a piezo speaker connected. The piezo speaker is connected exactly the same way as below.
Hopefully, this answers your questions. I also just want to thank for helping me figure this out. I'm just a beginner, and I don't know what I'm doing. I find it is extremely helpful to have someone with more knowledge on the subject help me figure out what's going wrong.
You might double-check that your shield is properly connected to the Arduino, and that none of the pins got cross-inserted into the headers. Be sure to run your BOE-Bot with the switch in the #2 position. You need to be sure the jumper beside the servo connectors is set to 5V, not Vin. These are small things easily missed when building the robot.
If you'd like, you can pull the stuff off the breadboard to simplify things for you. Comment out the first four lines in the setup() function. Recompile, and upload the new sketch to your Arduino. You can use the servo movement alone to verify proper function.
Many years ago, Parallax anodized the Boe-Bot chassis in gold, blue, and what was supposed to be red but turned out magenta, for a short time. Andy chose the gold chassis for taking photographs in his Robotics with the Boe-Bot text, since the images when printed in black and white turned out the best. Some of those images are still in use, as so noted in the Shield-Bot web tutorial.
Yes, exactly, thank you Franklin and Gordon.
If you still want to use 1.2 V rechargeable batteries, you can use the BOE-Boost module to add a 6th battery --- it slips in between the ends of the batteries and the terminals in the battery holder. That will bring the voltage back up to 7.2 V.
If you want to splurge, we also carry a Li-Ion Battery Pack/Charger designed to fit inside the small robot chassis.
I have double checked, and the pins are already properly lined up. The jumper was already set to 5V. I haven't changed the program at all and it still isn't working properly.
Then I'm at a loss if you're using 5 (not 4) non-rechargeable batteries and you've tried a FRESH set you just got from the pack ("checking" them like with a meter isn't enough -- old batteries can show near-full voltage when not under load). What you describe happens when the Arduino doesn't get enough juice from the batteries.
The robot beeps, goes forward for 2 seconds, and then spins right for about 2-3 seconds before it stops (it doesn't repeat itself). I copy/pasted the code from the lesson.
I haven't had issues with any other code from the learn.parallax.com site (for this kit) up until this activity. I checked all 5 of my non-rechargeable batteries with a multimeter and they all read between 1.45 and 1.55 V.
The servo from the kit (http://www.parallax.com/product/130-35000) is http://www.parallax.com/product/900-00008 .
Any ideas what could be wrong?
Thanks!