Go Down

Topic: new Arduino library: CheapStepper - made for the cheap 28BYJ-48 stepper motor (Read 2274 times) previous topic - next topic

tylerrr

I created a new library for the 28BYJ-48 Stepper motor (with ULN2003 driver board) and wanted to share it with you all:

https://github.com/tyhenry/CheapStepper  (It's also available on the Arduino Library Manager)


The 28BYJ-48 stepper motor is readily available and very inexpensive - yet quite decent for the money.

The library uses 8-phase half-stepping to give 4096 discrete (mini-)steps per shaft rotation for precise control.

The total steps per rotation is also adjustable :

  • the motor has an advertised 64:1 gear ratio but it has been measured as being 63.68395:1, which would give ~4076 steps per shaft rotation. 
  • you can also adjust this value to account for external gear ratios
    (e.g. if you are controlling a turntable with 1:4 motor:turntable gearing, change total steps to [4096*4=] 16384 steps, and then your motor control - rpm, degrees, etc. - will match your turntable)


The library allows you to:
 
control the stepping directly (CheapStepper::step()) or

use blocking moves (CheapStepper:move()) - i.e. sketch will "pause" - or

use non-blocking moves (CheapStepper::newMove() and CheapStepper:run()) - i.e. moves will be timed to occur across loop() iterations

More info is available on the GitHub repo and in the library code (fully commented!)

This is my first Arduino library, so I'm happy to receive feedback or pull requests!

Roadmap:
- adjustable voltage input (right now calcs are based on 5v)
- acceleration/de-accelaration
- easier external gear ratio adjustment


I'm using this library right now to build a 3D scanner and it's working quite well :)



Sblue_Flyhouse

Although, now that I'm playing with it, I can't seem to declare the stepper on other pins. Is there something inherent in the library that forces the use of pins 8, 9, 10, and 11?

jfmateos


PaulS

Quote
This is my first Arduino library, so I'm happy to receive feedback
Your constructor is setting the mode of the pins before the hardware is ready. Not a good idea.

Your class needs a begin() method, where the pinMode() calls should be made. The begin() method should be called in setup().
The art of getting good answers lies in asking good questions.

r0q

Thanks a lot! couldn't make it work on different pins. add begin() method to set pin modes - now its working!

Munsty

I also want to use this library on different pins. With my level of expertise I cannot figure out from the description above what code I have to add to make this work.

Could someone give an example?

Munsty

I asked a friend for help. He has no Arduino experience, but a lot of programming skills. Not sure if this the best solution, but I did the following and that worked.


instead of in CheapStepper.cpp:

CheapStepper::CheapStepper () {
    for (int pin=0; pin<4; pin++){
        pinMode(pins[pin], OUTPUT);
    }
}

write this:

CheapStepper::CheapStepper () {
}

void CheapStepper::begin () {
    for (int pin=0; pin<4; pin++){
        pinMode(pins[pin], OUTPUT);
    }
}


in CheapStepper.h add :

void begin(); // sets pins to output

above the line :

void setRpm (int rpm); // sets speed (10-24 rpm, hi-low torque)

And finally I added in setup():

stepper.begin();

After that it worked.

Go Up