thanks a lot for the hint. The voltage is fine. I am able to reach max speed with the simple TimerOne function. But here i am not able to use a acceleration. Thats way I want to use ContinuousStepper.
Thank you a lot for the tips and the code. I tested it in wokwi and in reality. I figured out that it is working fine until a special point. In Simulation and in reality it's the same.
My setup in wokwi:
Gear ratio of the stepper 4:1. That's the same as in reality.
It´s always the same. The motor accelerates until a speed, wich is rougthly 1/4 of full speed. I did let the code proceed this time, untill max speed was reached. Here is the intresting part.
The motor accelerates in the first seconds as expacted. Then it holdes the speed for some time. If the accaleration reaches the max speed, the motor suddenly jumps to max speed. So not the datatype is the Problem, but it seems to be something with the acceleration function?
I added a higher acceleration in the code above, so you can see the phenomen within some seconds, and don´t have to wait for a long time.
@BenoitB is it possible that something in the acc function overflows with such a huge speed value?
This sure sounds like a bug (probably an overflow) in the library.
I cannot address it right away, so I'd be very grateful if you could open an issue on GitHub.
Please include the above message in the issue description.
We'll continue the conversation from there.
Thanks!
i'm interested, thanks for making this. I like continous rotation at a slow speed with stepper motors but I would also like the acceleration feature you made.
I have a couple of uln2003 drivers with small steppers. Does your library also work with these driver boards? And how to connect/program? Your examples only use 2 pins if I'm correct, this driverboard has 4.
Thanks in advance!
The library only supports stepper drivers with two pins (DIR, STEP).
I'm willing to add support for four pins drivers, but I don't have the hardware.
Could you recommend a breakout board and a small stepper to go with it?
Preferably something that doesn't need soldering since I'll do all my tests on a desk.
This gives an error, even if you add the include and define the pins:
#include <ContinuousStepper.h>
const byte stepPin = 2, dirPin=3;
ContinuousStepper stepper(stepPin, dirPin);
void setup() {
stepper.spin(200); // rotate at 200 steps per seconds
}
void loop() {
stepper.loop(); // this function must be called as frequently as possible
}
Error:
sketch.ino:5:42: error: no matching function for call to 'ArduinoContinuousStepper::ContinuousStepper::ContinuousStepper(const byte&, const byte&)'
ContinuousStepper stepper(stepPin, dirPin);
^
In file included from sketch.ino:1:0:
/libraries/ContinuousStepper/src/ContinuousStepper.h:6:7: note: candidate: ArduinoContinuousStepper::ContinuousStepper::ContinuousStepper()
class ContinuousStepper : public ContinuousStepperBase {
^~~~~~~~~~~~~~~~~
/libraries/ContinuousStepper/src/ContinuousStepper.h:6:7: note: candidate expects 0 arguments, 2 provided
/libraries/ContinuousStepper/src/ContinuousStepper.h:6:7: note: candidate: constexpr ArduinoContinuousStepper::ContinuousStepper::ContinuousStepper(const ArduinoContinuousStepper::ContinuousStepper&)
/libraries/ContinuousStepper/src/ContinuousStepper.h:6:7: note: candidate expects 1 argument, 2 provided
/libraries/ContinuousStepper/src/ContinuousStepper.h:6:7: note: candidate: constexpr ArduinoContinuousStepper::ContinuousStepper::ContinuousStepper(ArduinoContinuousStepper::ContinuousStepper&&)
/libraries/ContinuousStepper/src/ContinuousStepper.h:6:7: note: candidate expects 1 argument, 2 provided
Error during build: exit status 1
You can work around it by initializing with .begin() in setup() like:
#include <ContinuousStepper.h>
const byte stepPin = 2, dirPin = 3;
ContinuousStepper stepper;
void setup() {
stepper.begin(stepPin, dirPin);
stepper.spin(200); // rotate at 200 steps per seconds
}
void loop() {
stepper.loop(); // this function must be called as frequently as possible
}
I am working on an inverted pendulum project with stepper motor. It seems like this library can help me a lot!
My initial idea is that my control loop can adjust the speed (or steps?) of the motor continuously.
#include <ContinuousStepper.h>
const byte stepPin = 2, dirPin = 3;
ContinuousStepper stepper;
void setup() {
stepper.begin(stepPin, dirPin);
}
void loop() {
readingsFromSensors;
u = controlAlgorithm(readingsFromSensors); //the speed and direction of the motor?
stepper.spin(u);
stepper.loop(); // this function must be called as frequently as possible
}
Above is the pseudocode of my initial thoughts. How should I write the stepper control? Should I write in this way? Thanks!
@cornnatron, if you need an "emergency stop", you can call powerOff().
Alternatively, you could also change the acceleration right before calling stop().
@Shumie, I finally published version 3 of the library!
As promised, this version supports four-wire stepper motors such as the 28BYJ-48 with the ULN2003.
Unfortunately, this new feature comes with a little breaking change: ContinuousStepper is now a template class with the stepper type as the first template argument.
// For a stepper driver with STEP and DIR pins
ContinuousSteppper<StepperDriver> stepper;
// For a four-wire stepper
ContinuousSteppper<FourWireStepper> stepper;
There is also a second template argument that allows you to use a timer library or a PWM pin; please check the README for details.
Is is possible to have the speed changing inside the loop, for example:
void loop() {
//do something here
//u is the output some algorithms
stepper.spin(u); //u can be different every loop
stepper.loop(); // this function must be called as frequently as possible
}
Or do I have to do:
void loop() {
//do something here
//u is the output some algorithms
while (!stepper.isSpinning()) {
stepper.spin(u); //u can be different every loop
}
stepper.loop(); // this function must be called as frequently as possible
}
have you tried ?
my understanding is that the library will go to the new speed through an acceleration / deceleration algorithm so it won't be an instant change but I see no reason why it would not work. There is probably mechanical inertia anyway so may be you should only change the speed every 10 seconds or something.
void loop() {
static uint32_t lastChange;
if (millis() - lastChange >= 10000ul) { // every 10s calculate a new speed if necessary
//do something here
//u is the output some algorithms
stepper.spin(u); //u can be different every loop
lastChange = millis();
}
stepper.loop(); // this function must be called as frequently as possible
}
I installed everything correctly, but problem was with extensions.
In code is #include <ContinuousStepper/Tickers/Tone.h>
in library is tepper-/ContinuousStepper/Tickers/Tone.hpp