Astepper1.setMaxSpeed(50); Astepper1.setSpeed(50); Hello,Thank you very much for your answers!As mentioned by Gregor, adding the setMaxSpeed function solved the problem.Under the Arduino IDE examples, several codes for steppers at constant speed include the line, but it’s unfortunately missing in the one I’ve chosen, under « Adafruit Motor Shield V2 »…Sorry for this.Once this problem has been solved, and as mentioned in my previous post, I had to raise the I2C clock speed in order to see my stepper reaching higher speeds.However, I’m still facing some problems with this..First, with OS Sierra, editing the twi.h file to change the I2C speed has no effect. Apparently, the Arduino IDE doesn’t seem able to find the path of the file, or to read it, I don’t really know…Therefore, adding the line dedicated to this in the code is the only way to change the bus speed.
Wire.setClock(400000L);As I’ve experienced by raising the constant speed of my stepper, a too low I2C speed has different effects depending of the step type chosen: with the SINGLE type, the stepper is subject to jitter, while with DOUBLE or INTERLEAVE (with adapted values), the speed of the stepper is lower than the one set.
In my case, raising the I2C speed works to solve this, unless the stepper speed is raised too much, or is subject to acceleration.I’m now trying to work with this simple code:#include <Wire.h>#include <AccelStepper.h>#include <Adafruit_MotorShield.h>Adafruit_MotorShield AFMS = Adafruit_MotorShield();Adafruit_StepperMotor *myStepper1 = AFMS.getStepper(200, 2);void forwardstep1(){myStepper1->onestep(FORWARD, DOUBLE);}void backwardstep1(){myStepper1->onestep(BACKWARD, DOUBLE);}AccelStepper stepper1(forwardstep1, backwardstep1);void setup(){AFMS.begin();TWBR = ((F_CPU /400000L) - 16) / 2;stepper1.setMaxSpeed(500);stepper1.setAcceleration(100);stepper1.move(2000);}void loop(){stepper1.run();}With the SINGLE type, and whatever the I2C speed is, the stepper jitters!DOUBLE type works fine, but my stepper is heating a bit, and I would prefer to avoid that.What should I do to make it work properly in SINGLE type?
stepper1.release();
Then, I’ve another problem with this code.I’m just trying to put a delay in the loop. I’d like the stepper to run, stop for a while, and run again. It sounds so simple, but I don’t manage to make it work out.I’ve tried something like this in the loop, which is obviously wrong:void loop(){stepper1.run();if (stepper1.distanceToGo() == 0)delay(5000);{if (delay == 0)stepper1.move(2000);}}I don’t get how to declare a delay as a variable and make its value become a condition for the other operations of the loop.How to do this??
static const uint32_t DELAY = 2000;
void loop()
{
//start a new movement
stepper1.move(2000);
//step the stepper until it reaches the targetposition set with the line above
while(stepper1.run())
;
//wait for some time
delay(DELAY);
}Thanks for your help!
--
You received this message because you are subscribed to the Google Groups "accelstepper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/accelstepper/7204a876-8587-43df-a23e-14aa02cf8a37%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hello Gregor,Sorry for this late answer and thank you very much for your help on the different problems I’m facing.The code for the delay works fine with one stepper!I’ve been therefore trying to do the same with two steppers, running and stoping independently from each other.I want my two steppers to run together, but stop at different times. They start to run together. Then, the first one stops, a LED turns on for 3 seconds, turns off, and the stepper starts to run again. Later on, the same sequence applies for the second stepper. Finally, they run again together, and both stop for 3 seconds to end the loop.Speeds and accelerations are the same for both steppers, and the steps and delays are combined properly to synchronize the steppers at the end of the loop.
if((stepper.speed() == 0.0) &&(stepper.distanceToGo() == 0))void checkSteppers(){ //code will only be executed if stepper is not moving any more if((stepper1.speed() == 0.0) &&(stepper1.distanceToGo() == 0)) { if (/* stepper has stopped just now */) { //remember the current time stepper1_stop_last = millis(); }
//if the stepper was stopped for long enough, set new targets if (millis() - stepper1_stop_last > STEPPER1_DELAY) { stepper1.move(36800); } }
//the same for other steppers...}
void loop() { checkSteppers(); //does not block! should return as soon as possible.
stepper1.run(); stepper2.run();}With this code, the steppers run one by one, and together only at the end. How to correct it to get the right sequence?Regarding the frequency of the I2C bus, I’ve tried to use Wire.setClock rather than the TWBR code.As I read on the Arduino web site, Wire.setClock admit only certain frequencies, depending also of the processor used. As I’ve experienced, TWBR may not work with some of these frequencies while admitting other ones. Does it sound correct to you?
Anyway, both ways work pretty fine to make my steppers run in DOUBLE and INTERLEAVE type. I still have problems with SINGLE, but my main problem is the use of MICROSTEP, that I would really need to use to avoid noise issues with my steppers.With adapted values of speed and acceleration (x 16), whatever the way to set the I2C frequency is and its value, my steppers run much slower. This is the code for one stepper:
By the way, I’m using a 6.2 V stepper supplied with 5 V.
Thanks again!!