Hi together
As I have tried numerous times to do the coding myself and time is running out for my project, I need some help.
My setup is simple and straight Forward:
- 4 stepper Motors with 4 A4988 Drivers
- 4 pots and one Arduino Mega
Stepper One: DirPin 2, StepPin 3
Stepper Two: DirPin 4, StepPin 5
Stepper Three: DirPin 6, StepPin 7
Stepper Four: DirPin 8, StepPin 9
Pot One: AnalogRead(A0)
Pot Two: AnalogRead(A1)
Pot Three: AnalogRead(A2)
Pot Four: AnalogRead(A3)
I have wired everything and it worked well in my different tries, but I never got to the goal I tried to achieve, which is to control each of the stepper motors individually by its respective pot, from stand still to a certain rotational speed.
The speed is not as important as the fluent motion, acceleration and slowing down of the motors. It is important that it starts from a standstill as I want to plug it in, start turning the pot and then let the steppers rotate.
As I have read in the AccelStepper library, with which I have tried working, there is a possiblity of letting a stepper motor make a full rotation only once every hour or so, I would like to have them approximately coded to the following rotations/second:
- stepper max 1 rotation per minute. This one will also be microstepped to 1/16th so that it does as many steps as possible during the rotation.
2./3./4. stepper max 10 rotations per second. It would be great if a comment can be included so that I can change it whenever I will need faster rotations. These motors will only be set to half-step, as I feel like this is enough for a smooth rotation.
The pot will rotate from 0 to max clockwise and the stepper should too. If it is possible to comment in the code how I can change that to counter clockwise, it would be great.
It would be good if the code is as simple as possible, as I am trying to figure it out myself and further develop it, but as of right now, I don't have anymore time for this project as it needs to be done by end of next week (for a birthday present, everything stands, just the coding isn't finished).
If anybody could PM me with an estimated time and budget, I would be really grateful. If any more information is needed, I will also answer in the forum.
Many thanks in advance
ifdocsay
Configuration in code or via serial?
What do you mean by code or serial configuration?
Well, you'll need some kind of configuration. And you'll need a way to modify it. Do you want it to live in code e.g. recompile/flash when changing config or do you want a serial terminal to change configuration? Values to store for each stepper are at least "max/min steps per second", "acceleration in steps/second", "deadband of poti", ...
Hi zwieblum
Thanks for the clarification. Andy changes I will be making will be in the code and I will Flash ist when I configure it.
Correct me in I’m wrong, but as I have worked with the AccelStepper Library until now it seems like it will be rather simple to reconfigure if I need any changes to the speed, acceleration, etc. Just someone short comments in the code will be enough I guess.
Hi together
I have somehow solved my issue with my previous code and it seems like I will just need some minor adjustments instead of a whole coding, which is good for me I guess.
For anybody interested, I had some mixup with some pins when I checked everything for this post and by changing my code a little, it worked fine. I still need to adjust and see how I can slow down the first Motor to just rotate once every 10min or so, but I guess it will be some trial and error. I hope this code can help anyone who will maybe need it in the future.
#include <AccelStepper.h>
#define POT_1 A0
#define POT_2 A1
#define POT_3 A2
#define POT_4 A3
int pot1Val, pot2Val, pot3Val, pot4Val;
AccelStepper stepperOne(1, 9, 8);
AccelStepper stepperTwo(1, 7, 6);
AccelStepper stepperThree(1, 5, 4);
AccelStepper stepperFour(1, 3, 2);
void setup() {
stepperOne.setMaxSpeed(1000.0);
stepperOne.setAcceleration(100.0);
stepperTwo.setMaxSpeed(4000.0);
stepperTwo.setAcceleration(300.0);
stepperThree.setMaxSpeed(4000.0);
stepperThree.setAcceleration(300.0);
stepperFour.setMaxSpeed(4000.0);
stepperFour.setAcceleration(300.0);
}
void loop() {
int pot1Val = analogRead(POT_1);
int pot1Speed = map(pot1Val, 0, 1023, 0, 100);
stepperOne.setSpeed(pot1Speed);
stepperOne.runSpeed();
int pot2Val = analogRead(POT_2);
int pot2Speed = map(pot2Val, 0, 1023, 0, 1000);
stepperTwo.setSpeed(pot2Speed);
stepperTwo.runSpeed();
int pot3Val = analogRead(POT_3);
int pot3Speed = map(pot3Val, 0, 1023, 0, 1000);
stepperThree.setSpeed(pot3Speed);
stepperThree.runSpeed();
int pot4Val = analogRead(POT_4);
int pot4Speed = map(pot4Val, 0, 1023, 0, 1000);
stepperFour.setSpeed(pot4Speed);
stepperFour.runSpeed();
}
Thanks anyway!
you want it to rotate it so slow that it takes 0 mins per revolution or you want to make it rotate fast but only every 10 minutes?
Ah sorry for the bad wording: I want the first stepper to complete one rotation over the course of 10, 20 or 30min. I have read in the AccelStepper library that this is possible, but yet to find a way. I will most certainly microstep it, to that it will only make a 1/16 steps so that it is as smooth as possible.