Arduino Forum

Using Arduino => Motors, Mechanics, and Power => Topic started by: celem on Dec 31, 2011, 08:46 pm

Title: 28BYJ-48 5-Volt Stepper
Post by: celem on Dec 31, 2011, 08:46 pm
FYI - below is some Arduino code that demonstrates bidirectional operation of a 28BYJ-48 5-Volt stepper motor. It does not use the Arduino library partly because I wanted to get a bit more hands-on with the stepper to learn its operation and partly because the library isn't designed for this type of stepper and the pin assignments need to flipped around to work. Plus, I don't think that the library correctly addresses the eight codes required for this stepper and, instead, uses only four codes. Anyway, this code works well for a functionality demo. The code is based on some general stepper code that I found on the web (I don't recall where) and modified for the  28BYJ-48 stepper. I have also attached a photo of the stepper and interface board that I am using - <$5 for both on eBay. I have also attached a schematic for the ULN2003 Driver Board.

Code: [Select]

// This Arduino example demonstrates bidirectional operation of a
// 28BYJ-48, which is readily available on eBay, using a ULN2003
// interface board to drive the stepper. The 28BYJ-48 motor is a 4-
// phase, 8-beat motor, geared down by a factor of 68. One bipolar
// winding is on motor pins 1 & 3 and the other on motor pins 2 & 4.
// Refer to the manufacturer's documentation of  Changzhou Fulling
// Motor Co., Ltd., among others.  The step angle is 5.625/64 and the
// operating Frequency is 100pps. Current draw is 92mA.  In this
// example, the speed and direction of the stepper motor is determined
// by adjusting a 1k-ohm potentiometer connected to Arduino pin A2.
// When the potentiometer is rotated fully counterclockwise, the motor
// will rotate at full counterclockwise speed. As the potentiometer is
// rotated clockwise, the motor will continue to slow down until is
// reaches its minimum speed at the the potentiometer's midpoint value .
// Once the potentiometer crosses its midpoint, the motor will reverse
// direction. As the potentiometer is rotated further clockwise, the speed  
// of the motor will increase until it reaches its full clockwise rotation
// speed when the potentiometer has been rotated fully clockwise.
////////////////////////////////////////////////

//declare variables for the motor pins
int motorPin1 = 8; // Blue   - 28BYJ48 pin 1
int motorPin2 = 9; // Pink   - 28BYJ48 pin 2
int motorPin3 = 10; // Yellow - 28BYJ48 pin 3
int motorPin4 = 11; // Orange - 28BYJ48 pin 4
                       // Red    - 28BYJ48 pin 5 (VCC)

int motorSpeed = 0;     //variable to set stepper speed
int potPin = 2; //potentiometer connected to A2
int potValue = 0; //variable to read A0 input


//////////////////////////////////////////////////////////////////////////////
void setup() {
 //declare the motor pins as outputs
 pinMode(motorPin1, OUTPUT);
 pinMode(motorPin2, OUTPUT);
 pinMode(motorPin3, OUTPUT);
 pinMode(motorPin4, OUTPUT);
 Serial.begin(9600);
}

//////////////////////////////////////////////////////////////////////////////
void loop(){

 potValue = analogRead(potPin);     // read the value of the potentiometer
 Serial.println(potValue);          // View full range from 0 - 1024 in Serial Monitor
 if (potValue < 535){               // if potentiometer reads 0 to 535 do this
   motorSpeed = (potValue/15 + 5);  //scale potValue to be useful for motor
   clockwise();                     //go to the ccw rotation function
 }
 else {                             //value of the potentiometer is 512 - 1024
   motorSpeed = ((1024-potValue)/15 + 5); //scale potValue for motor speed
   counterclockwise(); //go the the cw rotation function
 }
}

//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 1 to 4
//delay "motorSpeed" between each pin setting (to determine speed)

void counterclockwise (){
 // 1
 digitalWrite(motorPin1, HIGH);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin4, LOW);
 delay(motorSpeed);
 // 2
 digitalWrite(motorPin1, HIGH);
 digitalWrite(motorPin2, HIGH);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin4, LOW);
 delay (motorSpeed);
 // 3
 digitalWrite(motorPin1, LOW);
 digitalWrite(motorPin2, HIGH);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin4, LOW);
 delay(motorSpeed);
 // 4
 digitalWrite(motorPin1, LOW);
 digitalWrite(motorPin2, HIGH);
 digitalWrite(motorPin3, HIGH);
 digitalWrite(motorPin4, LOW);
 delay(motorSpeed);
 // 5
 digitalWrite(motorPin1, LOW);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin3, HIGH);
 digitalWrite(motorPin4, LOW);
 delay(motorSpeed);
 // 6
 digitalWrite(motorPin1, LOW);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin3, HIGH);
 digitalWrite(motorPin4, HIGH);
 delay (motorSpeed);
 // 7
 digitalWrite(motorPin1, LOW);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin4, HIGH);
 delay(motorSpeed);
 // 8
 digitalWrite(motorPin1, HIGH);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin4, HIGH);
 delay(motorSpeed);
}

//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 4 to 1
//delay "motorSpeed" between each pin setting (to determine speed)

void clockwise(){
 // 1
 digitalWrite(motorPin4, HIGH);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin1, LOW);
 delay(motorSpeed);
 // 2
 digitalWrite(motorPin4, HIGH);
 digitalWrite(motorPin3, HIGH);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin1, LOW);
 delay (motorSpeed);
 // 3
 digitalWrite(motorPin4, LOW);
 digitalWrite(motorPin3, HIGH);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin1, LOW);
 delay(motorSpeed);
 // 4
 digitalWrite(motorPin4, LOW);
 digitalWrite(motorPin3, HIGH);
 digitalWrite(motorPin2, HIGH);
 digitalWrite(motorPin1, LOW);
 delay(motorSpeed);
 // 5
 digitalWrite(motorPin4, LOW);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin2, HIGH);
 digitalWrite(motorPin1, LOW);
 delay(motorSpeed);
 // 6
 digitalWrite(motorPin4, LOW);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin2, HIGH);
 digitalWrite(motorPin1, HIGH);
 delay (motorSpeed);
 // 7
 digitalWrite(motorPin4, LOW);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin1, HIGH);
 delay(motorSpeed);
 // 8
 digitalWrite(motorPin4, HIGH);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin1, HIGH);
 delay(motorSpeed);
}

Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jan 11, 2012, 01:52 am
I've asked here in the motor forum.  I have the same hardware.  How do I make it go in reverse?  I tried using step(-64) in the library, it only goes forward.  Does this work for you?  If not, should I use your code instead?  If so, who not for me?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: celem on Jan 11, 2012, 02:25 am
If you use my code (above) counterclockwise() for one direction, clockwise() for the other. It works!
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jan 11, 2012, 06:31 am
Thanks!  Will try it.  Why doesn't the library work?
8 codes required for 28BYJ?
Only 4 in Stepper library?
Can anyone verify this?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: celem on Jan 11, 2012, 01:24 pm
Eight steps because the motor requires eight steps. See the manufacturer's spec sheet at http://tinyurl.com/6tt337n (http://tinyurl.com/6tt337n). I attempted to attach it but the forum complains that the upload area is full. However, the stepper library can be made to work. See: http://arduino-info.wikispaces.com/SmallSteppers (http://arduino-info.wikispaces.com/SmallSteppers)
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jan 11, 2012, 05:30 pm
The proper sequence is what I'm missing for reverse?
1,3,2,4 if I were using Arduino pins 1-4.
4,6,5,7 for my pins.
4,5,6,7 only goes forward?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jan 11, 2012, 05:37 pm
What is the advantage of using 8 sequences or phases in your code instead of 4?
More torque?
More speed?
Will try to measure it.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: celem on Jan 11, 2012, 06:36 pm
I do not personally know of a specific advantage other than this is how the manufacturer says that it should be done. It is intuitive that the manufacturer would not arbitrarily specify eight steps for no reason whatsoever. To turn the question around, do you anticipate some advantage for you to use the library function?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jan 11, 2012, 08:22 pm
No. It is a very minor advantage of simplicity.  Certainly I will use yours if there is any difference in performance.  Will let you know what I have measured.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jan 12, 2012, 09:49 pm
I was getting about 7RPM using 1,2,3,4 sequence in library.
15RPM with decent torque using 1,3,2,4 in library.
35RPM with your code and more torque!
I can't even stop it with my finger.
The improvement is like night and day.
You have to increase the speed gradually during ~10ms to achieve 35RPM.
Thanks!
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: celem on Jan 12, 2012, 10:12 pm
sbright33 - Thank you for reporting your test results. 8 is better than 4, after all.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: ajofscott on Jan 12, 2012, 11:27 pm
The 8 step is called a half step, on alternate steps one winding is powered down. One note, you would be best to use bitmasks and port writes so that all motor field changes happen in unison whereas your code has them happening sequentially.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: celem on Jan 12, 2012, 11:50 pm
Yes, I considered trying the bitmasks but was a bit lazy when I wrote the code.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jan 13, 2012, 06:03 am
It's a work in progress...
Will comment more when it's finished.
Questions?

Code: [Select]

// This Arduino example demonstrates bidirectional operation of a
// 28BYJ-48, which is readily available on eBay, using a ULN2003
// interface board to drive the stepper. The 28BYJ-48 motor is a 4-
// phase, 8-beat motor, geared down by a factor of 64. One bipolar
// winding is on motor pins 1 & 3 and the other on motor pins 2 & 4.
// Refer to the manufacturer's documentation of  Changzhou Fulling
// Motor Co., Ltd., among others.  The step angle is 5.625/64 and the
// operating Frequency is 100pps. Current draw is 92mA. 

const int motorPin1 = 4; // Blue   - 28BYJ48 pin 1
const int motorPin2 = 5; // Pink   - 28BYJ48 pin 2
const int motorPin3 = 6; // Yellow - 28BYJ48 pin 3
const int motorPin4 = 7; // Orange - 28BYJ48 pin 4
                                // Red    - 28BYJ48 pin 5 VCC
int motorSpeed=3000;            // set stepper speed
float err=0;
void setup() {
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  //Serial.begin(115200);
}
void loop(){
//long m=millis();
//Serial.println(millis()-m);

if(random(4))
degrpm(random(2),80*(random(8)+1),3200);
else delay(500);

//degrpmslowCool(1,long(360)*100*5,5*60);
//degrpm(1,4500,3000);delay(1000);
}
void rev(boolean bcw, long revo) { 
long step2=revo*64*8-12; //not exactly right?
int rpm100=500;
if(bcw) cwss(12,rpm100); //ramp up speed
else   ccwss(12,rpm100);
for(long i=0;i<step2;i++)
  if(bcw)cw(); else ccw();
off();
}
void degrpmslowCool(boolean bcw, long deg100, int rph100) { 
//ccw only, more torque, less current, less heat
motorSpeed=1200;
int step2=deg100*64*8/360/100; //rounded down
int d=long(351500)/2/rph100; //div 2? see stepper.xls
for(int i=0;i<step2;i++) {
ccw4st1(); off(); delay(d); //cools while off
ccw4st2(); off(); delay(d);
} //for
off();
}
void degrpmslowHot(boolean bcw, long deg100, int rph100) { 
//ccw only, more torque
motorSpeed=1200;
int step2=deg100*64*8/360/100; //rounded down
int d=long(351500)/2/rph100; //div 2? see stepper.xls
for(int i=0;i<step2;i++) {
ccw4st1(); delay(d);
ccw4st2(); delay(d);
} //for
off();
}
void degrpmslow2(boolean bcw, long deg100, int rph100) { 
//ccw only, more torque, less current, less heat
motorSpeed=1200;
int step2=deg100*64*8/360/100; //rounded down
int d=long(351500)/2/rph100; //div 2? see stepper.xls
for(int i=0;i<step2;i++) {
ccw4st1(); off(); delay(d/4); st1(); delay(d/2); off(); delay(d/4);
ccw4st2(); off(); delay(d/4); st2(); delay(d/2); off(); delay(d/4);
} //for
off();
}
void degrpm(boolean bcw, long deg100, int rpm100) { 
//max 64 turns or 23,000 deg or 2,300,000 deg100 long is bigger
//max 3500 rpm100 with 12v
int step2=deg100*64*8/360/100; //rounded down
if(rpm100<50)rpm100=50; //minimum should use degrpmslow()
rpm100=long(1463600)/rpm100-20;  //see stepper.xls
if(bcw) cwss(step2,rpm100);
else   ccwss(step2,rpm100);

float movedeg=float(step2)*360/64/8;  //float library adds 2K size to sketch
//Serial.println(movedeg);
//Serial.println(movedeg-(float)deg100/100);  //moved too little only?
//ccw4st1 can help this
err+=(movedeg-(float)deg100/100);
if(err<-1) {
motorSpeed=1200;
if(bcw) cw(); else ccw();
err+=(float(360)/64/8);
//Serial.print("err=");Serial.println(err);
} //if err
off();
}
void ccwss(int steps, int speed) {
//900 self starting 5v motor 5v ps
//800 most of 100% torque
//700 less torque
//600 almost none
//5v motor 12v supply:
//700 self starting
//400 decent torque
//6.6v 20RPM
//5V 10RPM strong
//if(speed<700) steps-=10;
//ramp up speed
motorSpeed=3000; if(speed<1200) {ccw(); ccw(); steps-=2;}
motorSpeed=1200; if(speed<1200) {ccw(); ccw(); steps-=2;}
motorSpeed=800;  if(speed<800 ) {ccw(); ccw(); steps-=2;}
motorSpeed=700;  if(speed<700 ) for(int i=0;i<4;i++) {ccw(); steps--;}
motorSpeed=speed; for(int i=0;i<steps;i++) ccw();  //64*8 is 1 rev
}
void cwss(int steps, int speed) {
motorSpeed=3000; if(speed<1200) {cw(); cw(); steps-=2;}
motorSpeed=1200; if(speed<1200) {cw(); cw(); steps-=2;}
motorSpeed=800;  if(speed<800 ) {cw(); cw(); steps-=2;}
motorSpeed=700;  if(speed<700 ) for(int i=0;i<4;i++) {cw(); steps--;}
motorSpeed=speed; for(int i=0;i<steps;i++) cw();  //64*8 is 1 rev
}
void ccw4st1(){
  // 1
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
  delayMicroseconds(motorSpeed);
  // 2
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
  delayMicroseconds(motorSpeed);
  // 3
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
  delayMicroseconds(motorSpeed);
  // 4
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, LOW);
  delayMicroseconds(motorSpeed);
}
void st1(){
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, LOW);
}
void ccw4st2(){
  // 5
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, LOW);
  delayMicroseconds(motorSpeed);
  // 6
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, HIGH);
  delayMicroseconds(motorSpeed);
  // 7
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, HIGH);
  delayMicroseconds(motorSpeed);
  // 8
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, HIGH);
  delayMicroseconds(motorSpeed);
}
void st2(){
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, HIGH);
}
void off(){
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
}
//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 1 to 4
void ccw (){
  // 1
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
  delayMicroseconds(motorSpeed);
  // 2
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
  delayMicroseconds(motorSpeed);
  // 3
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
  delayMicroseconds(motorSpeed);
  // 4
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, LOW);
  delayMicroseconds(motorSpeed);
  // 5
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, LOW);
  delayMicroseconds(motorSpeed);
  // 6
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, HIGH);
  delayMicroseconds(motorSpeed);
  // 7
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, HIGH);
  delayMicroseconds(motorSpeed);
  // 8
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, HIGH);
  delayMicroseconds(motorSpeed);
}
//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 4 to 1
void cw(){
  // 1
  digitalWrite(motorPin4, HIGH);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin1, LOW);
  delayMicroseconds(motorSpeed);
  // 2
  digitalWrite(motorPin4, HIGH);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin1, LOW);
  delayMicroseconds(motorSpeed);
  // 3
  digitalWrite(motorPin4, LOW);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin1, LOW);
  delayMicroseconds(motorSpeed);
  // 4
  digitalWrite(motorPin4, LOW);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin1, LOW);
  delayMicroseconds(motorSpeed);
  // 5
  digitalWrite(motorPin4, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin1, LOW);
  delayMicroseconds(motorSpeed);
  // 6
  digitalWrite(motorPin4, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin1, HIGH);
  delayMicroseconds(motorSpeed);
  // 7
  digitalWrite(motorPin4, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin1, HIGH);
  delayMicroseconds(motorSpeed);
  // 8
  digitalWrite(motorPin4, HIGH);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin1, HIGH);
  delayMicroseconds(motorSpeed);
}

Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jan 13, 2012, 07:51 pm
New version.
You can easily microstep with move(1) and degrpm8()

Code: [Select]

#define dw digitalWrite
#define dm delayMicroseconds

const int mp1 = 4; // Blue   - 28BYJ48 pin 1
const int mp2 = 5; // Pink   - 28BYJ48 pin 2
const int mp3 = 6; // Yellow - 28BYJ48 pin 3
const int mp4 = 7; // Orange - 28BYJ48 pin 4
                               // Red    - 28BYJ48 pin 5 VCC
int motorSpeed=3000;            // set stepper speed
int stepnum=0;
float err=0;

void setup() {
 pinMode(mp1, OUTPUT);
 pinMode(mp2, OUTPUT);
 pinMode(mp3, OUTPUT);
 pinMode(mp4, OUTPUT);
 //Serial.begin(115200);
}
void loop(){
//long m=millis();
//Serial.println(millis()-m);
//if(random(4)) degrpm8(random(2),9*(random(20)+2),3200); else delay(100);
//degrpmslowCool4(1,long(360)*100*5,10*60);
//for(int i=0;i<90;i++) {degrpm(1,400,800);delay(50);}
//for(int i=0;i<8;i++) degrpm8(0,4500,2400);
//revRestart(1,2,2000,4);
//does not work 5v for(int i=0;i<500;i++){move(1); off(); delay(1);}
//for(int i=0;i<500;i++){move(1); off(); delay(1);} //<5ms ok w 12v Cool4 better
degrpm(1,180*100,2000);
//ramp(1,2000);
off();delay(500);
}
void ramp(boolean bcw, int rpm100) {
//past 1200 it ramps in cwss() also that's bad
for(int i=50;i<1200;i+=100) //1200 or rpm100 for <1200
degrpmEZ(bcw,900,i); //<900deg ignores speed
revRestart(bcw,2,rpm100,1);
}  
void revRestart(boolean bcw, long revo, int rpm100, int xinrev) {
//xinrev small only
//in case it gets stuck due to torque load spike
for(long i=0;i<revo*xinrev;i++)
degrpm(bcw,36000/xinrev,rpm100);
}
void rev(boolean bcw, long revo) {  
long step2=revo*64*8-12; //not exactly right?
int rpm100=500;
if(bcw) cwss(12,rpm100); //ramp up speed
else   ccwss(12,rpm100);
for(long i=0;i<step2;i++)
 if(bcw)cw(); else ccw();
off();
}
void degrpmslowCool4(boolean bcw, long deg100, int rph100) {  
//ccw only, more torque, less current, less heat, most efficient code for maH
//but 4x as jerky
motorSpeed=1000;
int step2=deg100*64*8/360/100/2; //rounded down
int d=long(351500)*2/rph100; //div 2? see stepper.xls was /2 now *2
for(int i=0;i<step2;i++) {
ccw(); ccw(); off(); delay(d);
} //for
off();
}
void degrpmslowCool(boolean bcw, long deg100, int rph100) {  
//ccw only, more torque, less current, less heat
motorSpeed=1500; //why 1500 needed?
int step2=deg100*64*8/360/100; //rounded down
int d=long(351500)/2/rph100; //div 2? see stepper.xls
for(int i=0;i<step2;i++) {
ccw4st1(); off(); delay(d); //cools while off
ccw4st2(); off(); delay(d);
} //for
off();
}
void degrpmslowHot(boolean bcw, long deg100, int rph100) {  
//ccw only, more torque, hot w 12v
motorSpeed=1000;
int step2=deg100*64*8/360/100; //rounded down
int d=long(351500)/2/rph100; //div 2? see stepper.xls
for(int i=0;i<step2;i++) {
ccw4st1(); delay(d);
ccw4st2(); delay(d);
} //for
off();
}
void degrpmslow2(boolean bcw, long deg100, int rph100) {  
//ccw only, more torque, less current, less heat, 50% duty cycle
//compromise Hot,Cool
motorSpeed=1000; //12v
int step2=deg100*64*8/360/100; //rounded down
int d=long(351500)/2/rph100; //div 2? see stepper.xls
for(int i=0;i<step2;i++) {
ccw4st1(); off(); delay(d/4); st1(); delay(d/2); off(); delay(d/4);
ccw4st2(); off(); delay(d/4); st2(); delay(d/2); off(); delay(d/4);
} //for
off();
}
void degrpmEZ(boolean bcw, long deg100, int rpm100) {  
//max 64 turns or 23,000 deg or 2,300,000 deg100 long is bigger
//max 3500 rpm100 with 12v
int step2=deg100*64*8/360/100; //rounded down
if(rpm100<50)rpm100=50; //minimum should use degrpmslow()
rpm100=long(1463600)/rpm100-20;  //see stepper.xls
if(bcw) cwss(step2,rpm100);
else   ccwss(step2,rpm100);
}
void degrpm(boolean bcw, long deg100, int rpm100) {  
//max 64 turns or 23,000 deg or 2,300,000 deg100 long is bigger
//max 3500 rpm100 with 12v
int step2=deg100*64*8/360/100; //rounded down
if(rpm100<50)rpm100=50; //minimum should use degrpmslow()
rpm100=long(1463600)/rpm100-20;  //see stepper.xls
if(bcw) cwss(step2,rpm100);
else   ccwss(step2,rpm100);

//with this code you can step by 2.00 deg 180x will be 360+-1
//0.50 deg 720x works to 360
//even though step size is >0.50 or 0.72?
float movedeg=float(step2)*360/64/8;  //float library adds 2K size to sketch
//Serial.println(movedeg);
//Serial.println(movedeg-(float)deg100/100);  //moved too little only?
//ccw4st1 can help this
err+=(movedeg-(float)deg100/100);
if(err<-1) {
motorSpeed=1200;
if(bcw) cw(); else ccw();
err+=(float(360)/64/8);
//Serial.print("err=");Serial.println(err);
} //if err
//soft stop moves further than it should
//if(bcw) cwss(15,2000);
//else   ccwss(15,2000);
delay(10); //so it stops and holds before off in loop
//off();
}
void degrpm8(boolean bcw, long deg100, int rpm100) {  
//max 8 turns
//max <<3500 rpm100 with 12v cuz no ramping ~17RPM
const int min2start=1200; //700 12v, 1200 5v
int step2=deg100*64*64/360/100; //rounded down
if(rpm100<50)rpm100=50; //minimum should use degrpmslow()
rpm100=long(1463600)/rpm100-20;  //see stepper.xls same SAME
motorSpeed=rpm100;
if(motorSpeed<min2start)motorSpeed=min2start;
for(int i=0;i<step2;i++) {
 if(bcw)stepnum++; else stepnum--;
 st07();
 }
//was if(bcw)cwss(step2,rpm100); else ccwss(step2,rpm100);
//does not adjust for err like degrpm cuz step 0.088 or 1/11 deg
float movedeg=float(step2)*360/64/64;  //float library adds 2K size to sketch
//Serial.println(movedeg);
err+=(movedeg-(float)deg100/100);
//Serial.println(err);
//if(err<-1) {motorSpeed=1200; if(bcw) cw(); else ccw(); err+=(float(360)/64/8);}
//off();
}
void move(boolean bcw){
motorSpeed=1200;
if(bcw)stepnum++; else stepnum--;
st07();
}
void ccwss(int steps, int speed) {
//900 self starting 5v motor 5v ps
//800 most of 100% torque
//700 less torque
//600 almost none
//5v motor 12v supply:
//700 self starting
//400 decent torque
//6.6v 20RPM
//8.3v load 8.5v float 6x NiMh
//20RPM strong 28RPM weak
//15RPM 100% torque
//does not overheat
//5V 10RPM strong
//5V 20RPM weak
//5V 24RPM no torque
//12V 20RPM self start 35 max speed
//if(speed<700) steps-=10;
//ramp up speed
motorSpeed=1000; //<12 steps, 800 for 12v
if(steps>=12) {
motorSpeed=3000; if(speed<1200) {ccw(); ccw(); steps-=2;}
motorSpeed=1200; if(speed<1200) {ccw(); ccw(); steps-=2;}
motorSpeed=800;  if(speed<800 ) {ccw(); ccw(); steps-=2;}
motorSpeed=700;  if(speed<700 ) for(int i=0;i<4;i++) {ccw(); steps--;}
motorSpeed=speed;
} //if
for(int i=0;i<steps;i++) ccw();  //64*8 is 1 rev
}
void cwss(int steps, int speed) {
motorSpeed=1000; //<12 steps, 800 for 12v
if(steps>=12) {
motorSpeed=3000; if(speed<1200) {cw(); cw(); steps-=2;}
motorSpeed=1200; if(speed<1200) {cw(); cw(); steps-=2;}
motorSpeed=800;  if(speed<800 ) {cw(); cw(); steps-=2;}
motorSpeed=700;  if(speed<700 ) for(int i=0;i<4;i++) {cw(); steps--;}
motorSpeed=speed;
} //if
for(int i=0;i<steps;i++) cw();  //64*8 is 1 rev
}
void ccw4st1(){
 // 1
 dw(mp1, HIGH);
 dw(mp2, LOW);
 dw(mp3, LOW);
 dw(mp4, LOW);
 dm(motorSpeed);
 // 2
 dw(mp1, HIGH);
 dw(mp2, HIGH);
 dw(mp3, LOW);
 dw(mp4, LOW);
 dm(motorSpeed);
 // 3
 dw(mp1, LOW);
 dw(mp2, HIGH);
 dw(mp3, LOW);
 dw(mp4, LOW);
 dm(motorSpeed);
 // 4
 dw(mp1, LOW);
 dw(mp2, HIGH);
 dw(mp3, HIGH);
 dw(mp4, LOW);
 dm(motorSpeed);
}
void st1(){
 dw(mp1, LOW);
 dw(mp2, HIGH);
 dw(mp3, HIGH);
 dw(mp4, LOW);
}
void ccw4st2(){
 // 5
 dw(mp1, LOW);
 dw(mp2, LOW);
 dw(mp3, HIGH);
 dw(mp4, LOW);
 dm(motorSpeed);
 // 6
 dw(mp1, LOW);
 dw(mp2, LOW);
 dw(mp3, HIGH);
 dw(mp4, HIGH);
 dm(motorSpeed);
 // 7
 dw(mp1, LOW);
 dw(mp2, LOW);
 dw(mp3, LOW);
 dw(mp4, HIGH);
 dm(motorSpeed);
 // 8
 dw(mp1, HIGH);
 dw(mp2, LOW);
 dw(mp3, LOW);
 dw(mp4, HIGH);
 dm(motorSpeed);
}
void st2(){
 dw(mp1, HIGH);
 dw(mp2, LOW);
 dw(mp3, LOW);
 dw(mp4, HIGH);
}
void off(){
 dw(mp1, LOW);
 dw(mp2, LOW);
 dw(mp3, LOW);
 dw(mp4, LOW);
}
void st07(){
if(stepnum==-1)stepnum=7;
if(stepnum==8)stepnum=0;
switch(stepnum){
case 0:
 dw(mp4, HIGH);
 dw(mp3, LOW);
 dw(mp2, LOW);
 dw(mp1, LOW);
 dm(motorSpeed);
 break;
case 1:
 dw(mp4, HIGH);
 dw(mp3, HIGH);
 dw(mp2, LOW);
 dw(mp1, LOW);
 dm(motorSpeed);
 break;
case 2:
 dw(mp4, LOW);
 dw(mp3, HIGH);
 dw(mp2, LOW);
 dw(mp1, LOW);
 dm(motorSpeed);
 break;
case 3:
 dw(mp4, LOW);
 dw(mp3, HIGH);
 dw(mp2, HIGH);
 dw(mp1, LOW);
 dm(motorSpeed);
 break;
case 4:
 dw(mp4, LOW);
 dw(mp3, LOW);
 dw(mp2, HIGH);
 dw(mp1, LOW);
 dm(motorSpeed);
 break;
case 5:
 dw(mp4, LOW);
 dw(mp3, LOW);
 dw(mp2, HIGH);
 dw(mp1, HIGH);
 dm(motorSpeed);
 break;
case 6:
 dw(mp4, LOW);
 dw(mp3, LOW);
 dw(mp2, LOW);
 dw(mp1, HIGH);
 dm(motorSpeed);
 break;
case 7:
 dw(mp4, HIGH);
 dw(mp3, LOW);
 dw(mp2, LOW);
 dw(mp1, HIGH);
 dm(motorSpeed);
 break;
}
}
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: celem on Jan 13, 2012, 08:16 pm
I haven't tried either of your sketches yet but you have been busy. Given your comments about heat and 12-volt operation apparently you are putting a lot of stress testing with your stepper(s).
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jan 13, 2012, 08:43 pm
What is the expected life of a stepper?  I have discovered that 8v 6xNiMh or 12v is fine so long as you turn off the power when it's not moving.  Or between steps when it's moving slowly.  The 64:1 gear ratio keeps most external torque from changing the current phase in the sequence when the power is off.  My functions prove this concept.  Notice my parameters in the function calls look like this:  4500 is 45 degrees.  4525 is 45.25 degrees.  3050 is 30.50 RPM.  The slow functions take RPHour.  Just multiply RPM*60 if you prefer to use that instead.  You can even step by 2.00 degress for example without microstepping.  1/2 stepping?  1/8 stepping?  The 8-step size is not a whole interval of 2.00, but you can step 180 times and it will be 360 degrees of rotation anyway.  degrpm() supports ramping.  Or just use degrpm8() if 1/11th of a degree is good enough for you.  The only thing to add is speed ramping to achieve the highest RPM in degrpm8.  I figure it's not important because we're only moving a short distance anyway. 

Does anyone have code to translate an arbitrary angle to X and Y motors?  In other words 45 degrees would mean moving each motor 1 microstep at a time alternating evenly between them.  0 degrees is all X.  90 degrees all Y.  I don't want to move one motor 30 steps and the other 40 that would look jaggy.  Arctan gives you the ratio, but I need more than that.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jan 14, 2012, 05:59 pm
I have added the ability to measure a torque load and stop when it reaches the end of pulling a string for example.
Also Serial.printing turns or degrees as it is running.
Increased resolution to +-1/22 degrees in degrpm8().
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: celem on Jan 14, 2012, 11:10 pm
sbright33 - your sketch posted on January 13, 2012, 06:51:43 PM is missing declarations for cw() and ccw().

Also, has your testing with microsecond delays determined an optimal delay in microseconds after doing the stepper write?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: celem on Jan 14, 2012, 11:17 pm
I rewrote my original stepper test to utilize direct port manipulation. I hesitated in doing this until I was positive that writes to PORTB were not going to mess up the crystal on PB6 & PB7 - it does not. DO NOT TRY THIS SKETCH unless your setup is identical to the sketch. The PORTB writes only write to Digital pins 8-to-13. If you use different pins then you MUST rewrite the sketch. Read the other warning in the sketch. This sketch only been tested on an Arduino NANO.

Code: [Select]

// WARNING: USE AT YOUR OWN RISK!!!
// Do not use this script if your Arduino doesn't use a Atmega328 or Atmega168
// It is only been tested on an Arduino NANO
// This Arduino example demonstrates bidirectional operation of a
// 28BYJ-48, which is readily available on eBay, using a ULN2003
// interface board to drive the stepper.
//////////////////////////////
// The Atmega328p chips used on the Arduino board have three ports.
// We are interested in port B:
// We are using Arduino Digital bits 8-11, which map to Atmega328p PB0-PB3
// B (digital pin 8 to 13)
// NOTE: as tested by anescient, there's no harm in writing to PORTB as long as DDRB[6:7] are 0
// Read: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1261361330
////////////////////////////////////////////////
// The speed and direction of the stepper motor is determined
// by adjusting a 1k-ohm potentiometer connected to Arduino pin A2.
// When the potentiometer is rotated fully counterclockwise, the motor
// will rotate at full counterclockwise speed. As the potentiometer is
// rotated clockwise, the motor will continue to slow down until is
// reaches its minimum speed at the the potentiometer's midpoint value .
// Once the potentiometer crosses its midpoint, the motor will reverse
// direction. As the potentiometer is rotated further clockwise, the speed  
// of the motor will increase until it reaches its full clockwise rotation
// speed when the potentiometer has been rotated fully clockwise.
////////////////////////////////////////////////

//declare variables for the motor pins
int motorPin1 = 8; // Blue   - 28BYJ48 pin 1
int motorPin2 = 9; // Pink   - 28BYJ48 pin 2
int motorPin3 = 10; // Yellow - 28BYJ48 pin 3
int motorPin4 = 11; // Orange - 28BYJ48 pin 4
                       // Red    - 28BYJ48 pin 5 (VCC)

int motorSpeed = 0;     //variable to set stepper speed
int potPin = 2; //potentiometer connected to A2
int potValue = 0; //variable to read A0 input


//////////////////////////////////////////////////////////////////////////////
void setup() {
 //declare the motor pins as outputs
 pinMode(motorPin1, OUTPUT);
 pinMode(motorPin2, OUTPUT);
 pinMode(motorPin3, OUTPUT);
 pinMode(motorPin4, OUTPUT);
 Serial.begin(9600);
}

//////////////////////////////////////////////////////////////////////////////
void loop(){

 potValue = analogRead(potPin);     // read the value of the potentiometer
 Serial.println(potValue);          // View full range from 0 - 1024 in Serial Monitor
 if (potValue < 535){               // if potentiometer reads 0 to 535 do this
   motorSpeed = (potValue/15 + 5);  //scale potValue to be useful for motor
   clockwise();                     //go to the ccw rotation function
 }
 else {                             //value of the potentiometer is 512 - 1024
   motorSpeed = ((1024-potValue)/15 + 5); //scale potValue for motor speed
   counterclockwise(); //go the the cw rotation function
 }
}

//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 1 to 4
//delay "motorSpeed" between each pin setting (to determine speed)

void counterclockwise (){
 // 1
 PORTB = 0b0001;
 delay(motorSpeed);
 // 2
 PORTB = 0b0011;
 delay(motorSpeed);
 // 3
 PORTB = 0b0010;
 delay(motorSpeed);
 // 4
 PORTB = 0b0110;
 delay(motorSpeed);
 // 5
 PORTB = 0b0100;
 delay(motorSpeed);
 // 6
 PORTB = 0b1100;
 delay(motorSpeed);
 // 7
 PORTB = 0b1000;
 delay(motorSpeed);
 // 8
 PORTB = 0b1001;
 delay(motorSpeed);
}

//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 4 to 1
//delay "motorSpeed" between each pin setting (to determine speed)

void clockwise(){
  // 1
  PORTB = 0b1000;
 delay(motorSpeed);
 // 2
 PORTB = 0b1100;
 delay(motorSpeed);
 // 3
 PORTB = 0b0100;
 delay(motorSpeed);
 // 4
 PORTB = 0b0110;
 delay(motorSpeed);
 // 5
 PORTB = 0b0010;
 delay(motorSpeed);
 // 6
 PORTB = 0b0011;
 delay(motorSpeed);
 // 7
 PORTB = 0b0001;
 delay(motorSpeed);
 // 8
 PORTB = 0b1001;
 delay(motorSpeed);
}


Now if I can determine the optimal "motorspeed" value then I can optimize the stepper's functionality.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jan 15, 2012, 12:48 am
I couldn't fit cw and ccw() in the 10k code box limits of the forum.  It is included in the previous version, as well as the original version.  400us works if you ramp up the speed first.  Or just call degrpm(35rpm) it does that for you.  All the relevant speeds are listed in the comments.  I don't see the advantage of PORTB?  DigitalWrite is only microseconds apart which is not significant compared to 400 or 1200us.  Can you go faster than me?  My sketch is compatible with most Arduinos having the relevant ports which you specify at the top.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: celem on Jan 15, 2012, 02:17 am
PORTB's advantage is probably moot, since we are throwing in delays anyway. The only advantage is to eliminate those microseconds of delay when setting two ports simultaneously. However, the difference is not trivial - is about 95 times faster, according to John Boxall's blog: http://tronixstuff.wordpress.com/tag/portb/ (http://tronixstuff.wordpress.com/tag/portb/)

However, using PORTx commands introduce a lot of risk, reduces portability and readability and should be avoided unless truly needed.

I just wanted to see if I could get it working and I will NOT be using PORTx for a stepper application.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: ajofscott on Jan 15, 2012, 04:57 am
My point being that sequential turn off of motor windings is the same as a movement command, ergo there is a probability of either a backstep or a forward step as you release control.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jan 15, 2012, 05:40 pm
As you move from 1 step to the next you are only changing 1 winding at a time.  So if it begins to move before the 4th winding is not changed, all the better!  Then there is a delay of 1000x.  When you come to an immediate stop, there is no changes to worry about.  When you turn off the power in my code, the order could be important.  I have not handled this case yet.  You can choose which order to do this in.  If 1-4 then it could in theory move backward.  If 4-1 then maybe forward.  It could not move forward if there is some torque against it.  With the gear ratio of 64:1 nor will it move backwards.  Even if it did move a step 1/11th degree, you're coming to a stop anyway.  When you start up again it will be as if it didn't slip backwards.  It should not effect torque or top speed.  Agree?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: celem on Jan 15, 2012, 08:04 pm
For those of you interested in greater technical detail on controlling a stepper motor, take a look at Atmel Corp's Application Note  titled "AVR446: Linear speed control of stepper motor". Lots of math there for you number crunchers.   it is an PDF located at:
http://www.atmel.com/dyn/resources/prod_documents/doc8017.pdf (http://www.atmel.com/dyn/resources/prod_documents/doc8017.pdf)
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: celem on Jan 17, 2012, 11:14 pm
I was able to get the Arduino stepper library to perform better for the 28BYJ-48, but, of course, the  Arduino stepper library is limited and does not support acceleration/deceleration.  Here is working Arduino stepper library code for the 28BYJ-48:

Code: [Select]

/*
 Derived from YourDuino.com Example Software Sketch
  Small Stepper Motor and Driver, by:
  terry@yourduino.com
*/

#include <Stepper.h>
//declare variables for the motor pins
int motorPin1 = 8; // Blue   - 28BYJ48 pin 1
int motorPin2 = 9; // Pink   - 28BYJ48 pin 2
int motorPin3 = 10; // Yellow - 28BYJ48 pin 3
int motorPin4 = 11; // Orange - 28BYJ48 pin 4
                       // Red    - 28BYJ48 pin 5 (VCC)

#define STEPS  64   //Number of steps per revolution

//The pin connections need to be 4 pins connected
// to Motor Driver In1, In2, In3, In4  and then the pins entered
// here in the sequence 1-3-2-4 for proper sequencing of 28BYJ48
Stepper small_stepper(STEPS, motorPin1, motorPin3, motorPin2, motorPin4);

int  Steps2Take;

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
 small_stepper.setSpeed(200);
}/*--(end setup )---*/

void loop()
{
 // sweep 1 turn each way
 small_stepper.setSpeed(200);  
 Steps2Take  =  2048;  // Rotate CW
 small_stepper.step(Steps2Take);
 delay(2000);
 
 small_stepper.setSpeed(200);  // 200 a good max speed??
 Steps2Take  =  -2048;  // Rotate CCW
 small_stepper.step(Steps2Take);
 delay(2000);

}


Most recently, I have been experimenting with the powerful accelstepper library (http://www.open.com.au/mikem/arduino/AccelStepper (http://www.open.com.au/mikem/arduino/AccelStepper)). It supports acceleration/deceleration and much more. I posted a short demo video of a 28BYJ-48 being driven by the accelstepper library in full-step mode. It actually is more impressive in half-step mode but I didn't make a video of that. The video is at: http://youtu.be/1F3240hCHE4 (http://youtu.be/1F3240hCHE4)

The sketch used in the video is shown below:
Code: [Select]

// accellsteppertest.ino
// Runs one stepper forwards and backwards, accelerating and decelerating
// at the limits. Derived from example code by Mike McCauley
// Set for 28BYJ-48 stepper

#include <AccelStepper.h>

#define FULLSTEP 4
#define HALFSTEP 8

//declare variables for the motor pins
int motorPin1 = 8; // Blue   - 28BYJ48 pin 1
int motorPin2 = 9; // Pink   - 28BYJ48 pin 2
int motorPin3 = 10; // Yellow - 28BYJ48 pin 3
int motorPin4 = 11; // Orange - 28BYJ48 pin 4
                       // Red    - 28BYJ48 pin 5 (VCC)

// The sequence 1-3-2-4 required for proper sequencing of 28BYJ48
AccelStepper stepper2(FULLSTEP, motorPin1, motorPin3, motorPin2, motorPin4);

void setup()
{    
 stepper2.setMaxSpeed(1000.0);
 stepper2.setAcceleration(50.0);
 stepper2.setSpeed(200);
 stepper2.moveTo(2048);
}

void loop()
{
 //Change direction at the limits
 if (stepper2.distanceToGo() == 0) {
   stepper2.moveTo(-stepper2.currentPosition());
 }
 stepper2.run();
}


The accelstepper library has many useful features. Check it out!
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jan 23, 2012, 12:38 am
I find that library to be difficult to understand for a beginner.  Maybe I'm biased because I wrote mine.  I've added some of the useful features mine was missing.  I can detect the torque load or change!
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: masm on Feb 06, 2012, 09:00 am
Hello,

I just bought the 28BYJ48 stepper motor and will try these codes.
Just so that I will not burn my Arduino Nano, how is the wiring done?
I have also ULN2003 driver.

Thanks
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: celem on Feb 06, 2012, 12:39 pm
The wiring is listed in the sketch. I also used a nano as well as a mini-pro. The power pins on ULN2003 driver board, if yours is the same as mine, are poorly marked. Ground goes to the pin marked with a very litttle "-" and 5-volts Vcc is connected to the pin marked "+". For the ULN2003 driver board's LEDs to light the jumper must be in place - it is unmarked and is adjacent to the power pins.

From the sketch
...
int motorPin1 = 8;   // Blue   - 28BYJ48 pin 1
int motorPin2 = 9;   // Pink   - 28BYJ48 pin 2
int motorPin3 = 10;   // Yellow - 28BYJ48 pin 3
int motorPin4 = 11;   // Orange - 28BYJ48 pin 4
                        // Red    - 28BYJ48 pin 5 (VCC)

#define STEPS  64   //Number of steps per revolution

//The pin connections need to be 4 pins connected
// to Motor Driver In1, In2, In3, In4 ...
...
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: masm on Feb 07, 2012, 02:24 am
Thank you selem,

did you take the +5V from Nano or separate powersupply?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: celem on Feb 07, 2012, 05:02 am
The nano's supply is inadequate for the stepper. I used a separate 5v supply and just tied the grounds.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: joogaa on Feb 27, 2012, 01:56 am
@sbright33:
Hi! Do you have a new version of your code? Can you explain better your idea about the angle for motors x, y?

J
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Feb 27, 2012, 06:29 pm
My newer library is on another thread here.  Many improvements.  More coming.  PWM to make it smoother.  Non-blocking to free up the processor for other tasks.  Higher voltage to increase performance without getting hot...

I'd like to move 2 motors called x,y at the same time.  Pointing a laser for example.  While the laser is on when you go from 0,0 to 10,10 it should move at a 45 degree angle.  That's simple just move 1x,1y,1x,1y... until you get to 10.  Or move them simultaneously.  Not so simple when you're going to 75,80 or an arbitrary x,y.  There must be an easy algorithm?  I don't know it.  Anyone?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: keeper63 on Feb 27, 2012, 07:39 pm

There must be an easy algorithm?  I don't know it.  Anyone?


http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm

Fairly simple for 2D stuff (there are tons of implementations out there - it is used for line drawing in 2D graphics); not sure what it would take to add a 3rd stepper (or more). You might also look into the few g-code interpreter implementations for the Arduino that are out there...
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: keeper63 on Feb 27, 2012, 07:41 pm
Found this; the links still work:

http://www.gamedev.net/topic/536735-bresenham-2d-3d-4d-6d/
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: keeper63 on Feb 27, 2012, 07:42 pm
BTW - that 6D one looks like it could be easily generalized to N-degrees...
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Feb 27, 2012, 10:44 pm
Your first link looks really simple!  I like simple.
Only 10 lines of code in the loop.  Thanks!
2D is enough.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: joogaa on Mar 28, 2012, 05:30 pm
did that algorithm work for pointing at x,y?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Mar 28, 2012, 08:19 pm
Yes, in my simple experiments.  Only 10 lines of code it is easy to follow.  I've been sidetracked by a few other projects hope to get back to this.  The whole point of Bresenham is to make a straight line while moving to arbitrary x,y.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: lardconcepts on Nov 26, 2012, 09:15 pm

My newer library is on another thread here.  Many improvements.  More coming.  PWM to make it smoother.  Non-blocking to free up the processor for other tasks.  Higher voltage to increase performance without getting hot...


Hi sbright33, many thanks for your library. But I cannot find this newer version. Would you mind sharing the link?

I'm glad I found this, because with the standard library 28BYJ was getting very hot an not really behaving well!

I had trouble cobbling the code together from the various bits in this thread. Is there any particular reason to be pasting inline rather than just use a standard code-bin like pastebin or gist? If it helps anyone else, I put the latest version I could find on https://gist.github.com/4149982

The advantage of using something like Gist is that you can update the one file whenever you like and the forum link will always be up to date then.

Please don't take this as any criticism of your excellent library - it's just a newbie asking a newbie question!
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Nov 27, 2012, 06:26 pm
Thanks for your compliments and posting my old code on Gist.  I can update that site now?  Will do it with a few different versions.  It has branched off to a few since 2011.  One for a bigger motor without gears.  One for multiple steppers and servos together non-blocking with scripts.  One using PWM.  One to detect higher loads when the motor reaches travel limits.  I could try to put them all together, or keep them separate.  I also have a simple version for beginners which includes running cool and acceleration.  This might be a great introduction for new users to understand first before it gets complicated.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: lardconcepts on Nov 27, 2012, 07:13 pm

Thanks for your compliments and posting my old code on Gist.  I can update that site now?  Will do it with a few different versions.


Would love to see your new versions! You can't edit my pasted code there, but creating a new account takes less than a minute and is free. You can either "fork" my copy of the code into your account, or just start again. If you want me to now remove my copy of the code I'm happy to delete it and replace it with a link to your new code.

Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Nov 27, 2012, 08:53 pm
Viewed 6900 times exactly!
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: lardconcepts on Nov 27, 2012, 09:18 pm

Viewed 6900 times exactly!


Indeed. Which shows how popular your library is and how many people would appreciate the updates being made available!

If you have many versions, the other thing you could do would be to create a repository over at github. Then you have versioning and code commenting and people can suggest changes or improvements or bugfixes, they can follow the project and be notified of changes etc.

In fact, Arduino itself lives right there! https://github.com/arduino/Arduino

It might look scary to start with, but you'll soon see how easy it is. https://help.github.com/articles/create-a-repo

If there's anything I can do to help, please let me know.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Nov 28, 2012, 02:17 am
According to your link, Step 1 and 2 are on my local machine?  But I don't have Linux.  How do I do this with windows?
Should I just start with Gist?  I get it!
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: lardconcepts on Nov 28, 2012, 02:30 pm

According to your link, Step 1 and 2 are on my local machine?  But I don't have Linux.  How do I do this with windows?
Should I just start with Gist?  I get it!


Yes, you could certainly do everything you wanted with Gist. There's some more setup info and Windows apps at https://github.com/ if you DID want to make a full repository of it, but a Gist (a sort of "github-lite"!) will do perfectly for this.

Edit: Looks like you've already got an account there! https://github.com/sbright33 - if there's anything I can do to help get the new versions of the library up, please let me know.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Nov 30, 2012, 09:46 pm
Here it is at last!  With new features.  Will update Gist from now on.
https://gist.github.com/4178431

Please...
Questions?  Comments?  Requests for new features?  Improvements?
Thanks for looking at my code!
Steve

As a learning exercise or tutorial feel free to check out the older version, which is now obsolete.
https://gist.github.com/4149982
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: lardconcepts on Nov 30, 2012, 10:00 pm
Hey, Steve! Great work! Going to bust out some breadboard and have a go later!

Might be an idea to let people know where to get the narcoleptic.h library from: http://code.google.com/p/narcoleptic/

Incidentally, I've just added a note to the top of my old copy to point people to your version of the library.

Thanks again, keep up the good work!
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Nov 30, 2012, 10:16 pm
Here's a demonstration of related code I've been working on.  It allows the same script format to control both a stepper and servo simultaneously and independently.  The script allows you to do motion easing and mechanical animation with Arduino and cheap servos/steppers.  It's a work in progress. 

https://gist.github.com/4178630
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Dec 01, 2012, 12:20 am
Last summer I got a new Stepper motor!  It's big and does 1 degree / step.  It's faster 300RPM because there are no gears like the 28BYJ.  I wrote more code to do PWM to make it smoother at slow speeds.  It has no gears so you can't just turn off the power when you stop.  When stepping slowly you need to keep the coils on, at least at a lower voltage.  If you use 12v it will overheat within minutes.  It's all here, view at your own risk?  The 2nd file is smaller and much easier to understand first.

https://gist.github.com/4179366
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Dec 02, 2012, 05:35 pm
Is there Anybody out there... there... there...

I guess you're the only one lardconcepts!
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: keeper63 on Dec 02, 2012, 09:22 pm

Is there Anybody out there... there... there...

I guess you're the only one lardconcepts!


I'm still following the discussion; if I have anything more to add, I will...

:)
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: lardconcepts on Dec 04, 2012, 11:25 pm

Is there Anybody out there... there... there...

I guess you're the only one lardconcepts!


I would say that judging by the fact that your post is the 6th most viewed in this forum that there are probably LOADS of people out there appreciating your work. I know I certainly do.

Here's a way to know how many people are out there - shorten the link via somethin like goo.gl or bit.ly that gives you click stats, then stick  "s28BYJ-48 5-Volt Stepper library" in your signature and link to either the forum post, or the github gist where the code is, and I think you'll be pleasantly surprised!

Anyway, *I* thoroughly appreciate the fact that you helped bring my stepper to life without smoke or burning smell :)
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Dec 05, 2012, 03:21 am
Thanks it is great to feel appreciated!  But I'm still in doubt about the number of users.  I know my code is not perfect.  I know it is confusing at times.  Doesn't anyone have suggestions for improvements?  Bugs?  I'm really not that good.  It's been a year now.  Maybe there are many users who used my simple functions, and have not advanced to detecting torque or non-blocking code.  Don't be scared to try them!
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Dec 10, 2012, 02:31 am
I'm making a list of enhancements to my code.  I'd like to prioritize them before I start coding.
Any ideas for improvements this week?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: goyer on Dec 20, 2012, 12:34 am
Hey sbright33,

I've been following your tracks and posts for the last 3 hours and think that your work will help me like....a LOT. :)

I'm trying to build an old school split-flap display, like the ones that we used to see in train stations...

I bought five 28BYJ-48 12 Volt from adafruit (those :  http://www.adafruit.com/products/918 (http://www.adafruit.com/products/918)) and ULN2003 cards to control them (http://www.electrodragon.com/?product=stepper-motor-driver-uln2003-board (http://www.electrodragon.com/?product=stepper-motor-driver-uln2003-board)) and trying to control all of these with an arduino mega.

Got lot's of problem wiring everything since specs on both of those equipements sucks (inversed wired, no further explanation to use the 5V/12V jumper on the board...etc) but I think everything is ok now regarding hardware...

I tried the "classic" stepper library but I'm getting serious issues with it :
- my stepper doesn't seem to respond the same way clockwise and counterclockwise with the same "step" entered...
- my steppers are getting hot very fast
- the specs of my motor give me 768 steps but it seems to approximately correspond to 1,5 rotation, can't understand why...etc etc

I also tried the AccelStepper library but as your hardware is closer to mine (except my motors are 12V) I'll jump in your code and see where it leads me...

If someone already got back to you on modifications needed on your code with the 12V model of the 28BY J-48 I'll be happy to have their comments... XD

Anyway, I'll get back to you in few days with questions (many, many questions...) and maybe the biggest THANKS that you ever had for this code !!


Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Dec 21, 2012, 09:15 pm
Welcome! You don't need to modify my code to use it with 12v motors.  If your power supply is 12v then the temperature will be the same as running a 5v motor with 5v PS.  A 12v motor will of course have more torque and speed.  With my "cool" functions you can use your 12v motor with a 18-24v power supply.  Otherwise you will not need the "cool" functions.  They are designed for running a 5v motor at 12v or a 12v motor at 24v.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: lardconcepts on Dec 30, 2012, 06:29 pm

Thanks it is great to feel appreciated!  But I'm still in doubt about the number of users.  I know my code is not perfect.  I know it is confusing at times.  Doesn't anyone have suggestions for improvements?  Bugs?  I'm really not that good.  It's been a year now.  Maybe there are many users who used my simple functions, and have not advanced to detecting torque or non-blocking code.  Don't be scared to try them!


OK, now that the stress of Christmas is almost over, I'm going to get back to this! So, are you saying that you are happy with the functional state of your library, but you'd just like someone to suggest ways of making it more clean and readable for newbies (like me!)

For example, you have:
Code: [Select]
const int mp4a = 13; // 13 is not PWM should use 6 todo later
Is that actually OK to go ahead on rely on?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jan 01, 2013, 07:38 pm
No, it's a horrible idea to use pin 13 for PWM, since it's not supported.  You should use pin 6 instead?
It works with pin 13 as written in my code.  I used it because it's convenient to connect the wires.
I deserve to be shot for keeping that in the code...  But it works!  It was originally a mistake.
Thanks for pointing it out, and reminding me.  That's what comments are for in my code.
It was a test to see if you're paying attention?  Somebody is actually using that function?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: owengrace on Jan 13, 2013, 02:19 am
Hi  Sbright33

I am trying to use your code to experiment with a 28BYJ-48 and uln driver board
and a arduino mega 2560
I compile your sketch and upload it successfully (ts rx lights flash) 

then nothing happens

Probably a dumb Question, what digital pins are you using ( 4. 5. 6. 7. ) ?

Is the anything i have to do with the sketch for it to run

Be patient I am new at this.

cheer Owen 
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: d00m on Feb 23, 2013, 07:44 pm
Hello Sbright33

I also trying to use your code.
I have copied it from https://gist.github.com/sbright33/4178431 and paste to Arduino IDE
compiled and nothing happens..
I have tried uncomment two lines in loop

void loop(){
calloften(); delay(500);
off();while(1); //halt
}

but in not helps..
I have arduino nano + 28BYJ-48 + uln2003 driver board - all connected in proper way to 4,5,6,7 pin on arduino..

all other examples for stepper motor are working ok..
please advise.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: lowres on Mar 02, 2013, 11:00 pm
Hello,
I am trying to run 2-28BYJ-48 steppers using the Accelstepper library by Mike McCauley on an Uno R3.  If I run the base multistepper example, stepper one does not reverse and stepper two will turn and stop.  I found Celem's modification "accellstepper 28BYJ-48" for a single stepper, which I tried to adapt and I can get stepper 2 to reverse, but stepper 1 continues in the same clockwise direction.  Any advice would be helpful.
Thanks
Code: [Select]
// MultiStepper.pde
// -*- mode: C++ -*-
//
// Shows how to multiple simultaneous steppers
// Runs one stepper forwards and backwards, accelerating and decelerating
// at the limits. Runs other steppers at the same time
//
// Copyright (C) 2009 Mike McCauley
// $Id: MultiStepper.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>

// Define some steppers and the pins the will use
AccelStepper stepper1; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
AccelStepper stepper2(AccelStepper::FULL4WIRE, 6, 7, 8, 9);


void setup()

    stepper1.setMaxSpeed(1000.0);
  stepper1.setAcceleration(50.0);
  stepper1.setSpeed(200);
  stepper1.moveTo(2048); 
   
    stepper2.setMaxSpeed(1000.0);
  stepper2.setAcceleration(50.0);
  stepper2.setSpeed(200);
  stepper2.moveTo(2048);
}

void loop()
{
    // Change direction at the limits
    if (stepper1.distanceToGo() == 0)
stepper1.moveTo(-stepper1.currentPosition());
    if (stepper2.distanceToGo() == 0)
stepper2.moveTo(-stepper2.currentPosition());
    stepper1.run();
    stepper2.run();
   
}
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: lowres on Mar 02, 2013, 11:28 pm
actually, this is the code that will reverse stepper 2, but stepper one continues without reversing
Code: [Select]
// accellsteppertest.ino
// Runs one stepper forwards and backwards, accelerating and decelerating
// at the limits. Derived from example code by Mike McCauley
// Set for 28BYJ-48 stepper

#include <AccelStepper.h>

#define FULLSTEP 4
#define HALFSTEP 8

//declare variables for the motor pins
int motorPin1 = 6; // Blue   - 28BYJ48 pin 1
int motorPin2 = 7; // Pink   - 28BYJ48 pin 2
int motorPin3 = 8; // Yellow - 28BYJ48 pin 3
int motorPin4 = 9; // Orange - 28BYJ48 pin 4
                        // Red    - 28BYJ48 pin 5 (VCC)

// The sequence 1-3-2-4 required for proper sequencing of 28BYJ48
AccelStepper stepper1; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
AccelStepper stepper2(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);

void setup()
{
  stepper1.setMaxSpeed(1000.0);
  stepper1.setAcceleration(50.0);
  stepper1.setSpeed(200);
  stepper1.moveTo(2048);   
 
  stepper2.setMaxSpeed(1000.0);
  stepper2.setAcceleration(50.0);
  stepper2.setSpeed(200);
  stepper2.moveTo(2048);
}

void loop()
{
  //Change direction at the limits
  if (stepper1.distanceToGo() == 0)
    stepper1.moveTo(-stepper1.currentPosition());
   
  //Change direction at the limits
  if (stepper2.distanceToGo() == 0)
    stepper2.moveTo(-stepper2.currentPosition());
 
  stepper1.run();
  stepper2.run();
}
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: lowres on Mar 03, 2013, 02:57 am
OK, got it.  probably had to do with the pin definition
Code: [Select]
// accellsteppertest.ino
// Runs two steppers forwards and backwards, accelerating and decelerating
// at the limits. Derived from example code by Mike McCauley
// modified by Celem for single stepper
// Set for two 28BYJ-48 stepper motors

#include <AccelStepper.h>

#define FULLSTEP 4
#define HALFSTEP 8

//declare variables for the motor pins
int motorPin1 = 4; // Blue   - 28BYJ48 pin 1
int motorPin2 = 5; // Pink   - 28BYJ48 pin 2
int motorPin3 = 6; // Yellow - 28BYJ48 pin 3
int motorPin4 = 7; // Orange - 28BYJ48 pin 4
                        // Red    - 28BYJ48 pin 5 (VCC)
int motorPin5 = 8; // Blue   - 28BYJ48 pin 1
int motorPin6 = 9; // Pink   - 28BYJ48 pin 2
int motorPin7 = 10; // Yellow - 28BYJ48 pin 3
int motorPin8 = 11; // Orange - 28BYJ48 pin 4
                        // Red    - 28BYJ48 pin 5 (VCC)
// The sequence 1-3-2-4 required for proper sequencing of 28BYJ48
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
AccelStepper stepper2(HALFSTEP, motorPin5, motorPin7, motorPin6, motorPin8);

void setup()
{
  stepper1.setMaxSpeed(1000.0);
  stepper1.setAcceleration(50.0);
  stepper1.setSpeed(200);
  stepper1.moveTo(2048);   
 
  stepper2.setMaxSpeed(1000.0);
  stepper2.setAcceleration(50.0);
  stepper2.setSpeed(200);
  stepper2.moveTo(2048);
}

void loop()
{
  //Change direction at the limits
  if (stepper1.distanceToGo() == 0)
    stepper1.moveTo(-stepper1.currentPosition());
    if (stepper2.distanceToGo() == 0)
    stepper2.moveTo(-stepper2.currentPosition());
 
  stepper1.run();
  stepper2.run();
}
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sharonf on Mar 07, 2013, 05:12 pm
Hi,

I'm a fresh beginner.
Could someone post pictures of the built circuit so I can learn how to read the diagram ?

Thanks!
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: d00m on Mar 09, 2013, 05:44 pm
sharonf
pls check the first page of this thread.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sharonf on Mar 10, 2013, 04:59 pm
Doom, I mean a "real" picture of the arduino and the wires, not the circuit sketch
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: celem on Mar 10, 2013, 05:06 pm
Sharonf, you can see a video of a "real" functioning  28BYJ-48 5-Volt Stepper circuit on YouTube - at http://youtu.be/z3AO8XRncAc (http://youtu.be/z3AO8XRncAc)

If you pause the video you'll be able to see the wiring. It is using an Arduino NANO
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sharonf on Mar 10, 2013, 06:37 pm

Sharonf, you can see a video of a "real" functioning  28BYJ-48 5-Volt Stepper circuit on YouTube - at http://youtu.be/z3AO8XRncAc (http://youtu.be/z3AO8XRncAc)

If you pause the video you'll be able to see the wiring. It is using an Arduino NANO



Thanks,
What is the additional board at the end of the prototype bread board?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: celem on Mar 10, 2013, 07:51 pm
A breadboard power supply. The stepper draws too much current to run from the USB port. The power supply was purchased over eBay and is similar to these:
http://tinyurl.com/a6nj256 (http://tinyurl.com/a6nj256)
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: harriscreekcentral on Mar 11, 2013, 03:46 am
Is there Anybody out there... there... there...

Yes, I am out here, and I am a newbie reading every little bit of information like a new born puppie having its first drink of milk from its mommies nipple.  That is about the best way I have of describing my experience with Arduino.
I have the Arduino Uno, the 2003 driver board and the 28BYJ-48-5 motor.  I have played with the Uno board and have suceeded in getting the "Blink" command to work.   I have tried a previous set up to  get the motor to do its thing but so far a "Fail"..
I have just received a second new motor and 2003 board, and I am about to go to my basement work area and start a new fresh approach to the problem.
My aim to have the Uno control a stepper motor to drive a dividing head for my Unimat lathe.  I would like to direct you to a "YouTube" video by Chuck Fellows : http://www.youtube.com/watch?v=XwX0YjClgQE.......This is what I am aiming to do.
I will be back.  I just wanted you to know I was taking in all the good information.
Harvey,
in Kelowna, BC.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sharonf on Mar 11, 2013, 09:04 am
Maybe you could upload a picture of the wiring you did for the stepper + arduino, and the code you used?
I got it to work with some effort
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: harriscreekcentral on Mar 12, 2013, 12:19 am
I had Chuck look at the wiring. He thought I had one set of wires backwards.  I have taken that set up apart and I am starting all over. I'll see how far I get tonight.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: harriscreekcentral on Mar 13, 2013, 04:28 am
Note  reference to: "Celem" December 31, 2011, 11:46:27 AM »

I have copied and pasted the code from your messgae.  Thanks very much.  Now, I am new, new, new,to Arduino and the "codes" ..I am using the 28BYJ-48-5VDC Gear Stepper Motor with ULN2003 Driver Board. So just to let you know why I put in three new's my first project was to download the "BLINK" code, and completed that succesfully.  Now I have set up the Arduino Uno, with this little motor and driver, downloaded the code from your posting, and woopy it also works. So now Grampa has two attempts that have worked.

I sort of understand the concept of the clockwise and the C/clockwise, but I have no clue as to where to go into the code to edit it.  My motor is turning at just under 1 rpm.  Where  do I go to adjust the speed, and direction. Thanks for your help.
Harvey
in Kelowna BC.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: celem on Mar 13, 2013, 03:13 pm
If you are using the code in my December 31, 2011 post the variable "motorSpeed" controls the speed since it is used for the "delay" value between steps.
If your goal is to increase speed, remember that this stepper is geared down with a 1:64 ratio - so it will never spin very fast. That said, it can be improved with a different library - see my post of January 17, 2012, 10:14:20 AM - try the AccelStepper (http://www.open.com.au/mikem/arduino/AccelStepper) library mentioned there. The VIDEO (http://youtu.be/1F3240hCHE4) at that post shows the AccelStepper (http://www.open.com.au/mikem/arduino/AccelStepper) in use - your stepper should turn at least this fast.

The AccelStepper Library (http://www.open.com.au/mikem/arduino/AccelStepper) has speed() and runSpeedToPosition() functions that may give you what you want. While the AccelStepper (http://www.open.com.au/mikem/arduino/AccelStepper) Library supports a maximum stepping speed to about 4kHz, the 28YJ-48 supports a maximum no-load step rate of 900pps (less that 1kHz).

The 28BYJ-48 has a step angle of 5.625°/64. Therefore, one full rotation requires 4,096 steps. At 900pps (with simultaneous port writes as mentioned in the post of Reply #19 on: January 14, 2012, 10:17:55 AM) the maximum rotation speed computes to 13rpm (unless my math was wrong) - (900/((360/5.625)*64))*60. However, look back in this thread and you'll see that sbright33 says that he can achieve 35rpm. I don't see how this is possible but that is what he says. Please note, however, that he is running the stepper with 12VDC and he has to de-power it when idle to avoid overheating, so he is driving the stepper very hard.

As to speed, remember that this stepper was designed to move the vents on air conditioners, that are popular in Asia, with a goal of high torque not high speed.

Good luck with your experiments.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Mar 13, 2013, 04:39 pm
What he said.  Seriously.  My code does support acceleration in many of the functions so you can achieve the results in AccelStepper library without any effort.  Even using 5v.  12v is capable of going much faster with the only difficulty that celem mentioned.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: celem on Mar 13, 2013, 06:50 pm
sbright33 - re "What he said.  Seriously." No offence intended - your library and the empirical research behind it are commendable and it is just that your RPMs exceed the factory specifications and my personal experience. I have never tried running that stepper on 12V nor the resistors and capacitors. Maybe I'll try it when the time is available (if I can dig up a suitable 12V PS). I do have copies of your step1a.pde and step1p1dps.pde. Is there another version that I should try instead?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Mar 13, 2013, 10:35 pm
Here is the newest version for 28BYJ-48.

https://gist.github.com/sbright33/4178431

12v is reliable, you just have to mind the heat.  This means you cannot run at full speed for 20 minutes.  You can go slow forever using the "cool" functions.  Or go full speed then stop to let it cool down.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: harriscreekcentral on Mar 14, 2013, 11:25 pm
Quote
Reply #74 on: March 13, 2013, 06:13:49 AM


Thanks very much for the information.  I have a very big learning process ahead of me.  I have bookmarked serveral of your suggestions so I can come back to them as required.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: izanette on Mar 18, 2013, 09:20 pm
Hello,

  I've been doing some tests with this motor and I found that it misses some steps in two situations:

1. If you use speeds higher than 14 RPM;
2. If you change the direction frequently.

Case 1 seems normal. It must have a limit when the motor can't rotate fast enough to follow the signals.

Case 2 is something more strange. I created a small sketch where the motor turns an angle based in the value of a potentiometer. The noise in the readings of the potentiometer makes the motor go forward/backward often. When I turn the potentiometer to the limit, it doesn't come back to the initial position. I could get some good precision only if I reduce the speed down to 8 RPM.

Have you noticed this?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: celem on Mar 18, 2013, 09:45 pm
izanette - I have never tested for precision.  However, I would prefer to see programmatic tests without using a potentiometer. For example, running a securely fastened  stepper via test software to a set-point position, mechanically marking the position, then pseudo-randomly run the stepper back and forth and finally return to the set-point position and verify its position to the previous mark.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: izanette on Mar 19, 2013, 02:54 am

izanette - I have never tested for precision.  However, I would prefer to see programmatic tests without using a potentiometer. For example, running a securely fastened  stepper via test software to a set-point position, mechanically marking the position, then pseudo-randomly run the stepper back and forth and finally return to the set-point position and verify its position to the previous mark.


Hi celem,

Yes, I agree that it is better to have some random movements to make it easier for anyone to reproduce the experiment. So, I created this simple sketch:

Code: [Select]

/*
* Brownian motion
*
* A stepper motor moves forward by randomically chosen steps.
*
*/

#include <Stepper.h>

// change this to the number of steps on your motor
#define STEPS 2038

// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 8, 10, 9, 11);

// the position of the motor
int pos = 0;

// end of the brownian movement
boolean finish = false;

void setup()
{
  // set the speed of the motor to 7 RPMs
  // values higher than this leads to lose of steps
  stepper.setSpeed(7);
}

void loop()
{
  if (!finish)
  {
    // choose a value from -5 to 10
    // statistically, it will move forward.
    int movement = random(-5, 10);
   
    stepper.step(movement);

    // saves the position of the motor
    pos += movement;
   
    // finishes when it completes 2 turns
    if (pos > 2 * STEPS)
    {
      finish = true;
     
      // returns to the initial position
      stepper.step(-pos);
    }
  }
}


  Using it, I found out that the speed limit is even lower: 7 RPM. I'm using 4 NiMh batteries to power the motor, they supply about 4.8V. Maybe with a higher voltage it is possible to achieve higher speeds without loosing steps.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Mar 19, 2013, 04:20 pm
That makes sense to me.  You can only go 7RPM when you change directions without a delay.  You can go 14RPM in one direction.  The solution is simple.  Go 14RPM, then stop for a short delay before changing directions.  It's easy to calculate the delay using 7RPM.  It's just twice the delay between steps at 14RPM.

Why not use 12V as in my code?  You can change the duty cycle while moving so it never gets warm.  Increase it back to 100% for 1 step before and after you change directions.  This will give you 30RPM without any delay, even when changing directions.  That's 4x faster.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: vm5ita on Mar 30, 2013, 11:44 pm

Here is the newest version for 28BYJ-48.

https://gist.github.com/sbright33/4178431

12v is reliable, you just have to mind the heat.  This means you cannot run at full speed for 20 minutes.  You can go slow forever using the "cool" functions.  Or go full speed then stop to let it cool down.

For sure there's something that I didn't understood but, after using, with success, the first sketch on this post, I'm trying the last one without obtaining nothing of good. The four red leds on the PCB stay fixed without blinking.
In the setup there's no declaration of potentiometer to drive the motor. Is there something, due to my ignorance, that I miss? Thank You!
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: harriscreekcentral on Apr 27, 2013, 05:47 am
I am having trouble.   I found one code that I actually got to work, giving me the 1 RPM.  I have to admit I did not save it and cannot find it again for love nor money.. For some of my previous postings you can refer to # 70 area.  I Have had several other projects that needed my attention thus the delay in getting back to Stepper Motors.

I am wanting to start out fresh, and see if starting with a clean slate gets me on the right track.

I have some (5 sets) new motors and the 2003 drivers that should be on my door step in the next few days.  I also have two of the A4983 driver boards.

My first objective is to load a fresh sketch with code that I know has been proven.  I see several within these pages but am confused as I know zero about reading the codes.  Your direction again to the correct code for the basic forward reverse operation would be greatly appreciated.

Once I get the new motors and boards, I will try to keep my nose to the grind stone until I get this mastered. Thanks so much for your help.


Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on May 01, 2013, 05:35 pm
I don't think my code is compatible with A4983.  Try it with ULN2003.

Just download my code from Gist.  Try one function call at a time in Loop() until you get the hang of it.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: econjack on May 08, 2013, 05:53 am
HarrisCreekCentral:

I have a copy of Jack Purdum's Beginning C for the Arduino and would be happy to send it to you. (I pretty much know what's in it now.) I have a junk email account at h656775@yahoo.com if you want to send me your mailing address. On the email subject line write something like "Arduino C Book" so I don't just delete it!
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: jmbillings on Jun 08, 2013, 01:29 pm
Thanks for your work on this!
I'm new to Arduino, but your code makes sense so far apart from a few things...

My current Loop (test) code is:

Code: [Select]
 
 ramp(false, 1200);
 dw(13,HIGH);  
 degrpmslowCool4(false, 3.6, 1200);


I'd expect this to ramp up, then when the LED comes on to do one rotation - I assumed "deg100" is the number of degrees divided by 100. But it spins round more than that (around 2 times ish).

Can you clarify how the values work? My eventual goal for my project is to get the motor rotating at a known speed (doesn't need to be fast, a few RPM is enough, but I do need to know the speed is reasonably accurate; i.e. whatever function to run at a consistent 6rpm would be fine)


**EDIT**
Actually, just having this command in my loop:

Code: [Select]
degrpmEZ(false,90,1200); 

Will leave the motor just spinning forever- so I guess the "deg100" is not what I think it is. And if my loop only has degrpmslowCool4(false, 3.6, 1200); in it, the motor never even moves..?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jun 08, 2013, 09:28 pm
Off the top of my head while traveling I don't recognize ramp().
36000 is 360 degrees in my function call.
1200 is 12 RPM.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: E40racer on Jun 09, 2013, 12:42 am
I wrote some non blocking code (not using the delay function) for these stepper motors a little while ago: http://www.bajdi.com/non-blocking-code-for-the-28byj-48-stepper-motor/

I have just written some code that controls 4 of these little stepper motors using 2 74HC595 shift registers. So I'm controlling the 4 motors with only 3 pins. Will post it later on my blog.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jun 09, 2013, 05:00 am
Nice simple code!  I have also included 4 non-blocking functions.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: jmbillings on Jun 09, 2013, 11:38 am

Off the top of my head while traveling I don't recognize ramp().
36000 is 360 degrees in my function call.
1200 is 12 RPM.



Ahh, reverse of what I thought - cheers, i'll keep playing!
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: fcaldeira on Jun 28, 2013, 01:44 pm
2 Stepper motors with drive 28BYJ-48 (Chinese) + lib accellstepper

Hello everyone, I need help. I am wanting to use the lib that accellstepper

control over a stepper motor at the same time, but I can not for the code

using 2 motors running in opposite directions simutaneamente, triggered by buttons

for clockwise and counterclockwise. For lib "Stepper.h" and 2 engines already

get (below).

I thank anyone who can help.






Code: [Select]


#include <Stepper.h>


//
//
// 2 Motor de passo 5v + 2 botoes
//
//
#include <Stepper.h>  //Biblioteca já disponível na IDE do Arduino



#define STEPS 150  // max 100

const int steps=100;  //Número de passos para o motor
int buttonState1=0;
int buttonState2=0;
Stepper stepper1(STEPS, 0, 2, 1, 3); // Motor 1
Stepper stepper2(STEPS, 5, 7, 4, 6); // Motor 2

void setup()
{
stepper1.setSpeed(200);    //Velocidade da rotação do motor (RPM)
stepper2.setSpeed(200);    //Velocidade da rotação do motor (RPM)
pinMode(8,INPUT);   //Botão 1
pinMode(9,INPUT);   //Botão 2
pinMode(12,OUTPUT);   //LED

}

void loop()
{
buttonState1=digitalRead(8);
buttonState2=digitalRead(9);
if(buttonState1==LOW)   //Gira para um lado
{
   digitalWrite(12,HIGH);
   stepper1.step(steps);
   stepper2.step(steps);
}
else if(buttonState2==LOW)  //Gira para o outro lado
{
   digitalWrite(12,HIGH);
   stepper1.step(-steps);
   stepper2.step(-steps);
}
else   //Fica parado
{
   digitalWrite(12,LOW);
   stepper1.step(0);
   stepper2.step(0);

}
}


Title: Re: 28BYJ-48 5-Volt Stepper
Post by: fape on Jun 30, 2013, 02:08 pm
Hi guys!

First of all thanks for the useful things in this thread.
The arduino is really new for me, so sorry about my noob questions.
I'd like to create a motorized camera slider, first only with one 28BYJ-48.
I found Sbright33's great library(https://gist.github.com/sbright33/4178431 (https://gist.github.com/sbright33/4178431)).
But I'm so confused about the wiring. Do I simply connect the 28BYJ-48 motor to the arduino board. In this case how can I get 12V? Eg from the arduino board's Vin pin?
Or do I need to use the ULN2003 board (Connect the 28BYJ-48 motor to the ULN2003 and the ULN2003 to the arduino board)?


Thanks for your answer.

Regards,
Peter
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jun 30, 2013, 03:29 pm
Here's a good picture for you:
http://www.geeetech.com/wiki/index.php/Stepper_Motor_5V_4-Phase_5-Wire_%26_ULN2003_Driver_Board_for_Arduino
or
https://www.google.com/search?q=uln2003+wiring&tbm=isch
or
https://www.google.com/search?q=uln2003+wiring

I made a camera slider too!  Thanks for the Compliments...
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jun 30, 2013, 03:34 pm
You can use 5V or 12V.  Some of my functions are designed for a 12V supply and 5V motor.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: xitosman on Jul 03, 2013, 08:44 pm
hey guy this working perfectly thanks a lot
can you make a knob version
(if you dont understant war the knob is):
control thr direction of the stepper thith a pontetiometer
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jul 04, 2013, 06:13 pm
I would consider it.  What do you mean exactly?

Can anyone think of any improvements to my code?  It's been awhile since I asked or made any changes.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jul 14, 2013, 01:40 am
What's a knob version?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: jrburke99 on Aug 15, 2013, 10:45 pm
I am trying to use the original code on the first page of this post. I have this same stepper, and I only need to rotate it once, 360 degrees. Nothing continuous, and not very often. When I use the CustomStepper library, it works very well. But when I try to use the code from the original post here, the motor is very slow, and that is when I have the speed dialed all the way up to "5". Plus if I feel the motor, it feels very stuttery, not smooth at all like when I use the CustomStepper library. I looked at that library, and it seems to do the same thing (uses digitalWrites to the pins, and in the same sequence). So what is the difference? What am I missing? And how can I optimize the original code to make it work the same way? I want to take that code, and then use shift registers to send the various HIGH/LOW commands to several stepper motors at once. Thanks!
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: jrburke99 on Aug 15, 2013, 11:12 pm
Update. I just tried using a delay of "1", and that works very smoothly. Is there a way to use anything lower? Say "0.5"?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: o_lampe on Aug 31, 2013, 05:07 pm

Update. I just tried using a delay of "1", and that works very smoothly. Is there a way to use anything lower? Say "0.5"?


I'm also new to this and just started to explore the different Demos. With the sketch from posting #1 it wont be possible to go faster than delay(1). But if you like, you can rewrite the sketch and use delayMicrosecond and recalculate the whole potmeter-reading.

BTW: I have a newer Version of the ULN2003 board. It is made in SMD fashion and features pins in1-7 and A-F.
This pcb must be powered in a different way, where GND and VCC are placed on a separate Header instead of using In5 for VCC.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: o_lampe on Sep 02, 2013, 08:47 pm

...Can anyone think of any improvements to my code?  It's been awhile since I asked or made any changes.



I tried to understand what your code is doing. It seems, there are different voids to do the same Thing. " st07" is doing the 8-step thingy in an improved way, but there are also two others. Why?

There is a void "move" , which seems to be the simplest way to move the stepper.
It would help me a lot, if you could write a simple example program to demonstrate how to do microstepping or fast running.
Would you consider to split the sketch in a standard-(5v) and overclocked (12V)Version?

THX alot
Olaf
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Sep 10, 2013, 09:46 pm
Yes there are a few ways to step with st07.  Full steps and half steps.  4 or 8 of them.  Look for differences in the code.  You should not call these directly, as they are used by my functions.

move() is the easiest way to move one step.  The other functions use degrees and RPM as parameters.  Maybe you could help me by writing some demo code.  Just try one function call at a time in loop() or setup().  My Demo is only one short line of code.  They are commented out.  When you execute it you will see what it does.  Let me know if you have any questions about any of the function parameters.  I have written them up somewhere on github.  I can also translate what the function name means if you'd like.  The easiest way to learn is to try! 

Generally the "Cool" functions are designed for 12v.  There is no need to cool with 5v, as it will not be excessively hot to begin with.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: tone57 on Sep 14, 2013, 07:09 pm
Hey all, I just fell off the turnip truck and i just got one of these motors with the driver board.
don't have a clue how to wire it to my arduino. :~
Could one of you point me in the right direction while everyone else laughs and snickers?
thanks,
Tone



Never mind i found it
http://www.4tronix.co.uk/arduino/Stepper-Motors.php

i will have lots of other, hopefully better wuestions soon.
thanks

T
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: frogsmart on Sep 18, 2013, 06:59 pm
Using my own code (on a PC using FreeBSD) I got the 28BYJ-48 5-Volt Stepper
to turn a little faster than 16.5 RPM (with a chopstick horizontally binder-clipped
to it's top for a small load, and to make it easier to see it spin.) [that is, it spun around a
little more than 16 and a half times in a minute.]

Has anyone managed to get it to spin significantly faster than that?
(Irregardless of load)


Title: Re: 28BYJ-48 5-Volt Stepper
Post by: o_lampe on Oct 03, 2013, 12:35 pm

Using my own code (on a PC using FreeBSD) I got the 28BYJ-48 5-Volt Stepper
to turn a little faster than 16.5 RPM (with a chopstick horizontally binder-clipped
to it's top for a small load, and to make it easier to see it spin.) [that is, it spun around a
little more than 16 and a half times in a minute.]

Has anyone managed to get it to spin significantly faster than that?
(Irregardless of load)





It depends on the voltage you apply to the ULN-board. With a 3s lipo-battery (11.1V ) I got 19 rpm without problems.
Someone mentioned 35 rpm on 12V, but he had to accelerate the speed slowly.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: o_lampe on Oct 03, 2013, 12:45 pm
Today I disassembled one of my 28BYJ and found it has a permanent-magnet rotor. It's a so called hybrid-stepper.

Since I'm playing around with some " ferrofluid" at the moment, I added a few drops of this Magic stuff into to airgap between magnet and coils.
By now I can't actually tell a difference, but I'd expect the stepper to have even more torque.
( I couldn't stop the shaft from turning without ferrofluid, and for sure I can't stop it now )

Has anyone ever tested ferrofluid in a serious way and can tell us, what the benefit in a hybrid-steppermotor would be?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Oct 06, 2013, 01:42 am
Curious!  How long will it stay there?  Use a lever and spring to measure torque.  It's easy to measure relative torque without units.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: o_lampe on Oct 06, 2013, 08:47 am
The fluid is based on carbon-hydroxide. It won't dry out soon.
I'll try to set up a test rig, but at work we don't have the right machines and materials.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: kerimil on Oct 22, 2013, 02:40 pm
Here you can find a modified version of AccelSteppper library that supports the motors -> http://forum.arduino.cc//index.php?topic=194671.msg1437300#msg1437300

Not trying to spam just concluded that most people who need it won't even find it.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Oct 23, 2013, 06:37 pm
Can it do this?

Includes ability to step less than step size without losing track of total.
Detect torque spike when you get to end of travel.
Turns off coils between steps for motor with gears that do not need holding torque.
Cooler running with 12v.
Can sleep when moving slow.
Ramping.
Non-blocking.
Enhanced performance using 12v supply with 5v motor.

Here's a summary and some help to get you started:
http://arduino.cc/forum/index.php/topic,89159.0

From above link:
Here is a brief summary of the code.
It can spin a full size DSLR on it's shaft without bearings at 30RPM!
Ramping up and slowing down to prevent bouncing.
It can measure torque to detect an abnormal load or error.
It works without blocking or waiting or interrupts.
Enhanced performance using 12v without warming up the motor.
And much more!
Sounds like an advert, but it's all for Free.
Hardware is $4.

Here's the code:
https://gist.github.com/sbright33/4178431
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: kerimil on Oct 25, 2013, 07:44 pm
Not sure what you mean by
Quote
ability to step less than step size without losing track of total
unless that simply means it remembers every 1/8th of the entire step cycle, which kind of goes without saying really. A step motor library that doesn't do it is not a functional library.

Anyway as I said earlier you're library has some interesting functions in it though I couldn't really get it to work with more than one motor. With Accelstepper it was just a matter of reading comments in the libraries and I knew what to do to mod it. Not sure If I am experienced enough to make such statements but it seems really well structured and easy to understand.

I'll probably add a function for detecting torque spikes when I need it, but you can pretty much add all the functionality you want to.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Oct 26, 2013, 05:50 pm
Let's say the step size is 360/4096 degrees without microstepping.  With my code you can step 0.500 degrees so there are exactly 720 steps in a rotation. 

Accelstepper is easy to modify and understand. 

If the functions you want are already included, then the best choice is obvious!

Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Oct 26, 2013, 05:55 pm
Why doesn't everyone want the ability to use higher power when starting and stopping with 12v supply?  Less when moving at constant speed?  None when stopped with a gear box.  The Uno can go to sleep for some time.  This should be built into Accelstepper?  Mine does acceleration, but it's built in for beginners so you don't even have to consider it.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: kerimil on Oct 26, 2013, 08:37 pm
Just out of curiosity... have you used the motors with L/R driver circuits ? or chopper circuits ?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: pmlapl on Oct 26, 2013, 09:30 pm
Hi,
I've got a couple of the steppers referenced here and wanted to play with them and found your code. I'm sorry, but my experience with Arduino programming is limited and I'm trying to understand how to use it. You say it's a "library" but I don't see a ".h" label for it. Does it have one that I can add to my current libraries? Or, is it a bunch of snippits I can cut and past? I read the brief summary for the code, but once again, it's confusing to me. I understand function calls but which ones do I use? It may seem obvious to you, but not being familiar with them and what they actually do is making it hard for me to use the code. There are also numerous comments that look like commands. I assume they can be selected by uncommenting, but which ones?

Based on the many positive comments and the list of features the code is capable of, it looks like a great way to use these little steppers. However, highly skillful programmers I've found are not the best teachers because they take for granted the knowledge base of the readers. Unfortunately mine is no where near the level of yours. Could you please perhaps post an example of how to use the code with comments to help me understand? I would greatly appreciate it. Thanks.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: kerimil on Oct 26, 2013, 10:17 pm
Quote
Or, is it a bunch of snippits I can cut and paste?

Yes, you are right. Sbright's library isn't a library in a strict sense, but a collection of functions.
You can try the one I modified -  it's easy to use, supports multiple steppers at the same time, acceleration & deceleration, and can be used with a bunch of different types of steppers. I used it in the past for normal (not geared) step motors, as well as several others and IMHO it is really the best one.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: pmlapl on Oct 27, 2013, 01:35 am
Thanks much kerimil. I added AccelStepper to my library and copied your code. Works fine. In the mean time, I still want to try and understand Sbright's code.

Best regards.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: d_anders on Nov 02, 2013, 01:48 pm
Hello, what is the highest torque you can get from this motor? Speed doesn't matter and one step at a time is ok.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Nov 02, 2013, 07:41 pm
Just download the 1 file.  Uncomment some lines in Setup() or Loop() to test it.  Try it!  Only 1 function call at a time is needed.

For this motor, the maximum torque is limited by the internal slip.  Like a clutch.  When you abuse the motor it gets looser over time.  When it's off you can force the shaft to feel it slip.  When you use a higher supply voltage it gets very hot over a few minutes time.  That is another limitation.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: cadcoke5 on Nov 05, 2013, 02:52 am
First, thank you sbright33 for posting all of this.

I have a question that everyone seems to already know the answer to, or they were just very lucky.  There is a jumper that comes with the driver board that everyone sells with this stepper.  I know it either provides power to the steppers using the 5+ that comes from the Arduino board, or it accepts power from an external source.  However, I can't find anywhere that says which way the jumper should be to allow which setting.

-Joe
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Nov 10, 2013, 02:17 pm
I don't have one handy to look at.  Just leave the jumper on.  According to Google it can be used to disable the power to the motor.  If it works don't remove it!
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: cadcoke5 on Nov 10, 2013, 07:17 pm
One of the schematics I found for the board call it out as an, "External Power Switch."  I had originally interpreted this to mean that the power may come from an internal, or external source, and that this jumper chose between the two.  But, now I think I am wrong, and it simply is an in-line switch through the external power source.  It doesn't make a lot of sense to do that, but perhaps it is easier to remove that jumper than to unplug the stepper itself when you are doing tests.

Anyway, I have it working.  Thanks for the reply.

-Joe
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: terryking228 on Nov 30, 2013, 11:38 pm
Hi Steve,

For those just wanting VERY simple info about these motors I have updated the ArduinoInfo.Info WIKI page HERE: (http://arduino-info.wikispaces.com/SmallSteppers)  This now details the 4step vs 8step questions, actual gear reduction etc. There are two cut-and-paste test sketches to run one motor.

I will add links to Steve's Gist version and Accelstepper and others.

I have this stepper and driver board in a MicroComputer Engineering Kit  HERE: (http://yourduino.com/sunshop2/index.php?l=product_detail&p=395)(LINK)that I developed with some schools.  There are over 1000 University students using kits with these motors. The professors wanted them to learn about Stepper Motors because of all the current  CNC machines, 3-D printers etc. In class most schools have students write some stepper code from scratch, but then they use libraries etc.  Once school has 2 students build a small robot using these motors from their kits, and then use their 2.4Ghz transceivers in the kit to communicate with one. I haven't seen that yet, but I am asking for examples to post on ArduinoInfo.Info

Steve, I will suggest that the subjects you have raised about duty cycle / heat and blocking and torque measurement could be added to some of the classes.  

Thanks! to you and others who have used these little motors to enable a LOT of learning for a lot of people.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Dec 18, 2013, 08:41 pm
Thanks for including my code and input on these topics:

1) duty cycle within each step while turning
2) different ways to avoid overheating
3) turning off coils when idle with geared motors
4) non-blocking code can execute other tasks at same time
5) measuring torque simply, to avoid faults or detect end of travel
6) ramping to increase speed and stop skipping steps with a large object

Great Wiki and kit Terry!  Still nobody has documented which motors have exactly 2048 steps/revolution, and which have an odd number with a fraction to the right of the decimal point.  Anyone?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Dec 18, 2013, 08:57 pm
I understand it's for Beginners but...  In your Wiki you didn't mention that it's possible some motor are NOT exactly 2048 steps per revolution.  This could be confusing for some beginners.  Maybe yours are 2048?  I have not seen any information online about how to identify these motors.  Which category are most popular.  Or where to buy them?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: terryking228 on Dec 19, 2013, 12:31 am
Hi Steve,

I believe motors with "28BYJ-48" on them are all the same.  

UPDATE: I now believe that the actual mechanical gear ratio is not 64:1, but 63.68395.:1. Why? Because the train of gears in this motor has a variety of tooth numbers and they do not add up to 4096. The manufacturer expects these to be used for "back and forth" motions and that is the way they are usually used: as the "Back and forth flap" on most room air conditioneers, and "back and forth Vane position" in heating duct vanes.  So I think the manufacturer said "64:1 Close enough"...

All the ones I / YourDuino have are probably from the same manufacturer; we get them from the same supplier/factory, usually 500 at a time.   I reread my Wiki section on this and reworded it a little.  Is THIS clear? Do you think it is correct?

---------------------( COPY )---------------------
Step Angle (8-Step sequence: Internal Motor alone): 5.625° (64 steps per revolution)
Step Angle (4-Step sequence: Internal Motor alone): 11.25° (32 steps per revolution)
Gear Reduction ratio: 1 / 64 (Not really exact: probably 63.68395.:1 )
SO: it takes (64*64 = 4096 steps per output shaft revolution.. In 8-step sequence.
SO: it takes (32*64 = 2048 steps per output shaft revolution.. In 4-step sequence.
NOTE: Arduino "Stepper Library" runs in 4-step mode
-----------------( END COPY )----------------------

I've run these for hours with this sketch: http://arduino-info.wikispaces.com/SmallSteppers#1turn (http://arduino-info.wikispaces.com/SmallSteppers#1turn) and I always see 1 repeatable turn. That's because "back and forth" the same number of steps does not prove the exact gear ratio.  Hmmm....

I think these all have the same gears.. I'll dissect one and post here....

UPDATE: OK, I dissected one, and checked some online dissections that have the same gears. THEY counted all the teeth; I did not. I believe their numbers. See: http://forum.arduino.cc/index.php?topic=71964.msg1149466#msg1149466
Here's the gears as I see them:(http://yourduino.com/docs/StepperGears.jpg)

So, Steve is Right Again.  I can handle that :-)
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Dec 19, 2013, 01:40 pm
They are ALL 4076?  Sounds like I'm the only one with 4096 motors?  It's a simple code to test them just keep spinning in the same direction stopping every 4096 for an hour.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: terryking228 on Dec 19, 2013, 09:43 pm
Steve, MAYBE there are some with different gears inside, but not the ones I've seen.

Let's figure this out!!

Please post/point to your code.  The example I pointed to does 4096 back and forth, so the exact gear ratio is not important to have it return top starting position.

4096 forward, wait, 4096 forward is a different test.   I'll do that one but I'd like to try Your Code And Mine.

Thanks! Terry
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Dec 20, 2013, 08:42 pm
I don't have the code or the motors handy right now.  I'm away from my Lab.  I did the test almost 2 years ago.  Attach a pointer or stick to the motor.  Simply rotate 4096, then stop for 1 second.  Repeat.  After a few seconds, minutes, certainly hours the pointer will stop at a different place moving around like a clock.  20/4096 is 0.5% which is a lot!  More than 1 degree error for each revolution.  That's how I know mine are/were exactly 4096. 
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: terryking228 on Dec 20, 2013, 11:24 pm
Hi,
Quote
Attach a pointer or stick to the motor.  Simply rotate 4096, then stop for 1 second.  Repeat.  After a few seconds, minutes, certainly hours the pointer will stop at a different place moving around like a clock.


That's the exact same result I am seeing. Every 4096 steps the pointer advances a little. After 100 or so cycles, it's very obvious. I'll try to run it and find out how many cycles it takes to be one revolution ahead.

This is consistent with the ratio NOT being 64:1 but something like 63.68395.:1. which is what some of the people who disassembled the motor gearbox and counted teeth found, mathematically.  This makes sense since the  individual gar ratios are not nice division ratios of 64. That would need ratios like 4,4,4,  or 8,8 or something.  The discussion with photo of the gears is HERE:
http://forum.arduino.cc/index.php?topic=71964.msg1149466#msg1149466

That photo looks exactly like the motors I have, bought over the past 2 years from the same supplier:(http://yourduino.com/docs/StepperMany.jpg)

I think this is now all consistent with the gears we see in the motors I have and the one in the above discussion.

Here's the sketch I have that does 2048 steps in 4-step sequence:
Code: [Select]

/* YourDuino.com Example Software Sketch
  Small Stepper Motor and Driver V2.0 12/20/2013
  http://arduino-direct.com/sunshop/index.php?l=product_detail&p=126
  Steps one revolution of output shaft (2048 steps), waits,repeats
  in the same direction. This will show that the motor advances a little
  more than one revolution with 2048 (4-step sequence) steps. This means
  that the mechanical gear ratio is NOT exectly 64:1 but more like
  63.68395.:1  
  Questions: terry@yourduino.com */

/*-----( Import needed libraries )-----*/
#include <Stepper.h>

/*-----( Declare Constants, Pin Numbers )-----*/
//---( Number of steps per revolution of INTERNAL motor in 4-step mode )---
#define STEPS_PER_MOTOR_REVOLUTION 32

//---( Steps per OUTPUT SHAFT of gear reduction )---
#define STEPS_PER_OUTPUT_REVOLUTION 32 * 64  //2048  


/*-----( Declare objects )-----*/
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to

//The pin connections need to be 4 pins connected
// to Motor Driver In1, In2, In3, In4  and then the pins entered
// here in the sequence 1-3-2-4 for proper sequencing
Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11);

/*-----( Declare Variables )-----*/
int  Steps2Take;
int  TotalRevolutions = 0 ;

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
 Serial.begin(9600);
 Steps2Take  =  STEPS_PER_OUTPUT_REVOLUTION ;  // Rotate CW 1 turn
 small_stepper.setSpeed(500);
}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{

 small_stepper.step(Steps2Take);
 TotalRevolutions += 1;  // Count revolutions
 Serial.print("Total Revolutions = ");  
 Serial.println(TotalRevolutions,DEC);

 delay(2000);

}/* --(end main loop )-- */

/* ( THE END ) */



Bottom Line: This motor is fine for small back-and-forth applications, but constant 1-direction applications such as a clock face need corrections for the non-standard gear ratio.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Dec 28, 2013, 07:54 pm
Has anyone tested the same physical motor size with 16:1 ratio?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: terryking228 on Dec 29, 2013, 01:35 pm
Hi Steve, Can you point to a source for a 16:1 version? I'll try to test...
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Dec 29, 2013, 05:38 pm
Darn, can't find them by Googling.  After 100 rotations of 4096 it should be off by about 180 degrees.  Is this what you're seeing?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: terryking228 on Dec 29, 2013, 06:13 pm
Quote
After 100 rotations of 4096 it should be off by about 180 degrees.  Is this what you're seeing?


Yes, that's about what I'm seeing. It is quite obvious after 4 or 5 rotations.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: tuckera on Jan 01, 2014, 05:40 pm
I've been playing with the 28BYJ-48 stepper for the past few days, and this thread has been extremely helpful!
I became interested in the gear ratio controversy, loaded the test code Terry posted in Reply #131 of this thread, and ran it with my motor.  I saw the same thing he did - doing the 4-step methods with 2048 steps advances a pointer about 1.8o more than 360o.
Then I changed the code to do 2038 steps and the pointer returned to the same spot every time, with no error noticeable after about 140 revs.  Now I know how to get the speed I want out of my motors.  For what it's worth I got my motors recently (mid Dec. 2013) from ebay seller "nyplatform".

I started playing with Terry's code and tried to get a good correlation between the speed setting in the program and the actual speed of the motors, but I got results that did not make any sense.  Then I started systematically changing the speed setting and measuring the actual RPM.  The data and a graph are shown below.

The interesting thing is that there only seem to be 3 speeds available above 6rpm!  Has anyone seen this before?  Any idea what causes this behavior?
andy

(http://chem.queens.edu/bp/28BYJStepperGraph.gif)
[font=Lucida Console]Speed      
Setting     RPM       RPM*68.68395
20         0.31     20.01
50         0.79     50.30
100         1.62     103.36
150         2.44     155.35
200         3.25     206.74
250         4.11     261.91
300         4.80     305.93
350         5.85     372.28
400         7.34     467.75
450         7.33     467.12
500         9.65     614.61
550         9.64     614.12
600         9.68     616.59
650         14.49     922.51
750         14.49     922.96
800         14.50     923.63
850         14.50     923.18
900         14.46     920.73
950         No Rotation   
1000     No Rotation   [/font]
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jan 02, 2014, 03:52 pm
There must be a problem or misunderstanding in the code.  Off the top of my head I have seen 30RPM.  At 20RPM for example the speed is almost infinitely variable.  Each step can be 800us or 801us.  So you can go 20.02 or 20.04RPM. 

We can conclude that most motors are 4076.xxx and not 4096.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: ajofscott on Jan 03, 2014, 01:08 am
Terminal speed is a limitation of drive voltage,  winding inductance, and rotor inertia. As far as compatibility with the stepper class, it is compatible, your phase sequence must be correct. The actual phase order on the drive board header is ACBD due to the pin-out of the motor's connector. I have an external board for my purposes which is  1/2 of a 7486 and both halves of a 7474 configured as a synchronous up/down counter. Q1=A, Q2=B, Q1 NOT=C, Q2 NOT=D. I have done this so I can run 4 motors within the pinspace of an UNO and have all of the serial and analog pins available without relying on TWI schemes, not to mention I have driver boards other than the Arduino Motor Shield R3.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: tuckera on Jan 03, 2014, 05:03 am

There must be a problem or misunderstanding in the code.  Off the top of my head I have seen 30RPM.  At 20RPM for example the speed is almost infinitely variable.  Each step can be 800us or 801us.  So you can go 20.02 or 20.04RPM. 


Terry's code uses the Arduino stepper library with only 4 steps.  You have a post on the first page of this thread after you had tried celem's code:
Quote
I was getting about 7RPM using 1,2,3,4 sequence in library.
15RPM with decent torque using 1,3,2,4 in library.
35RPM with your code and more torque!

So I'm getting about the same top speed you got using the 4 step code.  I have no doubt that using 8 steps is better, but I'm still wondering what causes the limited speeds...
andy
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: MarkT on Jan 03, 2014, 09:21 pm
The reason that motor is a poor performer is it has high impedance windings - typically
30 or 50 ohms.  That means they are lots of turns of very fine wire.  This then means they
have a high inductance.  The more inductance the slower the current can change when the
winding drive switches.  Try to switch too fast and the current no longer is responding
much to the drive waveform - current is what generates the force in the motor.

The only ways round this are to use a higher drive voltage (and a current-limiting driver),
or lower resistance/inductance windings.

For instance high-performance bipolar stepper motors for CNC machines are typically
0.5 to 1 ohm winding resistance, take 2 or 3A and use current-limiting (chopper) drivers
from 36 to 120V supply.  The winding only needs a volt or two to overcome its resistance,
the rest of the power supply voltage is available to overcome inductance in the windings
(to get faster switching) and back-EMF from the spinning rotor (to get faster top speeds).

Unlike standard motors, steppers have to switch the current dozens to hundreds of
times faster, so inductance is a real performance limiter.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: tuckera on Jan 04, 2014, 09:16 am
I finally dug around in the stepper library and figured out why the number of speeds is limited!  It's an artifact of the way the Arduino stepper library sets motor rpm.  The speed value is used to calculate the integer "step_delay", which is a delay in ms inserted between pulse trains using the delay function.
If you calculate the step_delay for 500, 550, and 600 rpm, you get 3.75ms, 3.409ms, and 3.125ms.  However, the arduino is doing this with integer variables, so all of them come out as 3ms, so you get the same speed for each of those settings.
I guess the moral of the story is don't use the Arduino stepper library if you need a specific speed!  Now I'm playing with the AccelStepper library, which looks promising so far...

MarkT - thanks for the lucid explanation of why impedance matters!

I feel like I'm starting to get a handle on how steppers work, but I'm still not clear on why the 8 step(half stepping) sequence gives better performance(speed and torque) than a 4 step sequence.  ajofscott said "Terminal speed is a limitation of drive voltage,  winding inductance, and rotor inertia."  Are these the ONLY factors?  If so, then I guess I'd have to think that the extra pulses are keeping up momentum to fight inertia.
andy
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: ajofscott on Jan 04, 2014, 10:27 pm
Sometime you need to take a stepper motor apart and look and see how it is made, it will make more sense to you on how they operate. Although technically a type of synchronous motor, steppers are a unique animal compared to a conventional sine driven synchronous motor.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Jan 07, 2014, 06:53 am
All that you said makes sense to me.  You can get 35RPM by using a higher voltage with these tiny motors!
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: fran52 on Mar 19, 2014, 08:36 am
I know this is a sidestep to the topic but:  does anyone know if it would help to replace the uln2003 with a uln2803?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: dabineri on Apr 17, 2014, 03:55 pm
I am looking either for wheels that fit the 28BJ stepper or hints on how to make wheels for this motor.

Any ideas?   Thanks Dave
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: gadget_greg on May 21, 2014, 06:41 am
I haven't read this entire thread but...

Is there a link to the 'final' code that you guys have come up with?

And I'd like to offer this for anyone interested in learning how stepper motors work.  I watched it the other day and it's well made and quite informative!

https://www.youtube.com/watch?v=bngx2dKl5jU
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: huntermccray on Aug 27, 2014, 04:33 pm
Hey Guys!

I know this thread has been quiet for a while, but I am hoping for a bit of input on a project involving some 28BYJ-48 steppers with uln2003 drivers....

The project involves driving a fairly large number of steppers (10 to 30 in groups of 4-6) at ~10-20 rpm with as much torque as the little guys can muster....in ~6 hour cycles....12V/Full Step provides the requisite torque/speed but as noted frequently in this thread, the motors get really hot really fast...

I am familiar with stepper motor drivers from my CNC hobby and have a fairly strong background in electronics...In short, I know I need the higher voltage to overcome the inductance inherent in these steppers, but I need to limit the current to keep them from heating up....This is easily achieved with a PWM chopper with current feed back, but I don't have any desire to design/build a large number for complicated drivers......

Obviously I can use the existing code posted @ github, but I really don't want to dedicate a large number of arduinos to achieve the goals...preferably I would like to use some ATTINY2313's I have on hand....and this is where I need a touch of help....I have been writing AVR code in assembler since the 90s, but I have never taken the time to learn C....If someone could take just a few moments to outline how the "coolstep" portion of the code works with some pertinent details about the timing involved it would save me a ton of bench time......I suspect the "coolstep" function modifies the full or half step routines by breaking  each step into pulses...that is, for instance, @ the beginning of a 1mS step the driver is on for say 400uS, then "off" for 100uS then "on" for 100uS then "off" for 200uS then "on" for 50uS then off for the final 150uS....It is also possible the code could simply turn the driver on a specific period of time, then turn it off, thus allowing the current to reach its requisite level for the step and allowing the core's momentum to carry it through once the core has reached its saturation current.....

I don't need anyone to write the code for me, I would just love a few details about how the "coolstep" function actually works w/o having to battle my ineptness with C....

Thanks in advance.

Fish   
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: steinie44 on Sep 04, 2014, 08:47 pm
Adafruit Small steppers are 9-12V with 16 to 1 reduction or 16.032.
http://www.adafruit.com/products/918 (http://www.adafruit.com/products/918)

Yes, ULN2803 will work, it has 8 drivers and can run 2 steppers.
Better yet, add a PCF8574 in front and run them with I2c with only 2 pins.

Title: Re: 28BYJ-48 5-Volt Stepper
Post by: cbailer on Oct 11, 2014, 11:34 pm
I am a newly graduated ELCT. I have ordered my third component kit for the arduino and am having issues finding color code conversions. I understand US colors, but I cannot find what these wires represent: blue, pink, orange, brown, and yellow. Can someone help me before I hook this step motor to my Mega and blow it up.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: micahm on Nov 08, 2014, 08:22 am
Hello all,

This thread has been extremely helpful in me getting my 28BYJ-48 stepper motor running properly, so thanks.
One thing I would like to be able to check is the torque, or more exactly, check for a torque spike.

I looked at the library from sbright33 (thanks!!) located here:  https://gist.github.com/sbright33/4178431
I copied out the relevant section (or what I think is the relevant section):

//torque load detect code to prevent destroying motor
for(int i=0;i<steps;i++){
  if(nar>=1024){ //lower for slow?
    k=sum*5/nar; //why not 6? div 0? fixed
    if((k==last)&&(!norm)&&(millis()>5*1000)) norm=k; //since program start
    if((k==last)&&(k==norm+1)) norm=k; //within 40 sec when if k>norm+0 below
    //if((k==last)&&(k==norm-1)) norm=k;
    digitalWrite(13,LOW);
    if(!norm)digitalWrite(13,HIGH); //ON until normal is found
//10,-10 for 8v level ground
// 0,-10 for 12v >30RPM only
    if(((k>norm+20)&&norm)||((k<norm-20)&&norm)){ //0,-10 can change 2B less sensitive with high load
      digitalWrite(13,HIGH);
      //will never print past 1 min
      //Serial.println();Serial.print(millis()/1000/60);Serial.print(" Min ");Serial.print(nalarm+1);Serial.println(" count");
      if(millis()>long(40)*1000){ off(); while(1);} //infinite loop
      if(nalarm++>10){ off(); while(1);} //can change 10
    } //if load
    last=k;
    sum=nar=0;
  } //if 1024
  ccw();
  //if(i%16==0)Serial.println(float(i+1)*360/64/8);
  //can detect individual outliers here
  nar+=8; for(int j=0;j<8;j++) sum+=ar[j];
} //for


How does this check for the torque?  I am at a bit of a loss.  Thanks in advance if you can enlighten me!
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: sbright33 on Nov 15, 2014, 12:17 am
Yes, I wrote that code years ago.  Yes, you found the correct section.  Yes, I can remember exactly how to connect it, since it's so easy.  Yes, it works perfect in my application to detect a change in torque.  But I cannot explain the overall flow, and it takes me awhile to understand a specific line, even with my cryptic comments.  They made sense at the time?  Think of this code as an example to base your code on.  It should work for many situations, by only changing a few constants. 

Here's how to connect the hardware:  Connect a wire from any of the motor coils, to an analog pin.  I guess that AnalogRead is done in an earlier section.  Search for sum=.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: LorttoJorma on Feb 08, 2015, 11:00 pm
Code: [Select]
// This will show that the motor advances a little more than one revolution with 2048 (4-step sequence) steps.
// This means that the mechanical gear ratio is NOT exactly 64:1 but more like 63.68395.:1.

// Import needed libraries.
#include <Stepper.h>

// Number of steps per revolution of INTERNAL motor in 4-step mode.
#define STEPS_PER_MOTOR_REVOLUTION 4

// Steps internal motor have to take, so OUTPUT shaft turns one full revolution.
// 2048 would be the right number if the gear ratio was exactly 64:1.
// 2041 was the closest one i can come up, output shaft goes allmost full revolution.
// 2024 goes just over one revolution, a bit more over than 2041 leaves short.
// At 700 full revolutions it was ~1mm short from the start point at distance of ~10mm from the shaft.
#define STEPS_PER_OUTPUT_REVOLUTION 2041

// In1, In2, In3, In4  and then the pins entered here in the sequence is
// 1-3-2-4 for proper sequencing
Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 23, 27, 25, 29);

// Declare Variables
int  RunStepper;
int  TotalRevolutions = 0;

void setup() {
 Serial.begin(9600);
 RunStepper  =  STEPS_PER_OUTPUT_REVOLUTION;  // Rotate CW 1 turn
 small_stepper.setSpeed(6000);  // Fastest my motor would start with this sketch was somewhere 7500+ but the torgue starts to weaken after 5000+
}

void loop() {
 small_stepper.step(RunStepper);
 TotalRevolutions += 0;
 Serial.print("Total Revolutions = "); 
 Serial.println(TotalRevolutions,DEC);
 delay(200);
}
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: thrash3r on Apr 16, 2015, 10:47 pm
Please i need a Code to make something similar to this video https://www.youtube.com/watch?v=epSI04xXR7s
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: Old_Goat on Jun 18, 2015, 02:37 pm
Hi sbright33,

Looking through your 'stepper2' sketch there seems to be an error (or omission) in your direction loop - see void movetodir(boolean bcw, int steppos) sub-routine.


void movetodir(boolean bcw, int steppos){
//absolute position you decide direction
steppos&=4095;
movecnt&=4095; //this will not happen in move() can be >4096 or <0
while(movecnt!=steppos) {
 move(bcw);
 movecnt&=4095;

Compiling this section returns an error  - move was not declared in this scope. Perhaps a int is required here???
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: Old_Goat on Jun 20, 2015, 03:01 pm
Hi sbright33,

I d/loaded your stepper2 sketch and extracted the code "//code decides which direction to move is shortest" .

I then added an array with 8 various degrees and ran the sketch.

It worked BUT IN REVERSE! If I asked for 120° the stepper went to 240°. If I asked for 40° the stepper went to 320°, etc., the CW and CCW seemed to be about faced. Also, I found that this sketch only found the 'long way' to the next angle.

Maybe somewhere there's a error in the sketch or I missed something?

I made a short movie on this but I don't yet know how to post it.

Cheers
Old_Goat
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: mcnobby on Dec 18, 2015, 02:34 pm
Can I just clarify... did you get 35rpm out of the 28BYJ-48 ??
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: highrollerNO on Feb 06, 2016, 01:51 pm
Hello, and what an informative thread!
I have the 28BYJ-48 and struggeling with heat.

With no load on the stepper it gets realy hot after only 20-30 seconds with this code:

Code: [Select]

/* YourDuino.com Example Software Sketch
   Small Stepper Motor and Driver V1.3 11/30/2013
   http://arduino-direct.com/sunshop/index.php?l=product_detail&p=126
   Shows 4-step sequence, Then 1/2 turn and back different speeds
   terry@yourduino.com */

/*-----( Import needed libraries )-----*/
#include <Stepper.h>

/*-----( Declare Constants, Pin Numbers )-----*/
//---( Number of steps per revolution of INTERNAL motor in 4-step mode )---
#define STEPS_PER_MOTOR_REVOLUTION 32   

//---( Steps per OUTPUT SHAFT of gear reduction )---
#define STEPS_PER_OUTPUT_REVOLUTION 32 * 64  //2048 

/*-----( Declare objects )-----*/
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to

//The pin connections need to be 4 pins connected
// to Motor Driver In1, In2, In3, In4  and then the pins entered
// here in the sequence 1-3-2-4 for proper sequencing
Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11);


/*-----( Declare Variables )-----*/
int  Steps2Take;

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
// Nothing  (Stepper Library sets pins as outputs)
}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
 // small_stepper.setSpeed(1);   // SLOWLY Show the 4 step sequence
 // Steps2Take  =  400;  // Rotate CW
 // small_stepper.step(Steps2Take);
 // delay(2000);

//  Steps2Take  =  STEPS_PER_OUTPUT_REVOLUTION / 2;  // Rotate CW 1/2 turn
//  small_stepper.setSpeed(100);   
//  small_stepper.step(Steps2Take);
//  delay(1000);
 
  Steps2Take  =  - STEPS_PER_OUTPUT_REVOLUTION / 2;  // Rotate CCW 1/2 turn 
  small_stepper.setSpeed(700);  // 700 a good max speed??
  small_stepper.step(Steps2Take);
  delay(2000);

}/* --(end main loop )-- */

/* ( THE END ) */


I looked at the github page mentioned many times but the code gets to complex for me.

I am going to use my stepper to pull some curtains, but with the heat its building up at the moment i think there might be something wrong with the code i am using.

I am using the nano and the stepper driver that came with the motor with 12V powersupply.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: MAS3 on Feb 06, 2016, 09:49 pm
Hi.
The ones i've seen myself are 5 volt motors.
Are you sure yours is a 12 volt motor, does it say so on its label ?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: highrollerNO on Feb 09, 2016, 12:08 pm
Oh ****!

The stepper came with a bundled driverboard that said 5-12v so i just assumed that the motor could handle it. But you are correct, thanks for the tip and i will look more closely at voltages with my next komponents :)

Lucky for me the motor seems to have survived the high voltage.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: seriousmath on Mar 24, 2016, 12:32 am
Hello everyone,

First please excuse my English because I'm french.

I read the whole topic and above all I try to understand but it's a bit hard for someone who has never programmed in Arduino.

I'll try to explain why I found myself on this forum among you today. For the story, I am an amateur astronomer and I make pictures with my telescope.
To create my images I use a camera equipped with a manual filter wheel. I run a disc with the finger which places the desired color filter on camera.

So I bought a 28BYJ-48 5V stepper motor, a ULN2003 driver and a controller Arduino Nano to automate the placement of the desired filter in front of the camera.

Here is a video that shows the operation of what I want
https://www.youtube.com/watch?v=jUYTpBED4ik

Would require that the system be able to position itself in the right place when I indicate it a value of 1 to 5 which corresponds to the position of each color filter. Of course it must be perfectly reproducible positioning.
The control will be by a driver Ascom developed in Visual Basic.

I seek someone who can create the sketch and give me the links to the different libraries to use with.

I am aware that it is easy to register on a forum and come ask for a solution but in the present state of things I do not have the necessary capacity to realize this project.
Whether to give financial compensation via paypal to whoever will help me I'm open to suggestions.

Thank's a lot

best regards

Mathieu
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: HidirHaris on May 23, 2016, 09:19 am
Hi, anyone know how many (in cm) does 1 rotation of 28BYJ-48 do? If you were to do it manually. Thanks
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: Hollay on Jun 22, 2016, 08:53 am
Hello,

I'm new on this forum, need some help please.
I'm going to run an astronomical barn door tracker with Arduino nano.
I wrote a sketch, it works so far but I'm not really satisfied with it.
The basic idea is the following:
if powered up, it has to run down (CCW) in parking position. After pushing lower limit switch it has to wait for the START button. If start pressed, it has to turn CW very slow (as it has to follow Earth's turn) until upper limit switch pushed. If pushed, a blinking LED alerts to finish long time exposure.
There is a finetuning included to set +/- the CW speed (it has to be set up while taking long expo photos not to see lines instead of stars due to wrong speed). Speed is saved in Arduino's EEPROM.

My problems:
torque is not enough CW
with this code CCW movement is not fast enough, have to wait too long for reaching parking position

Could somenone help me correcting my code? Thanks a lot! Regards: F. Hollay
(frigyes <dot> hollay <at> hu <dot> bosch <dot> com)

Code: [Select]

#include <Stepper.h>
#include <EEPROM.h>

const int stepsPerRevolution = 200;
const int buttonPin_UP=5;
int button_state_UP;
const int buttonPin_DOWN=4;
const int buttonPin_START=6;
const int buttonFAST=2;
const int buttonSLOW=3;
int button_state_DOWN;
int ledPin = 13;
int I;
float Sp;

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution,8,10,11,9);

void setup() {
pinMode(buttonPin_UP,INPUT_PULLUP);
pinMode(buttonPin_DOWN,INPUT_PULLUP);
pinMode(ledPin, OUTPUT_PULLUP);
pinMode(buttonFAST,INPUT_PULLUP);
pinMode(buttonSLOW,INPUT_PULLUP);
int I=0;

Sp=EEPROM.get(0,Sp);          // read previously stored speed value
myStepper.setSpeed(Sp);
}

void loop() {
digitalWrite(buttonPin_UP, HIGH);    
digitalWrite(buttonPin_DOWN, HIGH);
digitalWrite(buttonPin_START, HIGH);  
digitalWrite(buttonSLOW, HIGH);      
digitalWrite(buttonFAST, HIGH);    

while (digitalRead(buttonPin_DOWN) == HIGH){              //rotating in parking position until lower limit switch pushed

myStepper.setSpeed(150);
myStepper.step(-stepsPerRevolution);}



while (digitalRead(buttonPin_START) == HIGH) {          // waiting for the start button being pushed

  }

while (digitalRead(buttonPin_UP) == HIGH){            // running (opening) barn door untill upper limit switch gets pushed

 
  if (digitalRead(buttonFAST) == LOW)                // change speed: increase with 0,1 RPM

    {
      Sp = Sp+0.1;
     delay(250); // waiting little bit...  
    }          

  if (digitalRead(buttonSLOW) == LOW)                 // change speed: decrease with 0,1 RPM
    {
     Sp = Sp-0.1;
     delay(250); // waiting little bit...  
    }            
 
myStepper.setSpeed(Sp);     //normal run
myStepper.step(stepsPerRevolution);}
delay(250);

for (int I=0; I <= 5; I++){                        // if upper position reached, blinking warn signal 5 times before running back to parking position
    digitalWrite(ledPin, HIGH);   // sets the LED on
    delay(500);                  // waits for a second
    digitalWrite(ledPin, LOW);    // sets the LED off
    delay(500);
   }

EEPROM.put(0,Sp);                              // writing value of speed variable into EEPROM in order to remember speed fine settings
delay(10);
}
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: mcnobby on Jun 22, 2016, 12:10 pm
Hollay, can you edit your post and put your code inside [ c o d e ] [ / c o d e ] tags, it makes it so much easier to read !
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: Hollay on Jun 22, 2016, 02:02 pm
Shure, thanks for hint.
Regards: Frigyes
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: rpt007 on Jun 22, 2016, 05:07 pm
@Hollay,

pls give us a bit more details about:
- your stepper motor (the same as headline says? I ask because the thread was started in 2011 ..)
- your stepper driver
- your power supply

If you are talking about having too less torque CW - it might depend on the speed.
There is a dependency between speed and torque.

As you are running CCW a bit faster than CW (you say, not fast enough - that may indicate driver/power supply/voltage issue) it seems that the motor at CCW speed has enough torque (or at least more than CW at low speed).

If you are operating your motor in a speed range, where torque is low, mightbe you need a gear reduction, so that the motor can run faster, but the resulting movement is still slow enough for your project.



Title: Re: 28BYJ-48 5-Volt Stepper
Post by: Hollay on Jun 22, 2016, 10:09 pm
Hi,
thanks for reply&help.

The motor is the same as in the headline. The driver board is a ULN2003 based tiny board (with 4 red leds), got in bundle from dx.com.
The power supply is a 240V AC/12V DC at 2A with stabilizer 7809 for the Nano and 7805 for the motor driver board. I guess it should be enough.

There should be 2 different speed values for the 2 directions.
The project has to have enough torque in the slow motion phase to run smooth with a camera on it and fast enough if parking back after exposure.
The motor is connected with a belt drive to the curved rod in order to avoid backlash btw. gears. The gear on the rod has to turn exactly with 1 RPM.
Just for information how a barn door tracker is looking like, here's an example (not mine): LINK (https://www.flickr.com/photos/128559914@N08/15294227659)
Thanks and regards:
Frigyes
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: rpt007 on Jun 23, 2016, 12:20 am
I am not familiar with your combination of driver and stepper.
What I found in the Internet, and if this information applies to your hardware:
Your motor needs 64 steps to make one 360 degree turn.

The integrated gear has a ration of 64:1, means that you have to send 64 * 64 = 4096 steps to have one full revolution. (Actually: 4076, see link below).

Compare that with your code:
Code: [Select]
const int stepsPerRevolution = 200;

So exchange the 200 with 4076 and test again.

Read the details in this link. (http://42bots.com/tutorials/28byj-48-stepper-motor-with-uln2003-driver-and-arduino-uno/)
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: Hollay on Jun 23, 2016, 08:56 am
Hmm, that sounds right.
I will test it on the weekend.
Thanks: Frigyes
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: rpt007 on Jun 24, 2016, 10:24 am
pls don't forget to leave a feedback here; EVEN when it works  :)
Disclosing a successful way to solve a problem will help to avoid repeating same kind of questions all over again and such waste precious free time on already solved issues.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: Hollay on Jun 26, 2016, 02:06 pm
Well, for the first look it seems to be worse. :(
I've set the value for 4076, but same time had to decrease speed (value: Sp). Now the torque is good at the minimum speed (1), but there's no more fine adjustment for speed as it seems not to take floating values (like Sp=0.9), only 1-7 as integer. I don't really understand why.
I've started a trial&error.
E.g. if I set the value for 1024, I have a speed range 1-25, which is way better in sense of fine tuning. Torque at Sp=1 seems to be OK, although highest speed is still not fast enough. If I set it higher, the motor makes only a high freq noise but not a single turn. :smiley-confuse:
I'm afraid the stepper library couldn't give me more...
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: rpt007 on Jun 26, 2016, 04:30 pm
As I have no such motors I cannot give it a try myself. Maybe somebody else here has the same configuration available and could give you a helping hand.
Alternative: look at another motor / driver combination which is in the range what you are looking for.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: Hollay on Jul 08, 2016, 10:44 pm
Ask again for help.
Using still the here already attached code I tried to change the small 28BYJ-48 on another unipolar stepper in order to get more torque. The config is the same: a Nano board with ULN2003 driver.

Tried e.g. a 42BYJ-07 (Syntha motor from a HEQ5 telescope mount) geared motor (as this is a 12V stepper, the ULN board gets 12V now).

The stepper is only vibrating, no matter in which sequence the coils are powered. Took an old unipolar motor from a 5,25" FD drive, same vibration W/o a single turn.

Tried another codes, not only stepper.h library but accelstepper too, same result.

What do I wrong? :(

Thanks for any answer.

Title: Re: 28BYJ-48 5-Volt Stepper
Post by: MAS3 on Jul 09, 2016, 11:15 pm
Hi.

If you need more torque, you need more current.
Is your driver able to supply the current the motors need ?

Do you have some specifications about those motors of yours ?
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: Hollay on Jul 10, 2016, 12:05 am
Hi,

I don't have any specs for those motors, sorry.
However torque is one issue in case of the 28BYJ, as it is just a tiny stepper. But my bigger problem is that the other steppers, like the 42BYJ-07 doesn't even make a single turn, just jumping a coil forward and another back (seems at least), that's I've written "vibrating". As if I would try to use it with a wrong coil sequence in the code. But tried all variations, no success.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: MAS3 on Jul 10, 2016, 01:16 am
If some current limiter kicks in, you might see a similar behaviour.

If you do not know the stall current, it's unlikely you will get it working correctly.

Try measuring voltages and currents, while you have some very slow stepping going on.
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: k4rma on Aug 02, 2016, 03:58 pm
I'm going to run an astronomical barn door tracker with Arduino nano.
I wrote a sketch, it works so far but I'm not really satisfied with it.
The basic idea is the following:
if powered up, it has to run down (CCW) in parking position. After pushing lower limit switch it has to wait for the START button. If start pressed, it has to turn CW very slow (as it has to follow Earth's turn) until upper limit switch pushed. If pushed, a blinking LED alerts to finish long time exposure.
There is a finetuning included to set +/- the CW speed (it has to be set up while taking long expo photos not to see lines instead of stars due to wrong speed). Speed is saved in Arduino's EEPROM.


Hi Hollay,

I happen to be on a similar issue with these little steppers. I tried SmallSteppers ans AccelSteppers as well, but both didnt really fit my needs.

The following simple example uses Timer1 with two steppers. Within the timed routine it will run the steppers to the position given by steps_X/Y_goto.

Code: [Select]


#include <TimerOne.h>

  byte stepper_sequence_clw[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};
  byte stepper_sequence_ccw[8] = {B00001, B00011, B00010, B00110, B00100, B01100, B01000, B01001};
  byte stepperX_spos,stepperY_spos,steps_X_step,steps_Y_step;
 
  byte stepperX_pins[4]={2,3,4,5}; //Stepper X digital pins D2...D5 blue pink yellow orange, ULN2003 1-4
  byte stepperY_pins[4]={6,7,8,9}; //Stepper Y digital pins D6...D9
  
  
  byte stepperX_delay = 0; //X stepper max speed
  byte stepperY_delay = 6; //Y stepper slow but with more torque
  
  long int steps_X_goto = 0;
  long int steps_Y_goto = 0;
  long int steps_X_pos = 0;
  long int steps_Y_pos = 0;

void setup(void) {

  for(int i=0;i<4;i++) pinMode(stepperX_pins[i],OUTPUT);
  for(int i=0;i<4;i++) pinMode(stepperY_pins[i],OUTPUT);
  stepperX_spos=0;
  stepperY_spos=0;
  steps_X_step=0;
  steps_Y_step=0;

  Timer1.initialize(1250) ; //max speed / lowest torque for 28BYJ

  Timer1.attachInterrupt(run_steppers);
  
}

void run_steppers(void){

    doSteps();
    //doBlinkLed or whatever
        
 }


void doSteps(){ //Do not use delay here as well as in the called funcs

    //having an endswitch it might be read here
    //if set, either let goto = pos or set goto = pos = 0
  
     if(steps_X_goto > steps_X_pos) doStepX(1,1);
     if(steps_X_goto < steps_X_pos) doStepX(1,0);  
  
    
     if(steps_Y_goto > steps_Y_pos) doStepY(1,1);
     if(steps_Y_goto < steps_Y_pos) doStepY(1,0);
  
      
  }

void doStepX(byte s_step, byte s_direction){
  if(!s_step) return;
  if(++steps_X_step < stepperX_delay) return;
  
  if(s_direction){
    if(++stepperX_spos>7) stepperX_spos=0;
    for(byte i=0;i<4;i++)
      digitalWrite(stepperX_pins[i],bitRead(stepper_sequence_ccw[stepperX_spos],i));
    steps_X_pos++;  
    } else {
    if(++stepperX_spos>7) stepperX_spos=0;
    for(byte i=0;i<4;i++)
      digitalWrite(stepperX_pins[i],bitRead(stepper_sequence_clw[stepperX_spos],i));
    steps_X_pos--;
    }
  steps_X_step = 0;
    
  }

void doStepY(byte s_step, byte s_direction){
  if(!s_step) return;
  if(++steps_Y_step < stepperY_delay) return;
  
  if(s_direction){
    if(++stepperY_spos>7) stepperY_spos=0;
    for(byte i=0;i<4;i++)
      digitalWrite(stepperY_pins[i],bitRead(stepper_sequence_ccw[stepperY_spos],i));
    steps_Y_pos++;
    
    } else {
    if(++stepperY_spos>7) stepperY_spos=0;
    for(byte i=0;i<4;i++)
      digitalWrite(stepperY_pins[i],bitRead(stepper_sequence_clw[stepperY_spos],i));
    steps_Y_pos--;
    }
 steps_Y_step=0;  
  }


 void loop(void) { //main loop, do non time critical things here


//set the steps to go

steps_X_goto = 4076;   //go 1 revolution clockwise
steps_Y_goto = -4076; //and 1 rev counterclockwise


delay(1); //always have a little bit of delay in here
}




The timed function is called every 1250us, resulting to 8k steps per second or 1kHz per cycle ("wave"). In my experiments this gives the stepper a quite decent turn rate leaving at least some torque. For more torque stepperX/Y_delay can be set as plain divider, using a delay of 10 will set the stepper to 100Hz as rated in its specs - which is really slow but should deliver the steppers max torque.

Beneath the timer interrupt and thus no need of using delay() in stepper control this example uses two different wave "signatures" for running back and forth to pick up the exact step in sequence instead of running the whole cycle before changing direction.  

Happy experimenting!

Regards, k4rma












Title: Re: 28BYJ-48 5-Volt Stepper
Post by: mun35 on Nov 24, 2016, 11:37 am
Does anyone know if the 28BYJ could be made to spin at 100RPM+? Or could one of its brothers/cousins go that fast?

Thanks
Title: Re: 28BYJ-48 5-Volt Stepper
Post by: jackever on Jan 11, 2017, 04:45 am
The darlington diagram has 2 of the diodes reversed .