Issue Changing RPM of a Stepper

Hi all,

I am running a stepper motor (Stepper motor - NEMA-17 size - 200 steps/rev, 12V 350mA : ID 324 : $14.00 : Adafruit Industries, Unique & fun DIY electronics and kits) using an Uno and Adafruit motor shield (Adafruit Motor/Stepper/Servo Shield for Arduino v2 Kit [v2.3] : ID 1438 : $19.95 : Adafruit Industries, Unique & fun DIY electronics and kits). I am trying to change the rotation speed of the stepper using the serial port, but it doesn't seem like I'm getting proper changes in speed below an input of 20.
(input of 5 corresponds to a RPM of 20
10=17
15=40,
20=16,
25=18.5
30=22
35=24,
60=37.5
ie its a pretty linear relationship after 20, but not before).
I've double checked my connections (ie coil 1 to M4 and coil 2 to M3) and everything looks fine, so I'm wondering if maybe there is something wrong with my code? I've attached it below here:

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

int speedvalue = 0;
int givendispvalue = 0;

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();

// Motor port #2 (M3 and M4) or #1 (M1 and M2)
Adafruit_StepperMotor *myStepper = AFMS.getStepper(200, 2);

void setup()
{
   Serial.begin(115200);           // set up Serial library at 115200 bps
   AFMS.begin();
   myStepper->setSpeed(speedvalue);
}

void loop()
{
   while (Serial.available()) {                                         //Only runs when serial input is available
      speedvalue = int(Serial.parseInt());
   }
   myStepper->setSpeed(speedvalue);
   if (speedvalue > 0){
      myStepper->step(10, FORWARD, SINGLE);                                
   } else if (speedvalue < 0 ){
      myStepper->step(10,BACKWARD, SINGLE);
   } else {
      myStepper->release();
   }
}

When I switch steps to micro there is no change in RPM, double follows the same trend as single, but different RPM values, interleave seems to be working ok.

Thanks for any help and/or suggestions!
Matt

Not using those libraries I post some suggestions.
Dig down in the documentation and find out about the limits of the stepper motor as well as the library range of speed.
Posting schematics could be valuable. What voltage are You applying to the stepper driver?
Myself, I'm fighting a stepper moving more than it should.....

I have read your posting several times and i do not see any mention of HOW you are measuring the RPM. Care to enlighten me?

Read this quote from the driver board: Instead of using a latch and the Arduino's PWM pins, we have a fully-dedicated PWM driver chip onboard. This chip handles all the motor and speed controls over I2C. Only two data pins (SDA & SCL in addition to the power pins GND & 5V) are required

Is that library using I2C to command the driver or is it using PWM?
Schematics please.

Thanks for the replies Railroader and Paul,

Railroader: The stepper motor can handle 12V and 350mA/phase, as far as I can tell (I'm fairly inexperienced) the library doesn't seem to limit the range. The motorshield has an input of 12V, schematic of the motorshield is attached(is this what you were looking for?). In this setup, it should be using I2C I think, but there is a way to PWM the stepper and drive it that way.

Paul: I am using a hall effect sensor and magnet to measure RPM. The standalone code:

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

Adafruit_MotorShield AFMS = Adafruit_MotorShield(); // Create the motor shield object with the default I2C address

const byte hallsensor = 2;       //The Hall effect sensor (HES) output connected to pin no 7 of Arduino due
volatile byte revolutions;       //To measure RPM
unsigned long timeold;           //To measure RPM
float measuredrpm;               //RPM value measured from HES

void setup() {
  Serial.begin(115200);             //Enables Serial Port
  timeold = 0;                    //Sets time storage to zero
  revolutions = 0;                //Set revolution count to zero
  AFMS.begin();               //Create with the default frequency 1.6KHz
  Wire.begin();                   //Enables I2C Port

}

void loop () { 
  RPM();
}
void isr() { 
   revolutions++;    //Each rotation, this interrupt function is run twice
}

void RPM(){
  attachInterrupt(digitalPinToInterrupt(hallsensor), isr, FALLING);     //Attaches interupt to HES signal
  pinMode(hallsensor, INPUT);                                           //Recieve data from HES
  while (revolutions >= 1) {          //Calculation for the RPM measured by HES
       measuredrpm = abs((float)60*1000/(millis() - timeold)*revolutions);
       timeold = millis();
       Serial.println(measuredrpm);
       revolutions = 0;
       }
  
     }

The RPM measurements are accurate, I've been verifying them by calculating by hand and have used this code on a few other project and haven't had any issues with it so far.

Thanks for both of your responses. I'm thinking I will just have to stay above 20 and then just the interleave setting if I need to go slower.

Not with what you have there.

Looking at your code, I do not see where you tell the software to move the motor more than just a few steps. If you want to motor to turn a full turn, you need to tell it that many steps to take.

What is the purpose of using a stepper if you need to treat it like a regular DC motor?

Hi Paul,

Thank you for your response.

For the PWM, changing out SINGLE with MICROSTEP will PWM the coils according to Adafruit's guide on the motor shield.

Eventually I will be pulsing the motor forwards and backwards and need better control over the distance traveled than what a DC motor can provide (I am trying to measure piezoelectric properties of PVDF nanofibers), but for now I am just troubleshooting some simplified code.

Thanks,
Matt