kvnal / uniStepMotor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Arduino Device Control Library

28BYJ-48 Stepper Motor (unipolar)

Allows Arduino boards to control a one or more of stepper motors.

This library can control one or more steppers both asynchronously and synchronously. It includes various state management methods for controlling multiple stepper motors individually, as well as methods for setting angles, revolutions, number of steps, and motor direction.


#### Releases To use this library, open the **Library Manager** in the Arduino IDE and install it from there. OR < < manual installation >>
  • 1.0.0 (latest)

Usage

To use this library:

#include<uniStepMotor.h>

Circuit diagram

img


1. Initiate Stepper Motor

UniStepMotor = myStepper(int IN1, int IN2, int IN3, int IN4);

Parameters : - mystepper: a object variable of type UniStepMotor : - IN1 - IN4: Arduino board pin connected from ULN2003 Driver Module's output PIN from IN1 - IN4.


2. Stepper motor 1 revolution steps configration (optional)

myStepper.configRevSteps(int no_of_steps_in_1_rev);

By default its configured at 4096 steps. How to calculate no. of steps in one revolution?


Methods

1. Full-Stepping BETA

To enable or disable full-stepping in stepper motor.

By default its configured as half-stepping at 4096 steps.

    myStepper.enableFullStepping(); // to enable
    myStepper.disableFullStepping(); // to disable

Note: No. of steps will be reduced to 1/2 of no. of steps it takes in half-stepping. i.e **by default: 2048 steps in one revolution

⚠ Note : full-stepping is currently in beta stage. i might not perform like its expected to be.

when to use? when you need speed and can compromise precision angle of the stepper.


2. Motor States

Get current state or control motor working using methods below.

In this library their are two types of motor states:

Start or Moving : denoted by int value 1

Stopped or paused : denoted by int value 0

Methods()

  • Get state of motor (moving or stopped)
  myStepper.getState()

Returns int value 1 : when motor is moving. int value 0 : when motor is not moving. It could be motor have completed its no. or steps of its state being stopped using setStateStop().


  • Set States of motor
  myStepper.setStateContinue() // to start motor
   myStepper.setStateStop() // to pause moving motor

3. Revolutions

Set no. of revolutions perform by the motor.

Methods()

  • set revolution

    myStepper.setRevolution(int no_of_Revolutions);
  • set revolution and put motor in continue state.

    myStepper.setRevolutionAndContinue(int no_of_Revolutions);
  • get number of revolutions left by the motor.

    myStepper.getRevolutionLeft();

    note: directions of motor will depend on the value in the arguments i.e -ve value will lead to counter-clockwise direction, while +ve will lead motor to clockwise direction. also, motor direction could be controlled dynamically by using Direction methods stated further in the documentation.


    Returns double (datatype value) : no of revolutions left is no_of_steps_left / no_of_steps_in_1_revolution.



4. Angle

Set angle in degree to perform by stepper motor.

Methods()

  • set angle
    myStepper.setAngle(int degree);
  • set angle and put motor in continue state.
    myStepper.setAngleAndContinue(int degree);
  • get no of degree left that needs to perfomed by the motor.
    myStepper.getAngleLeft();
    Returns no. of angle in degree left in double datatype from setAngle() or setAngleAndContinue().

5. Steps

Set steps to be perform by stepper motor.

Methods()

  • set steps
    myStepper.setSteps(int no_of_steps);
  • set steps and put motor in continue state.
    myStepper.setStepsAndContinue(int no_of_steps);
  • get no of Steps left that needs to perfomed by the motor. (Note : myStepper.getStepsLeft(); could be called (used) with revolutions or angle methods() too )
    myStepper.getStepsLeft();
    Returns int (datatype value)

6. Perform stepping (motion)

put stepper motor in to perfrom steps.

Consider it like a car: you must first insert the keys, rotate the key to start the engine, and then accelerate the cars using the paddle. Similarly, you must first set the angle/revolutions or steps to be performed by the stepper motor, then put the motor in a continuous state, and then take steps (it could be async or sync depending on the method you use below).

Methods()

  • Synchronous - Complete all the steps first. note: it stops the below code/sketch functionality.

    example:

  • Asynchronous - used when you need to perform other operations in the code/sketch as well.

  • Take steps example:

  • Take infinte steps. example:

all the async functions returns the state of the motor i.e 1 for continue state, 0 for stop/paused states

Example

get

 

7. Directions

Get or set stepper motor direction.

Methods()

  • set direction

    code.code();
  • get direction

    code.code();

    Returns return 1 : explain

7. Calculation helpers

perfrom various calculation using convertors provided it the library.

Methods()

  • degree to steps

    code.code();

    Returns return 1 : explain

  • steps to degree

    code.code();

    Returns return 1 : explain

Example

get

 

emergency stop - on pressing button stop motor change direction after one revolution working without stopping below code functionality working with two or more motors at same time start motor 2 steps after motor 1 completed its steps.

About


Languages

Language:C++ 100.0%