Good morning all, Im fairly new to Arduino and coding as a whole. I'm working on a fairly simple project for work, and was hoping to use an Arduino instead of tons of timers, and latching relays.
All I need to do is have a single push button, that when pressed will cause a stepper to turn, in one direction. I need to be able to set a ramp up time, and a ramp down time, and a max run speed after the ramp up. That's literally it, I almost feel silly for asking but I'm just not sure how to go about doing it.
A Bonus would be if I could make the program use my drivers enable wires too, obviously it would automatically enable when the button is pressed. But if I could also make it so that you can hold a 2nd button to disable to stepper when its not moving, essentially to "unlock it" so it can be spun by hand.
I found this searching on you tube. But I don't know how to go about modifying it so that I can control it using a momentary push button. I just need to push the button and have it ramp up and continue spinning indefinitely until the button is released, once the button is released it slows down and stops.
STI:
All I need to do is have a single push button, that when pressed will cause a stepper to turn, in one direction. I need to be able to set a ramp up time, and a ramp down time, and a max run speed after the ramp up. That's literally it, I almost feel silly for asking but I'm just not sure how to go about doing it.
An Arduino will do this nicely but your description here is very confused. Do you want to use a single button {A} to start the motion and {B} to adjust the acceleration rate?
If so I think that would result in very user-unfriendly system.
also look up the AccelStepper library as it is designed to manage acceleration and deceleration - assuming you want the motor to move a specific number of steps.
If you want the motor to move continuously after a button press and stop when the button is next pressed AND use acceleration and deceleration then you will need to write your own acceleration code, It is not particularly difficult to do so - one way is illustrated here.
When you push (and hold) button A I would like the arduino to Enable the stepper driver and begin accelerating to top speed. When the button is released I would like the arduino to begin decelerating to a stop, and then disable the driver.
Button B is just to manually Enable/Disable the driver when its not moving, thats all. This is so the motor can be turned by hand if needed.
When you push (and hold) button A I would like the arduino to Enable the stepper driver and begin accelerating to top speed. When the button is released I would like the arduino to begin decelerating to a stop, and then disable the driver.
Button B is just to manually Enable/Disable the driver when its not moving, thats all. This is so the motor can be turned by hand if needed.
Study the links I gave you in Reply #2. They will probably be easier than the Github stuff.
So I found the following code, using the accel stepper library, made some minor tweaks and it seems to do exactly what I need. However I cannot figure out how to change the running speed of the motor. and I don't really understand what the code is doing, or how it works.
I hate the thought of using something in my machine that I don't actually understand. Can anyone help to explain it a bit, and maybe make some suggestions on ways to make it better? I have never programmed in my life, and most of the guides I have found either cover something I don't need, or assume you already have some coding knowledge.
#include <AccelStepper.h>
AccelStepper stepper(AccelStepper::DRIVER, 9, 8);
int buttonPin = 3;
int buttonState;
void setup()
{
stepper.setMaxSpeed(2000);
stepper.setAcceleration(500);
stepper.setMinPulseWidth(1);
pinMode(buttonPin, INPUT);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState == LOW)
stepper. move (-20000);
stepper. run ();
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH)
{
stepper.stop();
stepper.runToPosition();
}
}