Pages: [1]   Go Down
Author Topic: 28BYJ-48 stepper  (Read 14155 times)
0 Members and 1 Guest are viewing this topic.
Pottstown, PA
Offline Offline
Sr. Member
****
Karma: 5
Posts: 318
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not working on any project. Simply fooling around with a 28BYJ-48 stepper motor and driver board I got very cheaply off of ebay. I have the motor mounted to the back of a piece of board with the output shaft protruding from the front of the boad and an arm attached to the output shaft. The the output shaft is attached a three inch arm. Imagine a clock. Using this code:

Code:
//Small Stepper Motor and Driver


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

/*-----( Declare Constants, Pin Numbers )-----*/
#define STEPS  100   //Number of steps per revolution


/*-----( 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, 8, 10, 9, 11);

int  Steps2Take = 0;

void setup(){   
}
void loop()   
{
  small_stepper.setSpeed(100);
  Steps2Take  = 2038;  // Rotate CW steps = 2058
  small_stepper.step(Steps2Take);
  delay(200);
}
/* --(end main loop )-- */

The arm swings around to what visually looks to be 360 degrees, pauses briefly, and repeats forever. I have marked where the arm stops. There is a brad sticking out of the end of the arm and the brad is close to the surface of the board so I can mark the stop position pretty accurately. After only a few minutes the brad is off from where it was originally marked. I have tweeked the number of Steps2Take by 2 but have not come up with the magic number that will make the arm stop consistently at the same place. Now I'm beginning to think that the stepper motor is not capable of being that exact. For instance is there an overrun in movement when it stops? Then I think of all the CNC machines that can provide absolute accuracy. Do they ramp down before stopping? Or have I just not found the magic number?

Another thing I wonder about is the Steps2Take for a 360 degree rotation. The spec sheet http://www.motionsolutions.us/motors/Stepper_Motors/Geared_Steppers/24_28_30BYJ.pdf says its 5.625 degrees per step for 64 steps per revolution of the stepper motor. The stepper drives reduction gears by a 1:64 ration. I come up with a total of 4096 steps per revolution of the out put shaft. More than double the number of steps I am using.

Any ideas, opinions? - Scotty
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 626
Posts: 34210
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Now I'm beginning to think that the stepper motor is not capable of being that exact.
Yes it is.

You are probably going too fast and the motor is missing a step or two. Slow things down and see if it helps.
Logged

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe speed, but you're only going 100.  4096 half steps.  2048 full steps.  Another possibility is that 2 of your wires are swapped incorrectly, this would cause it to skip some steps.  It should work the way you wish.  Did you see my code in this forum?
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Pottstown, PA
Offline Offline
Sr. Member
****
Karma: 5
Posts: 318
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Forgive me , Gentlemen. On significant point I left out is that the arm overshoots it's original stop point and I think it's safe to say that that overshoot occurs in every revolution. As suggested, I decreased the speed to 50; it didn't seem to make any difference as would be expected since you were thinking that the arm was falling short of the start point. I modified the code as follows to get a clear idea of what was going on . The truth table in the image below shows the results of the indicator leds A,B,C & D. Also in the image is the circuit wiring.



Here is the code:

Code:
//Small Stepper Motor and Driver


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

/*-----( Declare Constants, Pin Numbers )-----*/
#define STEPS  100   //Number of steps per revolution


/*-----( 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, 8, 10, 9, 11);

int  Steps2Take = 0;

void setup(){  
}
void loop()  
{
  small_stepper.setSpeed(2);
  Steps2Take  = 4;  // Rotate CW steps = 2058
  small_stepper.step(Steps2Take);
  delay(1000);
  
  //small_stepper.setSpeed(50);
  //Steps2Take  = 2038;  // Rotate CW steps = 2058
  //small_stepper.step(Steps2Take);
  //delay(200);
}
/* --(end main loop )-- */

Quote
Did you see my code in this forum?

I have seen some of your code using this stepper motor and a camera mount. Is that the code you refer to?

I see some other posts in that thread somenthing about the improved torque of this motor when using your code. From the data sheet I concluded a torque of about 4 in oz. Is that what can be expected?

Thanks for your replies Gentlemen. - Scotty
« Last Edit: April 13, 2012, 01:08:51 pm by scottyjr » Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 626
Posts: 34210
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is that what can be expected?
Not while you have LEDs in series with the motor winding.
It is probably that which is limiting the torque to the motor and causing it to skip.

Quote
I decreased the speed to 50; it didn't seem to make any difference as would be expected since you were thinking that the arm was falling short of the start point.
No you are skipping pulses, if it still happens at 50 try it even slower.
Logged

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Stepper2.pde has been well tested by now.  I don't see anything obvious wrong with your code.  Overshoot?  2058?  Those 2 words don't match.  If you need 2058 steps, that's more than 2048, then you would undershoot with 2048 steps.  That implies you are missing steps.  As if you were going too fast, which you are not.  When you hold the shaft it slips.  But you are not restricting it right?  I'm going to say something obvious here:  Something is wrong!  Hardware or software.  Try swapping 9,10 in the code just to see what would happen.  It only takes a second.  Here's how I would troubleshoot.  Go really slow, maybe 1 step/sec.  See if it hesitates or moves with even time intervals always in the same direction?

You can get nearly double the torque with 12v instead of 5v, at the expense of extra heat when running fast.
See code...

Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 626
Posts: 34210
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
at the expense of extra heat when running fast.
I think you mean extra heat when running slow. A stepping motor takes the most current when it is stopped, as it speeds up it takes less and less.

Quote
Not while you have LEDs in series with the motor winding.
I see you have now corrected the diagram, does this reflect what you actually have?
Logged

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, normally that would be a problem with a higher voltage supply.  But my code turns off the coils between steps, you choose the duty cycle.  The coolest of all for very slow speeds is when it's off the whole time between steps.  You cannot turn it off when you're running at full speed or there would be zero torque to the point where it can't run at all at that speed.  This motor is different from your traditional motor because of the gear box, and smaller steps than 1.8 deg.  If you turn a big motor off between steps even half the time it would go backward with any load at all.
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've been experimenting with the same motor and have noticed the exact same phenomenon.  It's commonly reported that these are 32 step motors with 64:1 gearing, but I have read another post were somebody opened up the motor and counted the teeth on the gears.  They reported (and I believe it based on my results) that the gearing ratio is not an integer.  This makes it impossibe (or at least exceedingly difficult) to use these motors as an sort of clock motor.  You can certainly use them in back-and-forth type of applications - they are intended to open and close ductwork.

edit: I found the discussion I was referencing above - read about halfway through the comments.
http://letsmakerobots.com/node/31381
« Last Edit: April 17, 2012, 09:46:03 am by mrbigbusiness » Logged

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I read the comments in the link.  I believe they are mistaken.  I have rotated the motor 1000 turns, each time 4096 steps, and it stops at the exact same place every time.  If there was an extra tooth, it would drift after 1000 revolutions.  You are doing something wrong.  You need to accelerate gradually at all but the slowest speeds even without a load.  It will skip steps if the load is variable.  You cannot go very fast using only 5v.  These are all potential problems you have to work around.  That is what my code is for!  It fixes most of these issues, depending on your physical setup.  Try it!  You should get EXACTLY 4096 half steps per revolution.  See my other thread here for more information. 

With my code, you can rotate 33.82 degrees.  An individual rotation might be off by 0.10, depending on your target number, but after 1000 moves of 33.82 degrees you can be sure it will have moved exactly 33820.0 degrees or 33820/360 revolutions.  That's because my code does Leap Steps.  Check it out.  Turning 30.0000 degrees is easy.
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Pottstown, PA
Offline Offline
Sr. Member
****
Karma: 5
Posts: 318
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I see you have now corrected the diagram, does this reflect what you actually have?
Yes, the current  diagram is now correct.

Quote
Overshoot?  2058?
The value 2058 is commented out in the code. The value I use for Steps2Take is 2038 and after a while it seems this value is too much since the arm begins to stop beyond the original start position. At first it seems to stop dead on but eventually it can be seen that the value of 2038 is higher than what is needed for 360 degree rotation. If I decrease the value to 2037 the arm, after only a few rotations can be seen to stop before its original start point.

Quote
But you are not restricting it right?
Right. The only load it has is the weight of the arm which is made from very light material.

Quote
No you are skipping pulses, if it still happens at 50 try it even slower.
How can it be skipping pulses if the arm goes too far?
A teacher tells John & Frank it takes children their size 120 steps to travel from the sliding board to the swingset. She instructs them both go to the sliding board and to walk 120 steps straight to the swingset. John begins walking but loses count at 79 and continues his count at 70. He finds himself beyond the swingset when he ends his 120 step walk since he has actually walked 130 steps. Frank takes the same walk but at count 59 he jumps to 70 and continues his count. At a count of 120 he finds himself short of the target because he 'skipped' steps 60-69. I am John.

I ran this motor for about 20 hours taking 1 step at a time at a speed of 1. After 2038 iterations of a loop (360 degree rotation) the count starts over. After 20 hours (66, 360 degree revolutions) The mark was right on. Changed Steps2Take to 2 and increased the speed to 10. After a few hours the arm is stopping about 3 degrees beyond its starting point. I did swap pins 9&10 as suggested but it didn't seem to make any difference.
Logged

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's confusing to me.  Swapping 9,10 should make a difference, without changing the code.  One way is right, one way is wrong.  It may not affect your total count, as you have observed, but it will not step in the right order, individual steps I mean.  This could lead to...

Skipping, ahead, not behind.

You don't have to go THAT slow. It takes too much time to do an experiment at that speed.

What surprises me is that you're so close to being correct.  I have seen a similar closeness when starting full speed and stopping without gradual accell.  It only misses a few steps at the beginning.  You case is different.  I don't understand your symptoms.  Try going at your speed of 1 and see if it takes tiny steps, equal size, equal time, all in the same direction.  Not jerky or uneven.

Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Pottstown, PA
Offline Offline
Sr. Member
****
Karma: 5
Posts: 318
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First, thanks for continuing to respond with help. I went back to a speed of 1 taking 1 step at a time in the loop. I checked the arm's movement with a magnifying glass. Can't say the movement is consistent. It does not move backward. The forward movements are regular in time but not in distance. I can't pick out a pattern. It seems random and I suspect this may be due to the slop between the gears. When you previously suggested switching pins 9 & 10, I switched them in the code. Is that ok? - Scotty
Logged

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sure, code or wires. One should be regular in distance. Switching them should not.  I don't know which order is correct.  There is no slop between gears.  It should move the same distance every time.  You''re on the right track looking at this. 
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Pottstown, PA
Offline Offline
Sr. Member
****
Karma: 5
Posts: 318
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I switched 9 & 10 again. The distance the arm moves is consistent now but it moves only on two of the four coil energizations (I think I just made a new word).

                          LEDA      LEDB      LEDC      LEDD
                            ON        ON         OFF        OFF   No movement
                           OFF        ON         ON         OFF   Arm moves
                           OFF       OFF         ON         ON    No movement
                            ON        OFF        OFF        ON    Arm moves


Gotta go to work. I'll check in later.

- Scotty
Logged

Pages: [1]   Go Up
Jump to: