Adafruit motor/stepper shield v2.0

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
BradAZ
 
Posts: 2
Joined: Thu Apr 03, 2014 8:47 am

Adafruit motor/stepper shield v2.0

Post by BradAZ »

I recently purchased Adafruit motor/stepper shield v2.0, product id 1438, invoice# 462091, to replace my old shield - v1.2 product id 81
using stepper motor, product id 324, 200 steps/rev

I'am having a problem with the speed
setting speed to 50 only produces 22 rpm
setting speed to 100 only produces 28 rpm, not even close to twice the rpm
setting speed to 150 only produces 31 rpm
does not run smooth at all

The old shield works fine, speed of 50 produces 41 rpm, 100 produces 91 rpm
The old shield set at 22 rpm runs smoother than the new shield

I used same code for both shields only difference is libraries
Below is output of serial monitor for the new shield and the old shield, plus code used

Any suggestions with this problem

Serial monitor, old shield
speed=50 rpm=47
speed=100 rpm=91


Serial monitor, new shield
Estimated pre-scale: 2.81
Final pre-scale: 3
speed=50 rpm=22
speed=100 rpm=28

Code: Select all

// Test code for new shield v2.0

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

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

// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);

unsigned long int startTime, endTime,elapseTime;
int mtrSpeed,stepCnt,rpm;

void setup(){
  Serial.begin(9600);
  AFMS.begin();
}

void loop() {

    stepCnt=800; // 2 revolutions for INTERLEAVE
    mtrSpeed=50;
    myMotor->setSpeed(mtrSpeed);
    startTime=millis();
    myMotor->step(stepCnt, FORWARD, INTERLEAVE);
    endTime=millis();
    elapseTime=endTime-startTime;
    rpm = (stepCnt/400)*60000/elapseTime;
    Serial.print("speed="),Serial.print(mtrSpeed),Serial.print(" rpm="),Serial.println(rpm);
    delay(500);
    
    mtrSpeed=100;
    myMotor->setSpeed(mtrSpeed);
    startTime=millis();
    myMotor->step(stepCnt, FORWARD, INTERLEAVE);
    endTime=millis();
    elapseTime=endTime-startTime;
    rpm = (stepCnt/400)*60000/elapseTime;
    Serial.print("speed="),Serial.print(mtrSpeed),Serial.print(" rpm="),Serial.println(rpm);
    
    myMotor->release();
    while(true){}
  
}


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

Re: Adafruit motor/stepper shield v2.0

Post by adafruit_support_bill »

There are a couple of factors at work here. One is that the step timing does not take into account the shield communication overhead. Since the V2 shield uses i2c, its overhead is significantly higher than the V1.x shields. The other problem is that the default i2c bus speed is 100KHz. You start running into this limit pretty quickly with a high-step-count motor.

It is possible to increase the i2c bus speed. This will reduce the step timing error and increase your top speed: http://learn.adafruit.com/adafruit-moto ... rduino/faq
Why won't my stepper motor go any faster?

Since the shield is controlled by i2c, the maximum step rate is limited by the i2c bus speed. The default bus speed is 100KHz and can be increased to 400KHz by editing the library file in your Arduino installation folder. The file can be found in hardware/libraries/wire/utility/twi.h.

Find the line with: "#define TWI_FREQ 100000L"
and change it to "#define TWI_FREQ 400000L"

Or, you can add the following code to your setup() function:

TWBR = ((F_CPU /400000l) - 16) / 2; // Change the i2c clock to 400KHz

BradAZ
 
Posts: 2
Joined: Thu Apr 03, 2014 8:47 am

Re: Adafruit motor/stepper shield v2.0

Post by BradAZ »

disappointed with output speed, wish the old version, v1.2 was still available

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

Return to “Arduino Shields from Adafruit”