Motor Shield LED goes off when I plug in USB

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

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
Kushal11
 
Posts: 46
Joined: Mon Mar 28, 2016 6:59 pm

Re: Motor Shield LED goes off when I plug in USB

Post by Kushal11 »

Sorry for the mistake. Actually I want microstepping!

I changed the step type for both motors to MICROSTEP
Also changed from setMaxSpeed() to setSpeed() [I don't need accel/decelerations, constant speed is fine]
and from runSpeedToPosition() to run()

Please have a look again. Thanks for your continuous support.

Code: Select all

#include <AccelStepper.h>
#include <MultiStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

Adafruit_StepperMotor *myStepper1 = AFMStop.getStepper(200, 1);
Adafruit_StepperMotor *myStepper2 = AFMStop.getStepper(200, 2);

// wrappers for the first motor!
void forwardstep1() {  
  myStepper1->onestep(FORWARD, MICROSTEP);
}
void backwardstep1() {  
  myStepper1->onestep(BACKWARD, MICROSTEP);
}
// wrappers for the second motor!
void forwardstep2() {  
  myStepper2->onestep(FORWARD, MICROSTEP);
}
void backwardstep2() {  
  myStepper2->onestep(BACKWARD, MICROSTEP);
}

AccelStepper stepper1(forwardstep1, backwardstep1);
AccelStepper stepper2(forwardstep2, backwardstep2);

MultiStepper steppers;
void setup() {
  Serial.begin(9600);
  // Configure each stepper
  stepper1.setSpeed(100);
  stepper2.setSpeed(100);
  // Then give them to MultiStepper to manage
  steppers.addStepper(stepper1);
  steppers.addStepper(stepper2);
}
void loop() {
  long positions[2]; // Array of desired stepper positions
  
  positions[0] = 1000;
  positions[1] = 1000;
  steppers.moveTo(positions);
  steppers.run(); // Blocks until all are in position
  delay(1000);
  
  // Move to a different coordinate
  positions[0] = -100;
  positions[1] = 100;
  steppers.moveTo(positions);
  steppers.run(); // Blocks until all are in position
  delay(1000);
}

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

Re: Motor Shield LED goes off when I plug in USB

Post by adafruit_support_bill »

When using AccelSterpper, you can't have delays in your loop. You need to call the run() function on your steppers regularly, or they won't step.

Do all your motor setup in the setup() function, then just call run() in your loop().

User avatar
Kushal11
 
Posts: 46
Joined: Mon Mar 28, 2016 6:59 pm

Re: Motor Shield LED goes off when I plug in USB

Post by Kushal11 »

Ok so this code is working fine.
https://github.com/adafruit/Adafruit_Mo ... tepper.ino

Now in this code, when I call run() for both motors in the loop, do they actually run simultaneously or is there still a little delay as it calls run() for motor1 first and then for motor2. ? [Because it looks like it steps the first motor, then second motor, then loop starts again, steps first motor, then second motor....]

void loop()
{
stepper1.run();
stepper2.run();
}

User avatar
Kushal11
 
Posts: 46
Joined: Mon Mar 28, 2016 6:59 pm

Re: Motor Shield LED goes off when I plug in USB

Post by Kushal11 »

When I use MICROSTEP with just one motor in the loop, it gives me correct speed. But when I use second motor in the loop, my speed decreases by half. This doesn't happen while using DOUBLE steps.
Can you help me with this?

Code: Select all

#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

Adafruit_MotorShield AFMStop(0x60); // Default address, no jumpers

// Connect two steppers with 200 steps per revolution (1.8 degree)
// to the top shield
Adafruit_StepperMotor *myStepper1 = AFMStop.getStepper(200, 1);
Adafruit_StepperMotor *myStepper2 = AFMStop.getStepper(200, 2);

// wrappers for the first motor!
void forwardstep1() {  
  myStepper1->onestep(FORWARD, MICROSTEP);
}
void backwardstep1() {  
  myStepper1->onestep(BACKWARD, MICROSTEP);
}
// wrappers for the second motor!
void forwardstep2() {  
  myStepper2->onestep(FORWARD, MICROSTEP);
}
void backwardstep2() {  
  myStepper2->onestep(BACKWARD, MICROSTEP);
}

AccelStepper stepper1(forwardstep1, backwardstep1);
AccelStepper stepper2(forwardstep2, backwardstep2);

void setup()
{  
  AFMStop.begin(); // Start the top shield
   
  stepper1.setMaxSpeed(18000.0);
  stepper1.setAcceleration(100.0);
  stepper1.moveTo(5000);
      
  stepper2.setMaxSpeed(18000.0);
  stepper2.setAcceleration(100.0);
  stepper2.moveTo(5000);
}

void loop()
{
    stepper1.run();
    stepper2.run();   //Adding this second motor decreases my speed by half in Microstep mode
}


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

Return to “Arduino Shields from Adafruit”