Giter Club home page Giter Club logo

stepmot's Introduction

Arduino library for Stepper Motors

For all StepStick motor drivers with STEP/DIR interface

Features

this library:

  • allows you to drive your stepper motor very precisely and easy!
  • can compensate a backlash for geared motors!
  • saves your battery and protects the motor from overheating by using power saving mode!
  • supports A4899, DRV8825, LV8729, TMC2100/2208/2209

How to use

StepMot(float steps_per_revolution, uint8_t step_pin, uint8_t dir_pin, uint8_t en_pin);
void setMode(bool mode);            // ABSOLUTE or RELATIVE(default)
void autoPower(bool status);        // ON: auto power on by moving and power off if stopped. OFF: power is always on (default)
void setBacklash(float angle);      // set backlash angle and activate compensation
void setRPM(float rpm);             // set the speed in revolutions per minute
void enable();                      // power on 
void disable();                     // power off
void setDir(bool dir);              // clockwise CW or counterclockwise CCW
void invertDir(bool invertState);   // software direction inverting
void setSteps(uint32_t steps);      // moving by steps
void setAngle(float newAngle);      // moving by angle
void rotate(bool dir);              // rotating clockwise CW or counterclockwise CCW
void rotate();                      // set speed (RPM) and rotate. Positive speed -> clockwise, negative -> counterclockwise
float getAngle();                   // get the absolute actual position
void resetPos();                    // reset the actual position to 0
void step();                        // make one step
bool ready();                       // get status if target is reached
bool update();                      // this method drives the motor, so it must be called as often as possible. Returns true if the motor is moving and false otherwise

Example

#include "StepMot.h"

/* Example of using StepMot Library
 * read about another methods in StepMot.h
 */

#define STEPS_PER_REVOLUTION  2037.88642  // 28BYJ-48 geared stepper motor
#define MICROSTEPS            1          // 1 for full step, 2 for halfstep ...
#define STEP_PIN              16
#define DIR_PIN               10
#define EN_PIN                14

StepMot motor(STEPS_PER_REVOLUTION * MICROSTEPS, STEP_PIN, DIR_PIN, EN_PIN);

void setup() {
  Serial.begin(9600);
  motor.setMode(ABSOLUTE);  // set to ABSOLUTE or RELATIVE modes (default RELATIVE)
  motor.setRPM(10);        // speed in revolutions per minute
  motor.enable();         // power on the motor
}

void loop() {

  while (Serial.available() > 0){
    int angle = Serial.parseInt();
    motor.setAngle(angle);
  }

  if(motor.update()) Serial.println(motor.getAngle());

}       

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.