Coder Social home page Coder Social logo

arduinocontinuousstepper's People

Contributors

bblanchon avatar

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduinocontinuousstepper's Issues

Acceleration bug after reaching speed 0

Hello again

Please see this video, especially, the last 10 seconds :

https://mega.nz/file/dN8WVJpS#iqVkulLG6svWgDDNpjS3Bi8mxf5pNM9cFxXds1pblqI

As you can see, everytime the speed is 0, the stepper completely stops moving for a varying time, then it starts more abruptly than the acceleration setting. But if the speed was 1 or -1, there is no problem, it will accelerate normally. It's only happening when speed is exactly 0 !

And it seems to be only when it's decelerating but at the same time accelerating in the other direction. I mean, if I release the button until the speed is 0, and then I press the other button, there is no problem. No, I was wrong, it's happening as well, but it seems to be less noticeable.

I have no hardware to try IRL, but I really think this is a bug in your library

The code I used in the video is the example I posted earlier in another issue, you can try it yourself to confirm the bug :

https://wokwi.com/projects/345467092978369107

Edit: I tried to delete the stepper motor and driver from the simulation, just in case, but no change. Then I tried to remove Serial prints, still no luck. Finally, I also tried the exact same code on a real Arduino Mega, without stepper motor and driver as I don't have them yet, and the same problem is happening as well (I see it in the Serial monitor)

Edit: if you change to these values then the problem is much more noticeable:

const int16_t acceleration     = 10;
const int16_t deceleration     = 10;
const int16_t target_rpm       = 10;

Here is another video with these settings, it's very strange :

https://mega.nz/file/9YM1BDRD#bmpXZsL5sU0pnWvM8VV7ajMWKKhwXh5dy48R84IIR7c

Start and Stop buttons with Accel and Decel

Hey I'm new to this stuff and accelstepper was not intended for what I'm trying to do, glad you built this library but I can't figure out how to get smooth accel/decel with buttons, just wondering if you could post a simple example with just a Start button and Stop button with accel/decel for both, thanks!

Controlling stepper driver boards with multiple stepping options

HI,
On stepper driver boards with multiple stepping options (1/8th stepping, 1/16 stepping .....) and multiple pins to set those options, e.g the big easy stepper driver board, do the stepping option pins need to be set specifically by the controller (e.g. an Arduino) or is this completely handled internally by the continuous stepper library.

Regards,

Richard.

More than one stepper?

Hello,

I like this library. Is it possible to use with more than one motor at a time?

possible bug with teensyTimerTools

Am attempting to run as high a number of steppers on a single teensy3.x as practicable
need around 15000PPS max
trying teensyTimerTool example but no success

step output defaults to 499.75Hz
regardless of requested spin speed both positive and negative
except stepper.spin(0) where no output at all

is this a fault or incorrect usage

is there a better way to achieve objective?

TIA
Harry Harrison

Need a way to invert the logic state of the Enable pin

Hello,

Please could you add an option to invert the Enable pin

My problem is with A4988 driver, the Enable pin is active LOW so using powerOn() doesn't work because it's setting the pin HIGH :)

For now, a workaround is to not use the enablePin parameter in begin() and handle the pin manually

Do number of steps

Hi!
Is there any way to do a defined number of steps with your library?

Something like "step(30, 200)" for example. That would do 30 steps with a speed of 200.

I'm searching for a non-blocking library to do defined number of steps in continuous mode. Neither accelstepper or your library does that, right?

Best

Acceleration is bit abrupt

I am having issue with the abrupt change with the acceleration of the motor that is the frequency of the wave changes directly from 10 kHz to directly 30 or 40 kHz Can you please help me in that regard

problem with stop()

I have a problem with stop() .
When stepper.stop(); is executed, the motor stops abruptly and starts decelerating when the next stepper.loop(); is processed.

...
...
void loop() {
  if (Serial.available() > 0) {
    int rlen = Serial.readBytesUntil('\n', buffer, BUFFER_SIZE);
    String buf = buffer;
    if (rlen > 0) {
      if (buf.substring(0,rlen) == "stop") {
        stepper.stop();
        Serial.println("stop");
      } else if (buf.substring(0,rlen) == "start") {
        stepper.spin(500);
        Serial.println("start");
      }
    }
  }
  stepper.loop();
}

Use of PWM

First of all thank you for writing this nice library. It is exactly what I needed and it works beautifully on my Raspberry Pico with 3 steppers powered by TMC2209 drivers.

While working, I wondered if it is possible to use PWM with a variable frequency to drive the step input from my TMC2209 drivers. for this I found this library: https://github.com/khoih-prog/RP2040_PWM

Any micro controller with adjustable PWM frequency can be used but the Raspberry Pico is particularly good at it and offers 8 hardware PWM channels each with a frequency ranging from 7.5Hz to 120MHz (Yeah that is a bit fast lol)

It was easy enough to try and I can confirm it works. I simply used a duty cycle of 50% (Recommended by Trinamic) I am not aware of anyone who has even done this with PWM and I might find reasons why you would not want to do this. I thought maybe this idea is of some use to you.

#include <RP2040_PWM.h>

RP2040_PWM* stepper;
float frequency;
float dutyCycle;
#define STEP_PIN      8
#define DIR_PIN       9

void setup() {
  pinMode(DIR_PIN, OUTPUT);
  //  Create PWM object and passed just a random frequency of 500 in it
  //  The duty cycle is how you turn the motor on and off
  stepper = new RP2040_PWM(STEP_PIN, 500, 0);
}

void loop() {
  setSpeed(1000);
  delay(3000);
  setSpeed(-500);
  delay(3000);
}

void setSpeed(int speed){
  //  Set the frequency of the PWM output and a duty cycle of 50%
  digitalWrite(DIR_PIN, (speed < 0));
  stepper->setPWM(STEP_PIN, abs(speed), 50);  
}

Use the library without acceleration

Hello,

Is it possible to use the library without any acceleration? I can stop the nema by stepper.powerOff();, but I cannot start it without acceleration.

If I use high accelerations it goes fast but the stops with strange noises, so I'm stuck with using accelerations at the end, something that I'd like to eliminate.

This is my code:

// ----------------------------------------
// NEMA

#include <ContinuousStepper.h>

const int motor1_pdir = 2;
const int motor1_pstep = 3;
const int motor1_enable = 4;
const uint16_t potReadInterval = 1000;  // in milliseconds
int speed = 5000;
static unsigned long lastPotReadTime = 0;

ContinuousStepper<StepperDriver> stepper;

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

  // NEMA
  pinMode(motor1_pdir, OUTPUT);
  pinMode(motor1_pstep, OUTPUT);
  pinMode(motor1_enable, OUTPUT);

  stepper.begin(motor1_pstep, motor1_pdir);
  stepper.setAcceleration(1000); // higher than 1000, it stops before reaching the potReadInterval
  stepper.spin(speed);  // rotate at 200 steps per seconds
}

void loop() {
  unsigned long currentTime = millis();

  if (currentTime - lastPotReadTime >= potReadInterval) {
    speed = -speed;
    stepper.powerOff(); 
    stepper.powerOn(); 
    stepper.spin(speed);
    lastPotReadTime = currentTime;
  }

  stepper.loop();  // this function must be called as frequently as possible
}

So at higher accelerations it just stops after having reached the speed (or this is what I think to see), before reaching the millis interval.

EDIT:

Actually, when I am using a too high acceleration, I can see that it indeed accelerates faster, so it looks like a bug in the sense that the motor can accelerate at those speeds, but when it seems to reach the speed then it wrongly stops.

Basic example of using this with nema 17 esp2866 and l298n

Hi,
Thank you for creating this. Just wanted to asked if there is any way to explain how to connect nema17 to l298n and to esp2866 because I tried but motor is not moving . I tried using the basic example. code uploads successfully but the motor just vibrates. Thank you

Another problem with stop()

I am using the ToneExample on Arduino UNO which appears to have much smoother acceleration and deceleration over the BasicExample.
The circuit has a SPDT switch (ON-OFF-ON) which is being used to select, Left, Right or Stop.
If I only use stop(); in the else statement the stepper just continues to rotate. Only when I use spin(0); can I get the stepper to decelerate and stop. Do I have a coding issue or is there something else occurring?
ContinuousStepper_Left_Right_Stop.zip

Control two stepper motors

Hi, is it possible to control two stepper motors at the same time that go at two different speeds? If so, how can I do it?

How to implement the "void" functions like powerOn, powerOff, etc. into my Arduino code?

Dear Benoît,
many thanks for your swift reply!
Your "Arduino Continuous Stepper" lib fits perfectly to my project for soft start, stop and constantly run a Nema23 stepper motor attached to a M542C driver.
I intend to use a quite simple code with some push buttons to start, stop, change direction and increase/decrease the speed.
Finally a LCD display should show some figures but just, if the rest is running smooth and reliable.
As a processor I'm using the TEENSY LC. Actually I don't use any VOID commands and I hope that this will make my code more elegant and less timing critical because the motor don't speed up and run as smooth as it does with your example code.
Also if I set the speed to 0, speeding down sounds not as smooth as it should be.
What I would like to understand is how I have to implement the VOID commands in my code and how to link my push buttons to it?
Please find my actual code attached...!

Many thanks for your time and support and have a nice weekend.
Dirk

// TEENSY LC ARM Cortex-M0+ processor at 48 MHz, 62K Flash, 8K RAM
// Steppermotor StepperOnline 23HS30-2804S 1.9Nm, 2.8A
// Stepperdriver Leadshine M542C (Dips 1on, 2off, 3on, 4,5off, 6,7,8on)
// Button unbounce with ezButton
// Continuous Stepper library for smooth ramping and continuous run
// Function enableState to toggle between Start/Stopp with SafetySlowSpeed
// Function Direction to toggle between CW/CCW with SafetyLimit 
// Button counter the easy way
// LiquidCrystalDisplay 20col/4Row with I2C


//#include <Wire.h> 
//#include <LiquidCrystal_I2C.h>
#include <ezButton.h>
#include <ContinuousStepper.h>

//LiquidCrystal_I2C lcd(0x27,20,4);  // LCD address 0x27 (Pin SDA 18, SCL 19) 20 chars, 4 line display

// Defines pins numbers

const uint8_t stepPin = 8;
const uint8_t dirPin = 7;
const uint8_t enablePin = 4;
//const int stepPin = 8;                      // Steps signal to the driver
//const int dirPin = 7;                       // Direction signal to the driver
//const int enablePin = 4;                    // Enable signal to the driver
const int enableButton = 5;                 // Enable push button
const int dirButton = 6;                    // Direction push button
const int upButton = 9;                     // Speed up push button
const int downButton = 10;                  // Speed down push button
ezButton changeDir(dirButton);              // Direction push button debounce
ezButton enableMot(enableButton);           // Enable push button debounce
ezButton speedupButton(upButton);           // Speed up push button debounce
ezButton speeddownButton(downButton);       // Speed down push button debounce
ContinuousStepper stepper(stepPin, dirPin, enablePin);

int customDelay; // Defines variables
int intervalBetweenSteps = 200;             // 200
int buttonPushCounter = 0;                  // counter for the number of button presses
int buttonStateUp = 0;                      // current state of the button Up
int lastButtonStateUp = 0;                  // previous state of the button Up
int buttonStateDown = 0;                    // current state of the button Down
int lastButtonStateDown = 0;                // previous state of the button Down
int rampVal = 1000;                           // Ramp value for Speed
int enableState = LOW;                      // the current state of the ENABLE Signal
int dirState = LOW;                         // the current state of the DIR Signal
int speedSet = 0;

 
void setup() {
 Serial.begin(9600);
  
  // Sets the pins as Outputs/Inputs
  pinMode(stepPin,OUTPUT);                   // set arduino pin to output for steps
  pinMode(dirPin,OUTPUT);                    // set arduino pin to output for direction
  pinMode(enablePin,OUTPUT);                 // set arduino pin to output for motor enable
  pinMode(enableButton, INPUT_PULLDOWN);     // set arduino pin to input pull-down mode
  pinMode(dirButton,INPUT_PULLDOWN);         // set arduino pin to input pull-down mode
  pinMode(upButton,INPUT_PULLDOWN);          // set arduino pin to input pull-down mode
  pinMode(downButton,INPUT_PULLDOWN);        // set arduino pin to input pull-down mode

  changeDir.setDebounceTime(50);
  enableMot.setDebounceTime(50);
  speedupButton.setDebounceTime(50);
  speeddownButton.setDebounceTime(50);
 
  digitalWrite(enablePin,LOW); //Disables motor

/* 
    lcd.init();                                // initialize the lcd 
    lcd.init();
    Print a static message to the LCD.
    lcd.backlight();
    lcd.setCursor(0,0);
    lcd.print("Smoothing Roller DSC");
    lcd.setCursor(0,1);
    lcd.print("Actual Speed:");
    lcd.setCursor(0,2);
    lcd.print("Direction:");
    lcd.setCursor(0,3);
    lcd.print("Status:");

  //stepper.spin(speedSet);
*/
  
}
void loop() {
  
  changeDir.loop();                           // start debounce
  enableMot.loop();                           // start debounce
  speedupButton.loop();                       // start debounce
  speeddownButton.loop();                     // start debounce
  stepper.loop();

  //speedSet = buttonPushCounter * rampVal;               // calculate the speed with pushButtonCounter * rampVal
  //stepper.spin(speedSet);



  Serial.print(F("SPEED = "));
  Serial.println(speedSet);
  Serial.print(F("OUT = "));
  Serial.println(buttonPushCounter);

  // --------------------------------------------------------------------
  // Up button counter
  // --------------------------------------------------------------------
  
  if(speedupButton.isPressed())
      buttonPushCounter++; 
     
     if (buttonPushCounter > 16)  // Max. Speed Limiter  
        buttonPushCounter = 16;
      

  // --------------------------------------------------------------------
  // Down button counter
  // --------------------------------------------------------------------
{  
   if(speeddownButton.isPressed())
      buttonPushCounter--;
   
    if (buttonPushCounter < 1)  // Min. Speed limiter   
           buttonPushCounter = 0;
      
   
}  
/*
    if ((changeDir.isPressed()) && (buttonPushCounter < 5)) {  // direction push button active at speed < 5 to protect the motor
    // toggle state of DIR
    dirState = !dirState;
    // control EnablePin arccoding to the toggled state
    digitalWrite(dirPin, dirState);                            // write signal to direction pin
    }
 */   
    if (enableMot.isPressed()) {                               // enable push button always active even for emergency stop
    // toggle state of ENABLE
    enableState = !enableState;
    // control EnablePin arccoding to the toggled state
    //  digitalWrite(enablePin, enableState);  // write signal to enable pin
     }  
    
      if (enableState == HIGH) {                              // if motor disabled, set Push button counter to min
          buttonPushCounter = 0;
  }

    speedSet = buttonPushCounter * rampVal;                   // calculate the speed with pushButtonCounter * rampVal
    stepper.spin(speedSet);
  
}

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.