Giter VIP home page Giter VIP logo

stepper's Introduction

Stepper Library for Arduino

Check Arduino status Compile Examples status Spell Check status

This library allows you to control unipolar or bipolar stepper motors. To use it you will need a stepper motor, and the appropriate hardware to control it.

For more information about this library please visit us at http://www.arduino.cc/en/Reference/Stepper

License

Copyright (c) Arduino LLC. All right reserved. Copyright (c) Sebastian Gassner. All right reserved. Copyright (c) Noah Shibley. All right reserved.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

stepper's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stepper's Issues

Dynamically control speed

Is it possible to control the speed of a stepper motor with an a4988 driver dynamically? I would like to realize a control system on an arduino, using speed and not position control.
Thanks in advance!

Avoid microsecond drift in step timing

The > condition here can allow extra uSeconds of time to creep in to the stepping:

this->last_step_time = now;

Since the condition to advance a step is >=, the result will be fewer steps than expected, in a given time frame.

This can be fixed by changing Stepper.cpp:201 to:

this->last_step_time += this->step_delay;

Argument for the existing code: that if the processor gets bogged down, the motors will step slower, and guarantee step counts. But, everything slows down.

Argument for updating the code: start to finish timing stays correct, but as the processor bogs down, it can lose steps at higher speeds.

Thank you for your attention to this detail.
Gerald Lafreniere

Update to Stepper library [imported]

From @cmaglie on November 15, 2012 18:19

This is Issue 144 moved from a Google Code project.
Added by 2009-11-19T00:38:14.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.

Original labels: Type-Enhancement, Priority-Medium

Original description

If the stepper doesn't complete a full resolution or goes for long periods of
time between steps or steps over a long period of time, it gets really hot
due to a bug in the stepper code. It leaves coils enegized. I have added a
motorOff() function that shuts off all power so that it will not become too
hot. Future development could be to insert a timer since we know the speed
and step degree and shut it off that way.

Copied from original issue: arduino/Arduino#144

ESP8266 Software reset

Hey there!

I am currently using a WEMOS D1 mini together with a 4-Pin stepper motor.
It works correctly but after turning it, the esp runs through a software reset.

The Exception Decoder says the following:

0x402016a4: Stepper::stepMotor(int) at D:\Arduino\libraries\Stepper\src\Stepper.cpp line 356
0x402016df: Stepper::step(int) at D:\Arduino\libraries\Stepper\src\Stepper.cpp line 198

My code looks like this:

#include <NTPClient.h>
#include <Stepper.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

// wifi settings
const char *ssid     = "Martin Router King";
const char *password = "<secret password here>";

// ntp settings
const long utcOffsetInSeconds = 3600;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);

// stepper settings
Stepper Motor(2048, D1, D3, D2, D4);

void setup(){
  Serial.begin(115200);

  // wifi
  WiFi.begin(ssid, password);
  while ( WiFi.status() != WL_CONNECTED ) {
    delay ( 500 );
    Serial.print ( "." );
  }
  Serial.println("Connected!");

  // ntp
  timeClient.begin();

  // stepper
  Motor.setSpeed(10);
}

void loop() {
  timeClient.update();

  int currentHour = timeClient.getHours();

  if(currentHour % 12 == 0 && timeClient.getMinutes() == 6 && timeClient.getSeconds() == 0){
    Serial.println("Liftoff!");
    Motor.step(2048);
  }
  delay(1000);
}

The stepper motor is connected as follows:
IN1 -> D4
IN2 -> D3
IN3 -> D2
IN4 -> D1

As I said, it works and rotates but after its done my esp resets :/

Also I couldn't find any issue in the Stepper.cpp/Stepper.h (for my low experience level with C++).

EDIT: I tried using only the stepper motor without any NTP or anything else, it keeps resetting.

Stepper class does not initialize step_delay which can lead to lock-ups

Moved from arduino/Arduino#3300 by @cxrodgers

I was having an intermittent issue where my arduino would occasionally lock up while stepping a stepper. It turned out that it was because I had neglected to call setSpeed explicitly. I had thought that it defaulted to some reasonable value, but upon examining the code, I see that it does not, meaning that step_delay will be whatever random value resides in that memory location.
https://github.com/arduino/Arduino/blob/master/libraries/Stepper/src/Stepper.cpp

Here was my forum posting on this topic.
http://forum.arduino.cc/index.php?topic=327132.0

I believe that the memory is typically set to zero, but when using dynamic memory allocation (for instance: stepper = new Stepper(...), there is no guarantee that this memory location will start at zero. Regardless, it seems dangerous to rely on the memory containing any particular value without being initialized.

I think step_delay should be initialized to zero in the constructor. Alternatively, I think it should be documented that a call to setSpeed is required before calling step.

Multiple stepper motor delay

Hello, when using multiple stepper motors they don't work at the same time they work one by one, due to while loop used in the code.

#include <Stepper.h>

const int spr = 200;  // change this to fit the number of steps per revolution
const int rmp = 100;
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper sm1(spr, 52, 50, 48, 46);
Stepper sm2(spr, 44, 42, 40, 38);
Stepper sm3(spr, 36, 34, 32, 30);
Stepper sm4(spr, 28, 26, 24, 22);




void setup() {
  // set the speed at 60 rpm:
  sm1.setSpeed(rmp);
  sm2.setSpeed(rmp);
  sm3.setSpeed(rmp);
  sm4.setSpeed(rmp);
  Serial.begin(9600);

  //  myStepper.step(stepsPerRevolution);
}

void loop() {
  // step one revolution  in one direction:
  Serial.println("clockwise");
  sm1.step(spr);
  sm2.step(spr);
  sm3.step(spr);
  sm4.step(spr);

}

when m1 finished its first loop then m2 starts and it goes on.

Please change the while loop with some async loop which will allow other stepper motors to start simultaneously.

Change data type of step() parameter to `long`

Hello.
My Arduino Uno board cannot handle steps_to_move bigger than 32767 which is the maximum of 16bits integer.
This was simply solved by modifying the int in below two lines to long.
I would like to modify the parts below so that we can use a wider range of step numbers without changing the board.
Is there any reason that we have to use int datatype instead of long datatype?

void Stepper::step(int steps_to_move)

int steps_left = abs(steps_to_move); // how many steps to take

Document the 2-wire mode as a A/B Quadrature output

Per

Stepper/src/Stepper.h

Lines 36 to 39 in 4068b93

* A slightly modified circuit around a Darlington transistor array or an
* L293 H-bridge connects to only 2 microcontroller pins, inverts the signals
* received, and delivers the 4 (2 plus 2 inverted ones) output signals
* required for driving a stepper motor. Similarly the Arduino motor shield's

and

Stepper/src/Stepper.h

Lines 58 to 71 in 4068b93

* Step C0 C1 C2 C3
* 1 1 0 1 0
* 2 0 1 1 0
* 3 0 1 0 1
* 4 1 0 0 1
*
* The sequence of control signals for 2 control wires is as follows
* (columns C1 and C2 from above):
*
* Step C0 C1
* 1 0 1
* 2 1 1
* 3 1 0
* 4 0 0

Some modified H-bridge drivers and high-end configurable stepper drivers can use the 2-wire C0/C1 A/B Quadrature output from this constructor:

Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2);

The TI L293x datasheet (pg 9) shows this circuit for how to wire it up with some inverters to use two signals to drive 2-phase quadrature input:

image

and

image

Half-steps in stepper library for 4-wire motors [imported]

From @cmaglie on November 15, 2012 18:19

This is Issue 139 moved from a Google Code project.
Added by 2009-11-05T07:28:01.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.

Original labels: Type-Enhancement, Priority-Medium

Original description

Using a half-step-library would double the precision of the stepper.

Attached you'll find my proposal for the changed Stepper library. I kept
the changes to a minimum.
It contains a new (added) constructor, a private boolean which indicates
whether or not to use the half-step system. The Stepper::step function was
changed to allow 2, 4, or 8 steps and the Stepper::stepMotor was changed
to send the 8 different signals to the 4 wires.

Users who created sketches using the previous lib can change to this new
library without compatibility problems.

Copied from original issue: arduino/Arduino#139

Small notation error in comment.

Hi!
It's nothing serious but I got a little distracted in my work rechecking how micro() worked because of it.

So just to let you know that in line 105 in "Stepper.h", the comment says "// delay between steps, in ms, based on speed".
"ms" is short for millisecond, the correct abbreviation for microsecond is "µs" or for easier typing "us".

Reference:
https://simple.wikipedia.org/wiki/Second

Thank you for your time!

How stop the motor

Hi, I use this library and I would like to know if I can make a forced stop of the engine.

counter clockwise only work if swap pin at myStepper()

#include <Stepper.h>

const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); # works clockwise
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11); # works counter-clockwise

void setup() {
  Serial.begin(9600);
}

void loop() {
  // Movendo o motor para frente
  for (int i = 0; i < 200; i++) {
    myStepper.step(15);
    delay(10);
  }
  delay(2000);
  // Movendo o motor para trás
  for (int i = 0; i < 200; i++) {
    myStepper.step(-15); // negative value do not turn the motor counter-cockwise
    delay(10);
  }
  delay(2000);
}

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.