๐ŸŽ„โ›„โ„๏ธ๐ŸŽ It's beginning to look a lot like ADABOX-mas! The next ADABOX from Adafruit ships soon! Get yours now, or give as a gift! ๐ŸŽ„โ›„โ„๏ธ๐ŸŽ
0

Adabox 002 - motors not stopping
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adabox 002 - motors not stopping

by andriust on Thu Nov 07, 2019 3:37 pm

My daughter and I are enjoying buiding and starting to work with the Adabox 002 robot. We altered the DCMotorTest example sketch (below). The sketch runs as expected, with both wheels turing back and forth, until, at some point, both just start going full speed and do not stop. A reset stops them, after a little while, and then it starts working correctly, and then takes off again.

Can I get any help?

Thank you,

Andrius

Code: Select all | TOGGLE FULL SIZE
/*
This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2
It won't work with v1.x motor shields! Only for the v2's with built in PWM
control

For use with the Adafruit Motor Shield v2
---->   http://www.adafruit.com/products/1438
*/

#include <Wire.h>
#include <Adafruit_MotorShield.h>

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);

// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myLeftMotor = AFMS.getMotor(4);
// You can also make another motor on port M2
Adafruit_DCMotor *myRightMotor = AFMS.getMotor(3);

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Adafruit Motorshield v2 - DC Motor test!");

  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
 
  // Set the speed to start, from 0 (off) to 255 (max speed)
  myLeftMotor->setSpeed(255);
   myLeftMotor->run(FORWARD);
  // turn on motor
   myLeftMotor->run(RELEASE);

   
  // Set the speed to start, from 0 (off) to 255 (max speed)
  myRightMotor->setSpeed(255);
   myRightMotor->run(FORWARD);
  // turn on motor
   myRightMotor->run(RELEASE);
}

void loop() {
  uint8_t i;
 
  Serial.print("bek");

  myLeftMotor->run(FORWARD);
  myRightMotor->run(FORWARD);
  for (i=0; i<255; i++) {
    myLeftMotor->setSpeed(i); 
    myRightMotor->setSpeed(i); 
    delay(10);
  }
  for (i=255; i!=0; i--) {
    myLeftMotor->setSpeed(i); 
    myRightMotor->setSpeed(i); 
    delay(10);
  }
 
  Serial.print("tyl");

  myLeftMotor->run(BACKWARD);
  myRightMotor->run(BACKWARD);
  for(i=0; i<255; i++) {
     myLeftMotor->setSpeed(i);
     myRightMotor->setSpeed(i);   
     delay(10);
  }
  for (i=255; i!=0; i--) {
    myLeftMotor->setSpeed(i); 
    myRightMotor->setSpeed(i);
    delay(10);
  }

  Serial.print("rest");
  myLeftMotor->run(RELEASE);
  myRightMotor->run(RELEASE);
  delay(1000);
 
 
}

andriust
 
Posts: 3
Joined: Thu Nov 07, 2019 3:33 pm

Re: Adabox 002 - motors not stopping

by mikeysklar on Fri Nov 08, 2019 12:05 am

Hi andriust,

It looks like this code will take the motors all the way up to the full speed going forward and then all the way down. Then do the same with reverse. What would be your preference for behavior?

mikeysklar
 
Posts: 376
Joined: Mon Aug 01, 2016 8:10 pm

Re: Adabox 002 - motors not stopping

by andriust on Fri Nov 08, 2019 1:40 am

What you describe is my preference, and it is what I expect, but it is not what happens. The motors wind up to full speed forward, then wind down, then do the same for reverse. After doing this some number of times, the motors go up to full and stay there. This is not in the code.

What could be happening? What can I do to avoid this? And wasn't there some problem with Kias doing this about 15 years ago?

Andrius

andriust
 
Posts: 3
Joined: Thu Nov 07, 2019 3:33 pm

Re: Adabox 002 - motors not stopping

by mikeysklar on Fri Nov 08, 2019 4:23 pm

Hi andriust,

Thank you for the helpful clarification about the motor behavior you are seeing.

Maybe we should try a simple binary test which might be helpful for your daughter to see the debugging process.

How about eliminating the final two chunks of REVERSE code and see if the problem goes away. You could also sprinkle some print statements so that you can monitor the output on the console for what part of the code is being executed. I know it is a basic start, but might provide some clues.

mikeysklar
 
Posts: 376
Joined: Mon Aug 01, 2016 8:10 pm

Re: Adabox 002 - motors not stopping

by adafruit_support_bill on Fri Nov 08, 2019 5:27 pm

After doing this some number of times, the motors go up to full and stay there. This is not in the code.

If the loop is executing correctly a few times, then the problem is probably not software. My suspicion would be interference from the motors is causing the processor to misbehave.

Motors can be troublesome loads in a couple of ways:

At startup, the motor will draw a lot of current and this can cause a 'brownout' which can disrupt the processor. If things work better with a fresh set of batteries and degrade over time, that may be what is happening here.

And brushed DC motors like the one in the Adabox also generate a lot of electrical "brush noise" which can also feed back through the power lines and affect the processor. The remedy for this is a little more involved. Expand the FAQ question at this link to see what is involved:
https://learn.adafruit.com/adafruit-mot ... aq-2861890

adafruit_support_bill
 
Posts: 75036
Joined: Sat Feb 07, 2009 10:11 am

Re: Adabox 002 - motors not stopping

by johnpark on Fri Nov 08, 2019 7:41 pm

How are you powering the motor FeatherWing? Fresh, high quality alkalines are a good bet in troubleshooting brown-out like behavior.

johnpark
 
Posts: 617
Joined: Wed Mar 25, 2009 2:15 pm

Re: Adabox 002 - motors not stopping

by andriust on Fri Nov 08, 2019 8:21 pm

John - we are using the batteries that came in the box, which have probably been sitting there for years. When did these boxes come out? The Feather is being powered by the USB cable; we are still at the "place it on a coffee mug" stage. I'll replace the batteries as a first step.

Bill - thanks for the pointer to the solution with capacitors. I'll try it if changing the batteries does not work.

Andrius

andriust
 
Posts: 3
Joined: Thu Nov 07, 2019 3:33 pm

Please be positive and constructive with your questions and comments.