Accel_ConstantSpeed Example

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
RonLat
 
Posts: 2
Joined: Sat Dec 03, 2022 7:18 am

Accel_ConstantSpeed Example

Post by RonLat »

Hardware:
Adafruit Motor Shield V2.3
Arduino UNO Rev 3
Adafruit NEMA17 Stepper Motor 12V

After the installation of the libraries for the Adafruit Motor Shield, there are some examples in the Arduino IDE 2.0 in File > Examples > Adafruit Motor Shield V2 Library. While the example Accel_MultiStepper works just fine, the example Accel_ConstantSpeed moves the stepper only one step per second. It is supposed to move the motor at a constant speed. Changing the

Code: Select all

Astepper1.setSpeed(50)
to some higher value does not have any effect. What is the reason for this strange behavior of this code?

Code: Select all


#include <AccelStepper.h>
#include <Adafruit_MotorShield.h>

Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *myStepper1 = AFMS.getStepper(200, 2);

// you can change these to DOUBLE or INTERLEAVE or MICROSTEP!
void forwardstep1() {
  myStepper1->onestep(FORWARD, DOUBLE);
}
void backwardstep1() {
  myStepper1->onestep(BACKWARD, DOUBLE);
}

AccelStepper Astepper1(forwardstep1, backwardstep1);

void setup()
{
   Serial.begin(9600);
   Serial.println("Stepper test!");

  if (!AFMS.begin()) {         // create with the default frequency 1.6KHz
  // if (!AFMS.begin(1000)) {  // OR with a different frequency, say 1KHz
    Serial.println("Could not find Motor Shield. Check wiring.");
    while (1);
  }
  Serial.println("Motor Shield found.");

  Astepper1.setSpeed(200);
}

void loop()
{
  Astepper1.runSpeed();
}

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

Re: Accel_ConstantSpeed Example

Post by adafruit_support_bill »

Looking at the library code from the airspayce site, the only constraint I see on setSpeed is that it is not allowed to exceed maxSpeed. Try calling setMaxSpeed in your setup with a speed at least as high as setSpeed.

https://www.airspayce.com/mikem/arduino ... 6ec929c18f

User avatar
RonLat
 
Posts: 2
Joined: Sat Dec 03, 2022 7:18 am

Re: Accel_ConstantSpeed Example

Post by RonLat »

Thank you!

the setMaxSpeed() function in the setup is, what is missing in this example skatch. Now the motor runs with a constant speed.

Code: Select all

void setup(){
   Serial.begin(9600);
   Serial.println("Stepper test!");

  if (!AFMS.begin()) {
    Serial.println("Could not find Motor Shield. Check wiring.");
    while (1);
  }
  Serial.println("Motor Shield found.");

  Astepper1.setMaxSpeed(400);
  Astepper1.setSpeed(300);
}

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

Re: Accel_ConstantSpeed Example

Post by adafruit_support_bill »

Good to hear that solved it. Thanks for the update!

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

Return to “Arduino Shields from Adafruit”