Arduino library · Motion

GyverStepper: an example that runs

Yes. You can use the GyverStepper library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (Stepper motor, 28BYJ-48 with ULN2003). The example below, "An eighth of a turn of a 28BYJ-48 with GyverStepper", runs on the Arduino Uno R3.

Built in on Mokxi: #include <GyverStepper.h> and it builds, with nothing to install. Free, and no account needed.

What GyverStepper does

GStepper<STEPPER2WIRE> on a STEP/DIR driver or <STEPPER4WIRE> on four coil pins: tick() from loop(), FOLLOW_POS to setTarget() with setMaxSpeed() and setAcceleration(), KEEP_SPEED with setSpeed(), stop(), brake(), autoPower() and the degree calls. That is what GyverStepper, by AlexGyver, covers. The sketch below uses it on the Arduino Uno: “An eighth of a turn of a 28BYJ-48 with GyverStepper”.

AlexGyver's GyverStepper library (GStepper), a stepper on a STEP/DIR driver or four coil pins that follows a position with acceleration or holds a speed, moved by tick() from loop().

Simulated, on the a4988 part with a NEMA 17 and on the 28BYJ-48's ULN2003 board. SMOOTH_ALGORITHM, upstream's other planner, is accepted and plans as the default one does.

The calls follow release 2.7.3 of the library, so a sketch written here builds on a real board too. The example is the one Mokxi's own tests build and run, so what is printed here is what runs.

Library Manager nameGyverStepper
AuthorAlexGyver
Include#include <GyverStepper.h>
Boardsevery board Mokxi compiles for but ATtiny85
In the simulatorSimulated: it runs against the part the way it does on the bench.
Parts it drivesStepper motor, 28BYJ-48 with ULN2003, Stepper driver, A4988, Stepper motor, NEMA 17

Install it

It builds on every board Mokxi compiles for but ATtiny85.

In Mokxi it is built in: #include <GyverStepper.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "GyverStepper" by AlexGyver from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add GyverStepper to lib_deps in PlatformIO. Mokxi follows the calls of release 2.7.3, so a sketch written here builds there too.

What to know in the simulator: Not listed for the ATtiny85: the float planner and a Serial print overflow its 8 KB. SMOOTH_ALGORITHM plans as the default planner does. GyverStepper2.h and the GPlanner multi-axis planners are not here.

The calls you will use

In the order a sketch meets them.

GStepper<STEPPER4WIRE> stepper(2048, 11, 9, 10, 8)

Makes stepper, the GStepper object the calls below are made on.

stepper.setRunMode(FOLLOW_POS)

Sets the run mode to the value you pass in.

stepper.setMaxSpeed(400)

Sets the max speed to the value you pass in. Arguments: speed.

stepper.setAcceleration(800)

Sets the acceleration to the value you pass in. Arguments: accel.

stepper.setTarget(256)

Sets the target to the value you pass in.

stepper.getCurrent()

Returns the current as a whole number.

stepper.getCurrentDeg()

Returns the current deg as a decimal number.

Example: An eighth of a turn of a 28BYJ-48 with GyverStepper

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3
#include <GyverStepper.h>

// The ULN2003 board's IN1 to IN4 go in as IN4, IN2, IN3, IN1, as upstream's demo says.
GStepper<STEPPER4WIRE> stepper(2048, 11, 9, 10, 8);

void setup() {
  Serial.begin(115200);
  stepper.setRunMode(FOLLOW_POS);  // follow the target position
  stepper.setMaxSpeed(400);        // steps a second
  stepper.setAcceleration(800);    // steps a second, a second
  stepper.autoPower(true);         // coils off at the target
  stepper.setTarget(256);          // an eighth of 2048 steps
  while (stepper.tick()) {
  }
  Serial.print("at ");
  Serial.print(stepper.getCurrent());
  Serial.print(" steps, ");
  Serial.print(stepper.getCurrentDeg(), 1);
  Serial.println(" deg");
}

void loop() {}

Wiring

  • Arduino Uno R3 8 to Stepper motor, 28BYJ-48 with ULN2003 IN1
  • Arduino Uno R3 9 to Stepper motor, 28BYJ-48 with ULN2003 IN2
  • Arduino Uno R3 10 to Stepper motor, 28BYJ-48 with ULN2003 IN3
  • Arduino Uno R3 11 to Stepper motor, 28BYJ-48 with ULN2003 IN4
  • Arduino Uno R3 5V to Stepper motor, 28BYJ-48 with ULN2003 VCC
  • Arduino Uno R3 GND to Stepper motor, 28BYJ-48 with ULN2003 GND

Open it in the editor, wired and ready to run

Try GyverStepper without installing anything

Open the example, change the sketch, and keep your version in a free account.