I have a question. I am working to automate my curtains with a stepper motor nema 17 stepper, DVR8825 stepper driver, wemos D1 mini.
I made a code with 3 pulse switch.
Input D5 move to step 1275
Input D6 move to step 0
Input D7 stop
however the stop does not work, I would like it to stop immediately when it is doing the movement.
can someone help me?
Add some serial prints so that you can be sure that the stop button is being detected. Also, that the other buttons aren't just immediately kicking off movement again.
First question: How are your buttons wired up? They will need an external pullup/pulldown resistor to work. Are they installed? Much better to wire one side of your button to the pin, the other side to ground and declare it as INPUT_PULLUP. It will then read LOW when pressed.
You should look at the State Change Detection example that is part of the IDE (File->examples->02.digital->State Change Detection) to learn how to detect when those buttons get pressed, not if they are currently pressed (or not).
i checked it in the serial monitor. The buttons work.
now I also read somewhere that the function stepper.runToPosition. blocks until executed
I think that's why the stop button doesn't work
Does anyone have an idea how I can get this to work?
I would like to move the button (closed) from position 0 to 1275
and with the button (open) goes from 1275 to 0.
and with the button (stop) can stop it immediately.
With this code, crazy things may happen if you press multiple buttons and the buttons are not debounced, etc. It would be much better to look at the State Change Detection example in the IDE (File->examples->02.digital->State Change Detection) and then only change the value when a button is pressed.
Thank you,
I'll have a look in the IDE (File->examples->02.digital->State Change Detection).
This code does work.
But when I use the (stop) button it only works when the motor is running at full speed and it doesn't stop immediately.
I would like it to stop immediately when the button (stop) is pressed.
idea ?
If you want it to stop without doing any deceleration, just tell it to move to its current position. This is exactly what the .move() function does [relative move]
I have changed the code.
but now when i press the button (stop) it stops accelerating and slowly comes to a standstill, then moves back to the point where i pressed stop
void loop() {
stepper.run();
if (digitalRead(D5) == HIGH) {
Serial.println("Dicht");
stepper.moveTo(1975);
}
if (digitalRead(D6) == HIGH) {
Serial.println("Open");
stepper.moveTo(0);
}
if (digitalRead(D7) == HIGH) {
Serial.println("Stop");
stepper.move(0);
}
}
Not to the coding level. But do have the data sheet for the controller printed and handy? From it I see this: The first step in configuring the DRV8825 requires the desired motor speed and microstepping level. If the target
application requires a constant speed, then a square wave with frequency ƒstep must be applied to the STEP pin.". That is where you calculate the rate to pulse the step pin. Then follows a warning about attempting to set the rate too high, but by coding the individual steps, you likely will not exceed the limit where acceleration is necessary.
So, identify the step, direction and other pins used by the control board. Your program is already using them with libraries.
This is going to be a long project, so are you REALLY, REALLY sure you want to to stop the motor immediately?