28byj-48 stepper with adafruit motor shield v2.3

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
sadikcar
 
Posts: 11
Joined: Thu Dec 08, 2016 12:11 pm

28byj-48 stepper with adafruit motor shield v2.3

Post by sadikcar »

I am using motor shield v2.3 stacked on mega 2560 r3 and connected to 2 28byj-48 stepper motors.
Right now I am using a modified version of stepperTest example given along with adafruit library where the number of steps is 4096. and rpm=10
OBSERVATIONS:
only works at forward, double mode with rpm nearly 5 with a lot of heat
in backward, double mode : goes forward rpm nearly 1 with a lot of heat and vibrations

These were at 5v taken from the board itself. while using a 12v source, even the above motion are not observed and it becomes very hot and has too much vibrations

For my project, i need a precise number of revolutions and a decent rpm above 10-15 rpm (as max as possible).

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

Re: 28byj-48 stepper with adafruit motor shield v2.3

Post by adafruit_support_bill »

Stepper motors do tend to run quite warm. But it sounds like these may not be the right motors for the job. The high gear ratio requires a very high step rate. The V2 motor shield can tweaked to do up to about 1161 steps/second with some modifications to library and an increase of the i2c clock speed.
viewtopic.php?f=31&t=57041&p=292119
At 4096 steps/revolution, that works out to about 17 RPM with one motor. Half that for 2.

The other issue is that the exact gear ratios on these motors vary somewhat depending on the supplier. I've cracked open a few of them and the ratio is not quite exactly 16:1
viewtopic.php?f=31&t=41608&p=210339

User avatar
sadikcar
 
Posts: 11
Joined: Thu Dec 08, 2016 12:11 pm

Re: 28byj-48 stepper with adafruit motor shield v2.3

Post by sadikcar »

Thank You for the reply
So, does the motor shield support fractional no. of steps or do I have to modify the header file?
and is there a guarantee that if I get the no. of steps right then the motor will run smoothly?

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

Re: 28byj-48 stepper with adafruit motor shield v2.3

Post by adafruit_support_bill »

It does not accept fractional steps. But at high step rates, the inter-step timing is not very precise anyway.

The rough operation could be due to wiring issues. Although they can be run as unipolar motors, they typically perform better when wired for bipolar. How do you have them connected?

User avatar
sadikcar
 
Posts: 11
Joined: Thu Dec 08, 2016 12:11 pm

Re: 28byj-48 stepper with adafruit motor shield v2.3

Post by sadikcar »

The connections which I have made are as shown in figure

Code: Select all

/* 
This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2
It won't work with v1.x motor shields! Only for the v2's with built in PWM
control

For use with the Adafruit Motor Shield v2 
---->	http://www.adafruit.com/products/1438
*/


#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.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(4096, 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("Single coil steps");
  myMotor->step(1000, FORWARD, SINGLE); 
  delay(500);
  myMotor->step(1000, BACKWARD, SINGLE); 
  delay(500);

  Serial.println("Double coil steps");
  myMotor->step(4096/2, FORWARD, DOUBLE); 
  delay(500);
  myMotor->step(4096/2, BACKWARD, DOUBLE);
  delay(500);

  Serial.println("Interleave coil steps");
  myMotor->step(1000, FORWARD, INTERLEAVE); 
  delay(500);
  myMotor->step(1000, BACKWARD, INTERLEAVE); 
  delay(500);
  
  Serial.println("Microstep steps");
  myMotor->step(2000, FORWARD, MICROSTEP); 
  delay(500);
  myMotor->step(2000, BACKWARD, MICROSTEP);
  
  delay(1000);
  
}
This is the code i am using while on 5v from the mega board itself.it only works during the double forward mode that too with lower rpm.
Attachments
IMG_20161209_101319970.jpg
IMG_20161209_101319970.jpg (655.44 KiB) Viewed 1980 times

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

Re: 28byj-48 stepper with adafruit motor shield v2.3

Post by adafruit_support_bill »

That is unipolar wiring. Disconnect the red center-tap wire from the center ground connection for bipolar wiring.

User avatar
sadikcar
 
Posts: 11
Joined: Thu Dec 08, 2016 12:11 pm

Re: 28byj-48 stepper with adafruit motor shield v2.3

Post by sadikcar »

Thanks for the reply,
the motor is working smoothly now. but, it can only manage till 6 rpm, even after increasing the voltage from 5v and increasing the set speed.
also, I want to declare an array of stepper motors and shields;

Code: Select all

Adafruit_MotorShield AFMS[5] = {Adafruit_MotorShield(0x60), Adafruit_MotorShield(0x61), Adafruit_MotorShield(0x62), Adafruit_MotorShield(0x63), Adafruit_MotorShield(0x64)};
//all the motors

const int r=4076
Adafruit_StepperMotor *abmotor[10];

*abmotor[0] = AFMS[0].getStepper(r, 1);
While declaring a motor I am getting an error regarding expected constructor, destructor or type conversion before '=' sign.
I wonder if it is the correct syntax

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

Re: 28byj-48 stepper with adafruit motor shield v2.3

Post by adafruit_support_bill »

Which of those lines is it complaining about?
Please post the exact error text.

User avatar
sadikcar
 
Posts: 11
Joined: Thu Dec 08, 2016 12:11 pm

Re: 28byj-48 stepper with adafruit motor shield v2.3

Post by sadikcar »

the error lines are:

ab1:12: error: expected constructor, destructor, or type conversion before '=' token
expected constructor, destructor, or type conversion before '=' token

Code: Select all

#include <Wire.h>

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

Adafruit_MotorShield AFMS[5] = {Adafruit_MotorShield(0x60), Adafruit_MotorShield(0x61), Adafruit_MotorShield(0x62), Adafruit_MotorShield(0x63), Adafruit_MotorShield(0x64)};
//all the motors


Adafruit_StepperMotor *abmotor[10]={};

*abmotor[0] = AFMS[0].getStepper(r, 1);

here line 12: *abmotor[0] = AFMS[0].getStepper(r, 1);

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

Re: 28byj-48 stepper with adafruit motor shield v2.3

Post by adafruit_support_bill »

See this thread on the topic: viewtopic.php?f=31&t=96580&p=484379

User avatar
sadikcar
 
Posts: 11
Joined: Thu Dec 08, 2016 12:11 pm

Re: 28byj-48 stepper with adafruit motor shield v2.3

Post by sadikcar »

Thanks a lot, Sir,
the code now compiles like a breeze
just 1 more issue that is the motor still does not rotates in reverse.

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

Re: 28byj-48 stepper with adafruit motor shield v2.3

Post by adafruit_support_bill »

If it is a motor you purchased from us, we can try replacing it. Please contact [email protected] with a link to this thread and your order information.

User avatar
sadikcar
 
Posts: 11
Joined: Thu Dec 08, 2016 12:11 pm

Re: 28byj-48 stepper with adafruit motor shield v2.3

Post by sadikcar »

nope, i did not purchase the motors from you guys. so, I will figure out another way

I have encountered another problem.
this is a function defined globally

Code: Select all

void abreset(int abr[5][10])
{
  int i,j;
  for(i=0;i<10;i++)
  {
    for(j=1;j<5;j++);
    {
      if(abr[0][i]==1)
      {
        //servo[i] -60 deg
        abr[0][i]=0;
      }
      if(abr[j][i]==1)
      {
       abmotor[i]->step(4076, FORWARD, DOUBLE); // FWD
       abr[j][i]=0;
      }
    }
  }
} 
and as suggested I have initialised the motors in the setup

Code: Select all

void setup() {
  // put your setup code here, to run once:
 Serial.begin(9600);
 Serial.setTimeout(60000);

 Adafruit_StepperMotor *abmotor[10];

*abmotor[0]=AFMS[0].getStepper(r, 1);
*abmotor[1]=AFMS[0].getStepper(r, 2);
*abmotor[2]=AFMS[1].getStepper(r, 1);
*abmotor[3]=AFMS[1].getStepper(r, 2);
*abmotor[4]=AFMS[2].getStepper(r, 1);
*abmotor[5]=AFMS[2].getStepper(r, 2);
*abmotor[6]=AFMS[3].getStepper(r, 1);
*abmotor[7]=AFMS[3].getStepper(r, 2);
*abmotor[8]=AFMS[4].getStepper(r, 1);
*abmotor[9]=AFMS[4].getStepper(r, 2);


AFMS[0].begin();
AFMS[1].begin();
AFMS[2].begin();
AFMS[3].begin();
AFMS[4].begin();
 


 
}
I got an error as:

ab1.ino: In function 'void abreset(int (*)[10])':
ab1:310: error: 'abmotor' was not declared in this scope

which is a normal out of scope error. but, now I am in a fix as I can't declare the motors as global and I am also unable to insert them in a suitable function

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

Re: 28byj-48 stepper with adafruit motor shield v2.3

Post by adafruit_support_bill »

Hmmm. Is abmotor declared before abreset in your code?

User avatar
sadikcar
 
Posts: 11
Joined: Thu Dec 08, 2016 12:11 pm

Re: 28byj-48 stepper with adafruit motor shield v2.3

Post by sadikcar »

nope, it isn't.

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

Return to “Arduino Shields from Adafruit”