0

I have an Arduino Uno connected to the Adafruit Motorshield v2. I have it hooked up to a stepper motor(27BYJ-48). I am trying to make the motor do one complete revolution. However, the number of steps I specify to the stepper motor(200 in the code) doesn't affect the motor steps. For example, the 2200 step in this code, is roughly one rotation and is completely unaffected by change the steps/revolution specified when instantiating the motor. How do I get the motor to do one exact revolution?

Here is the code on the arduino:

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

Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
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

  myMotor->setSpeed(2000);  // 10 rpm   
}

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

Edit: Wiring: Wiring from Motorshield to Stepper

enter image description here

7
  • What happens if you disconnect the red wire?
    – James
    Commented Mar 24, 2016 at 1:03
  • Also change the 200 at AFMS.getStepper(200, 2); to 64. The spec sheet says 5.625 degrees per step -> so the motor does 64 steps for 1 revolution.
    – James
    Commented Mar 24, 2016 at 1:07
  • Nothing changes, motor turns same as before. Changing the the code also did not change anything.
    – johnidel
    Commented Mar 24, 2016 at 1:07
  • That's the RPM, so with 10 it does 10 a minute, however, it is painfully slow and goes much slower than that. So yes, setting the RPM there does not actually convert to the real RPM.
    – johnidel
    Commented Mar 24, 2016 at 1:16
  • 1
    This motor is a unipolar type, right? Wiring is thus a bit different than a bipolar. The AFMS expects bipolar by default if I remember correctly. In any case, double check their doc for more info on how to connect unipolar/bipolar steppers.
    – CQuinson
    Commented Mar 24, 2016 at 10:45

2 Answers 2

1

Ok so I'm not familiar with the sheild or API (or motor lol) but going off the spec sheets etc

Leave the red wire disconnected [see 1] and try this code and report back what happens:

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

  Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
  Adafruit_StepperMotor *myMotor = AFMS.getStepper(64, 2); // 64 steps pr revolution
                                                           // Using M3 and M4 of shield

  void setup() 
  {
    AFMS.begin();  // create with the default frequency 1.6KHz
    myMotor->setSpeed(30);  // 30 rpm, so 1 full turn every 2sec  
  }

  void loop() 
  {  
    // 64 steps per motor shaft revolution,
    // 64 revolutions of motor per output shaft revolution
    myMotor->step(4096, FORWARD, DOUBLE);    // Should be 1 rev in one direction
    myMotor->step(4096, BACKWARD, DOUBLE);   // and 1 rev in other direction
  }

[1] : your motor is unipolar (wikipedia on unipolar and bipolar motors), according to its documentation. The red wire is the central tap, and useless in this context.

6
  • It goes forward and back incredibly minutely, i had to up the values from 2 just to acknowledge it was working.
    – johnidel
    Commented Mar 24, 2016 at 2:05
  • Try 128 steps (2 rev's)...how long in seconds for each rev?
    – James
    Commented Mar 24, 2016 at 2:24
  • It goes ~20 degree back and forth, each 30 degree takes about 2 seconds
    – johnidel
    Commented Mar 24, 2016 at 2:42
  • 1
    Maybe there is some gearing on the motor. It might be called the speed variation ratio in the spec sheet (1/64). Let's assume thats it and so we could say 64 steps multiplied by 64 (allow for the gearing ratio for 1 turn). Can you edit the code to be... step(4096, Forward, Double);? Try that.
    – James
    Commented Mar 24, 2016 at 3:06
  • edited code above
    – James
    Commented Mar 24, 2016 at 3:16
1

I also tested 27BYJ-48 stepper motor with instructables source code. It works but I had the same "complete revolution" problem. They compute on their website that a revolution contains 4096 steps.

As @James said, indeed, there is gearing inside the stepper motor. The problem is the gearing could be different for the exact same reference ! Everything is described here : 28BYJ-48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.