Arduino Library – CustomStepper

library icon

Installatie van Arduino IDE libraries: Arduino info
arduino logo rond
Informatie (ENG):

CustomStepper is a library for controlling stepper motors. I’ve decided to make this library after having some troubles with my stepper motor and the regular Stepper library. It comes with functions to make the motor rotate a given number of times, a given angle (in degrees) or rotate until you send another command. I plan to use it to build an Arduino controlled CNC. The library default parameters are the ones of the 28BYJ-48 5-Volt stepper motor with 283712/4455 gear ratio I have.

Methods & Usage

CustomStepper (Constructor)

pin1-pin4
The constructor has from 4 to 8 parameters, the first 4 are mandatory, they are the 4 pins where the motor is connected at.

steps[]
The 5th parameter is the stepping sequence, which is an array, the 1st element is the number of steps in the sequence, it can be up to 8.

spr
The 6th parameter is the number of steps the motor takes per rotation (Note that if your motor is geared, the number of steps per rotation of the axis will be equal to the number of steps per rotation of the motor times the gear ratio). This parameter accepts float because there are some motors (like mine) with weird gear ratios that would translate in a non-integer number of spr.

rpm
The 7th parameter is self-explanatory, the motor RPMs. This parameter is also float in case you want to control the rotation more accurately, although it doesn’t have an 100% guaranteed precision because the time is controlled by microseconds which are of long time.

rotation
The 8th parameter is the rotation orientation, which can be one of the defined constants of the library: STOP, CW and CCW, the last two standing for clockwise and counterclockwise respectively.

The optional parameters defaults are the following:

CustomStepper(byte pin1, byte pin2, byte pin3, byte pin4, byte steps[] = (byte[]){8, B1000, B1100, B0100, B0110, B0010, B0011, B0001, B1001}, float spr = 4075.7728395, float rpm = 12, byte direction = CW);


setRPM
This method allows you to set the RPM of the motor, it must be greater than 0, if you want to stop the motor, use the setDirection(STOP). The type is float:

void setRPM(float RPM); 

setSPR
This method allows you to set the SPR (Steps Per Rotation of the motor, it must be greater than 0. The type is float.

void setSPR(float SPR);


Download @ playground.arduino.cc

[#/arduino/libraries/customstepper” ]