Motor Shield V2.3 - Stepper Motor Doesn't Stop?

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
GorillaDetective
 
Posts: 7
Joined: Sun Oct 28, 2018 1:16 pm

Motor Shield V2.3 - Stepper Motor Doesn't Stop?

Post by GorillaDetective »

Hi,

Wondering if anyone can shed some light on why my stepper motor doesn't stop? I have it hooked up correctly I believe and I am powering the board with 12v. The stepper turns when I upload the code to the Arduino but I am expecting it to stop after the amount of steps I tell it to go and it just keeps turning, not sure why... I am expecting it to go 10 steps but it keeps turning. The stepper motor I am using is like this one https://www.aliexpress.com/item/4000222246368.html. Also, is there a code repository somewhere that gives more information on how to use the board than the simple tutorial does? Code below:

Code: Select all

#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); 

// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);


void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Stepper test!");

  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
  
  myMotor->setSpeed(10);  // 10 rpm   
}

void loop() {
  Serial.println("Double coil steps");
  myMotor->step(10, FORWARD, DOUBLE); 
}

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

Re: Motor Shield V2.3 - Stepper Motor Doesn't Stop?

Post by adafruit_support_bill »

Code: Select all

void loop() {
  Serial.println("Double coil steps");
  myMotor->step(10, FORWARD, DOUBLE);
}
The code in you loop tells it to go 10 steps. So it will go 10 steps and then stop. But the loop function in an Arduino program is repeated indefinitely. So once it stops, the loop immediately comes back around and does 10 steps again.

User avatar
GorillaDetective
 
Posts: 7
Joined: Sun Oct 28, 2018 1:16 pm

Re: Motor Shield V2.3 - Stepper Motor Doesn't Stop?

Post by GorillaDetective »

Thank you! Such a silly thing to over look! Appreciate it.

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

Return to “Arduino Shields from Adafruit”