Shop OBEX P1 Docs P2 Docs Learn Events
Boe- Bot for Arduino- program malfunctioning — Parallax Forums

Boe- Bot for Arduino- program malfunctioning

lotsofdottslotsofdotts Posts: 7
edited 2014-08-08 11:33 in Robotics
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.


// 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

  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-03-27 13:26
    The code looks fine, but without more information on your BOE-Bot setup it's hard to know what might be happening. Are you using your BOE-Bot with an Arduino and the Parallax BOE Shield? Or do you have your Arduino connected to the BOE-Bot some other way?

    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.
  • lotsofdottslotsofdotts Posts: 7
    edited 2014-03-27 20:06
    The picture of the assembled Boe-bot below is set up exactly like mine. I'm using the Parallax Boe Shield for Arduino with the DFRduino UNO R3 (Here's is the link for the product page in case you have questions: http://www.dfrobot.com/index.php?route=product/product&product_id=838#.UzThEmRDtqs). I have an AAx5 battery pack plugged into the DFRduino Uno R3. The battery pack was included with the Parallax BOEBot Robot for Arduino kit. I followed all of the directions in the tutorials for building the robot. When I started Chapter 4, which begins to go over how to make the wheels go forward for three seconds, is when it first started malfunctioning.
    mt_brd.jpg


    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.

    piezo_circ.png


    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.
    683 x 321 - 59K
    529 x 488 - 51K
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-03-27 22:50
    What's happening is that your Arduino is spontaneously restarting itself. This is most often caused by insufficient voltage to power it. Under a certain voltage -- about 4.6 volts -- it will go into brownout mode. The voltage sag can occur because the servos can take a healthy amount of current. With the heavy current the voltage to the Arduino to dip. The sketch actually helps identify this problem because it doesn't have anything in the loop() function. It will run its servo pattern only once, then stop. Yours isn't doing that, and is instead showing the Arduino keeps resetting itself. Apart from a defective Arduino, the problem is most likely power/current related.

    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.
  • FranklinFranklin Posts: 4,747
    edited 2014-03-28 09:51
    What type of batteries are you using? You need to have at least 6v to run everything.
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-03-28 14:01
    Franklin makes an excellent good point. If you're using rechargeable batteries, they output only 1.2 volts each; so the 5-cell pack for your BOE-Bot will only be six volts MAX. The Arduino uses a voltage regulator that requires a few volts overhead. The specs call for 7 volts minimum. You get 7.5 volts when using a set of five 1.5v non-rechargeable (or rechargeable alkaline) cells.
  • ercoerco Posts: 20,255
    edited 2014-04-08 10:26
    Hey, now where did that bitchin' gold anodized BoeBot chassis come from?
  • Steph LindsaySteph Lindsay Posts: 767
    edited 2014-04-08 10:43
    erco wrote: »
    Hey, now where did that bitchin' gold anodized BoeBot chassis come from?

    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.
  • Steph LindsaySteph Lindsay Posts: 767
    edited 2014-04-08 10:46
    Franklin makes an excellent good point. If you're using rechargeable batteries, they output only 1.2 volts each; so the 5-cell pack for your BOE-Bot will only be six volts MAX. The Arduino uses a voltage regulator that requires a few volts overhead. The specs call for 7 volts minimum. You get 7.5 volts when using a set of five 1.5v non-rechargeable (or rechargeable alkaline) cells.

    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.
  • lotsofdottslotsofdotts Posts: 7
    edited 2014-04-08 16:54
    What's happening is that your Arduino is spontaneously restarting itself. This is most often caused by insufficient voltage to power it. Under a certain voltage -- about 4.6 volts -- it will go into brownout mode. The voltage sag can occur because the servos can take a healthy amount of current. With the heavy current the voltage to the Arduino to dip. The sketch actually helps identify this problem because it doesn't have anything in the loop() function. It will run its servo pattern only once, then stop. Yours isn't doing that, and is instead showing the Arduino keeps resetting itself. Apart from a defective Arduino, the problem is most likely power/current related.

    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.

    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.
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-04-08 17:24
    And the type of batteries you are using?
  • lotsofdottslotsofdotts Posts: 7
    edited 2014-04-09 14:36
    Sorry for the wait, I'm using non-rechargeables.
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-04-09 17:03
    Sorry for the wait, I'm using non-rechargeables.

    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.
  • lotsofdottslotsofdotts Posts: 7
    edited 2014-04-13 21:15
    I will try a fresh set of batteries from straight out of the box. But if that doesn't work, should I get a new 5xAA battery pack/ the BOE-Boost module, or should I buy a new Arduino Uno? Which one would you recommend that I should try first?
  • fdesjarlfdesjarl Posts: 2
    edited 2014-08-06 20:27
    Hi -- I'm also having a similar problem with this exercise on the learning site for Chapter 4 / Activity 1 "Moving Backward, Rotating, and Pivoting" (http://learn.parallax.com/node/219) for sketch 'ForwardLeftRightBackward'.

    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!
  • fdesjarlfdesjarl Posts: 2
    edited 2014-08-08 11:33
    To follow-up on my post -- the left servo (on pin 13) fell out of calibration. After re-calibrating, it worked great.
Sign In or Register to comment.