Hi everyone !
I am working on an art installation with motors. Before i always used Dc motors but i always had trouble with the lack of precision. So today, i am starting using stepper motors (nema 18, 17HS19-2004S1, 0,59Nm) with Tb6600 drivers, 12v 2A power supplies, and arduinos uno.
What i would like to do :
I'd like to set the four stepper motors on the ceiling of a room, equipped with reels of nylon wires. The wires are linked to the four corners of a sheet. I want to pre-program the motors so they move indepently and simultaneously in a choreagraphy that last 3 minutes and loops every nine minutes.
So step by step, it could look like :
-Pause of a long delay at the end or the beginning
-motors starts to run, together or one by one, at different speeds, different accelerations and during different times.
- when a motors stops, it can pause for one or few seconde an then run again to another position.
For better understanding, this code is for one motor and i would like to run four (or at least two) motors with each its own choregraphy, independent of the others, in a single sketch (apart from the fact that runToPosition is a blocking function, obviously) :
#include <AccelStepper.h>
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
void setup() {
}
void loop() {
stepper.setMaxSpeed(800);
stepper.setAcceleration(200);
stepper.moveTo(8000);
stepper.runToPosition();
delay(1000);
stepper.setMaxSpeed(1000);
stepper.setAcceleration(500);
stepper.moveTo(0);
stepper.runToPosition();
delay(3000);
stepper.setMaxSpeed(1500);
stepper.setAcceleration(800);
stepper.moveTo(500);
stepper.runToPosition();
delay(1000);
}
So I looked to the Multiplesteppers example. And i'm having trouble.
I tried to modify it in many ways, but i always end up far from the result i am looking for.
exemple :
#include <AccelStepper.h>
AccelStepper stepper1(AccelStepper::DRIVER, 2, 3);
AccelStepper stepper2(AccelStepper::DRIVER, 8, 9);
void setup()
{
}
void loop()
{
stepper1.setMaxSpeed(200.0);
stepper1.setAcceleration(100.0);
stepper1.moveTo(800);
if (stepper1.distanceToGo() == 0)
stepper1.moveTo(400);
stepper1.run();
stepper2.setMaxSpeed(300.0);
stepper2.setAcceleration(100.0);
stepper2.moveTo(1200);
if (stepper2.distanceToGo() == 0)
stepper2.moveTo(400);
stepper2.run();
}
With this code, for exemple, the first rotation is good on each motors and then they run extremely slow and note in the direction i told or at least want them to.
If i try to had a delay, the two motors run extremely slow from the beginning.
Do you have any advices ? infomations ? helpful references ?
I can feel i'm getting closer to the goal but this is the part where i'm lost
Thanks for reading
Noar