Motor Shield v2.3 problems after pulling power

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ben_cowden
 
Posts: 26
Joined: Fri Jun 26, 2015 11:38 am

Motor Shield v2.3 problems after pulling power

Post by ben_cowden »

Hi. I have two Adafruit Motor Shield v2.3's running on a Metro M0 Express, driving 3 steppers. Each stepper has a leadscrew and a carriage that moves up and down. During testing, one of the carriages was about to collide with the chassis so I pulled the 12v plug, and now things are malfunctioning. What keeps happening is that every time the code begins (when I open the serial monitor), the first motor just starts driving in a direction, not at all in the sketch. I can't figure out how to get it to stop other than pulling the power, which puts me back at square 1. I tried restarting the computer, disconnecting power, pushing reset buttons, loading a different sketch. The Metro board is working (new sketch loaded). But the steppers keep malfunctioning. Any advice? Thanks!

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield v2.3 problems after pulling power

Post by adafruit_support_bill »

What keeps happening is that every time the code begins (when I open the serial monitor), the first motor just starts driving in a direction, not at all in the sketch.
The shield has no processor of its own and cannot step motors by itself. If motors are stepping continuously, it is because your sketch is continuously sending it step commands.

Please post the code that you are using.

User avatar
ben_cowden
 
Posts: 26
Joined: Fri Jun 26, 2015 11:38 am

Re: Motor Shield v2.3 problems after pulling power

Post by ben_cowden »

Thanks Bill. I actually think something bizarre is happening. I got things working again, but moved the problem stepper from one side of the shield to the other. I added tons of serial messages between each step so I could pinpoint where the error is happening. Things worked, but that one motor struggled under its load until *poof*, it ran smooth but just kept running, and I hit <reset> before it crashed. Now I have the same original problem: setup goes fine until this one moment when the motor just start turning and won't stop. Here's the code and a screenshot of where things go awry:

Code: Select all

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

Adafruit_MotorShield AFMStop = Adafruit_MotorShield(0x61); //right jumpers soldered
Adafruit_MotorShield AFMSbot = Adafruit_MotorShield(0x60); //bottom board with stacking headers

Adafruit_StepperMotor *myMotor1 = AFMStop.getStepper(200, 1);
Adafruit_StepperMotor *myMotor2 = AFMStop.getStepper(200, 2);
Adafruit_StepperMotor *myMotor3 = AFMSbot.getStepper(200, 2);

#define limit1 8 //Pin8 connected to the limit switch activate for limit switch
#define limit2 9 //Pin9 connected to the limit switch activate for limit switch
#define fill 5 //Pin5 connected to button for filling bitters syringe
#define button 4 //Pin 4 connected to button
int buttonState = 0;  //variable for reading the button
int spiid = 400;      //speed of motor variable
int steps1;           // Variable for pot1 reading
int steps2;           // Variable for pot2 reading
int steps3;           // Variable for pot3 reading


void setup() {
  Serial.begin(9600); // initialize serial communication at 9600 bits per second
  while (!Serial);    //only begins after serial monitor is opened
  Serial.println("Weeee! let's go!");  
  delay(100);
  
  Serial.println("Begin talking to the bottom board");  
  AFMSbot.begin(); 

  Serial.println("Begin talking to the top board");  
  AFMStop.begin();// create with the default frequency 1.6KHz
   
  Serial.println("setting speed");  
  myMotor1->setSpeed(spiid);     
  myMotor2->setSpeed(spiid);  
  myMotor3->setSpeed(spiid);

  Serial.println("Running Movement test");  
  for (int i=0; i<50; i++) {
    myMotor1->onestep(FORWARD, SINGLE);
    myMotor3->onestep(FORWARD, SINGLE);
    delay(3);
  }
    
  for (int i=0; i<50; i++) {
    myMotor1->onestep(BACKWARD, SINGLE);
    myMotor3->onestep(BACKWARD, SINGLE);
    delay(3);
  }

    Serial.println("starting homing procedure");  
  // Homing procedure at startup:
  
  while (digitalRead(limit1) == LOW) {  // Do this until the switch is activated   
      Serial.println("Homing");
      myMotor3->step(1, BACKWARD, SINGLE); 
   }
  while (digitalRead(limit1) == HIGH) { // Do this until the switch is not activated
      myMotor3->step(1, FORWARD, SINGLE);
  }
  steps3=0;  // Reset position variable to zero
  
  while (digitalRead(limit2) == LOW) {  // Do this until the switch is activated   
      Serial.println("Homing");
      myMotor1->step(1, BACKWARD, SINGLE); 
   }
  while (digitalRead(limit2) == HIGH) { // Do this until the switch is not activated
      myMotor1->step(1, FORWARD, SINGLE);
  }
  steps1=0;  // Reset position variable to zero

   }


void loop(){
  // read the state of the pushbutton value:
buttonState = digitalRead(button);

if (digitalRead(button) == HIGH) { //if the button is pressed
    steps1 = map(analogRead(A0), 1, 1023, 50, 1200);
    steps2 = map(analogRead(A1), 1, 1023, 30, 100);
    steps3 = map(analogRead(A2), 1, 1023, 50, 1200);
    Serial.print("Bourbon pot = ");
    Serial.println(steps1);
    
    Serial.print("Vermouth pot = ");
    Serial.println(steps3);
    
    Serial.print("Bitters pot = ");
    Serial.println(steps2);

    delay (1000);
    pour();} //do the pour
  
else if (digitalRead(button) == LOW) {
  Serial.println("waiting...");
  while (digitalRead(fill) == HIGH) { //if the fill button is pressed
    Serial.println("Filling Bitters!");
    myMotor2->step(1, BACKWARD, DOUBLE);
    }
  myMotor2->release(); 
  delay (50);
  } 
}

void pour()
{
  Serial.println("pouring");
  
  Serial.println("Bourbon GO!");
  for (int i=0; i<steps1; i++) {
    myMotor1->step(1, FORWARD, DOUBLE);
    if  (digitalRead(fill) == HIGH) { //if the fill button is pressed
      bourbonHome();
    }
  }
  while (digitalRead(limit2) == LOW) {  // Do this until the switch is activated   
      myMotor1->step(1, BACKWARD, DOUBLE); 
   }
  while (digitalRead(limit2) == HIGH) { // Do this until the switch is not activated
      myMotor1->step(1, FORWARD, INTERLEAVE);
  }
  steps1=0;  // Reset position variable to zero  myMotor1->release();

  Serial.println("Vermouth GO!");
  for (int i=0; i<steps3; i++) {
    myMotor3->step(1, FORWARD, DOUBLE);
    if  (digitalRead(fill) == HIGH) { //if the fill button is pressed
      vermouthHome();
    }
  }
  while (digitalRead(limit1) == LOW) {  // Do this until the switch is activated   
      myMotor3->step(1, BACKWARD, DOUBLE); 
   }
  while (digitalRead(limit1) == HIGH) { // Do this until the switch is not activated
      myMotor3->step(1, FORWARD, INTERLEAVE);
  }
  steps3=0;  // Reset position variable to zero  myMotor3->release();

  Serial.println("Bitters GO!");
  myMotor2->step(steps2, FORWARD, DOUBLE);
  
  myMotor1->release(); //release the motors so they don't have to maintain position
  myMotor3->release();
  myMotor2->release();

  delay (1000);
}

void bourbonHome()
{
  while (digitalRead(limit2) == LOW) {  // Do this until the switch is activated   
      myMotor1->step(1, BACKWARD, DOUBLE); 
   }
  while (digitalRead(limit2) == HIGH) { // Do this until the switch is not activated
      myMotor1->step(1, FORWARD, INTERLEAVE);
  }
  myMotor1->release(); 
  steps1=0;  // Reset position variable to zero  myMotor1->release();
}

void vermouthHome()
{
  while (digitalRead(limit1) == LOW) {  // Do this until the switch is activated   
      myMotor3->step(1, BACKWARD, DOUBLE); 
   }
  while (digitalRead(limit1) == HIGH) { // Do this until the switch is not activated
      myMotor3->step(1, FORWARD, INTERLEAVE);
  }
  myMotor3->release(); 
  steps3=0;  // Reset position variable to zero  myMotor3->release();
}
  

[img]
MotorDriveProblem.JPG
MotorDriveProblem.JPG (189.79 KiB) Viewed 129 times
[/img]

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield v2.3 problems after pulling power

Post by adafruit_support_bill »

Code: Select all

    Serial.println("starting homing procedure");  
  // Homing procedure at startup:
  
  while (digitalRead(limit1) == LOW) {  // Do this until the switch is activated   
      Serial.println("Homing");
      myMotor3->step(1, BACKWARD, SINGLE); 
   }
  while (digitalRead(limit1) == HIGH) { // Do this until the switch is not activated
      myMotor3->step(1, FORWARD, SINGLE);
  }
Most likely you have a bad switch connection and the input is stuck HIGH. So it skips the first loop and gets stuck in the second.

User avatar
ben_cowden
 
Posts: 26
Joined: Fri Jun 26, 2015 11:38 am

Re: Motor Shield v2.3 problems after pulling power

Post by ben_cowden »

Thanks Bill! I shouldn't be surprised that you are absolutely correct. I am very grateful for your help. I inserted some checks on the button inputs, and lo and behold! I ended up swapping the input pin for one of the limit switches (I tested the button itself, but it works fine), and we are all systems GO for the moment! Thanks!
MotorDriveProblem_BUTTON.JPG
MotorDriveProblem_BUTTON.JPG (195.29 KiB) Viewed 121 times

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield v2.3 problems after pulling power

Post by adafruit_support_bill »

Good to hear you have got it going. Thanks for the follow-up.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”