Hey,
i am fairly new at this... I need a solution for an exhibition. A rotating platform needs to turn by 90 degrees each time the button is pushed. Since i am going to use gear reduction of of 4:1 the stepper (Bipolar NEMA 17) needs to turn 360 degrees each time. I already figured out the basics and learned how to control a stepper using either a L298 or a A4988 driver board. But i can't figure out how implement the push button. I tried different scripts for the button, but the stepper either always turns or does not react at all. I realize that it is much to ask, but im really stuck here...
Could you point me in the right direction? Is my hardware suitable for this?
pyrococcus:
I tried different scripts for the button, but the stepper either always turns or does not react at all.
Show us your script and someone will probably help you fix it. (use the </> in the message editor to post your code)
Is my hardware suitable for this?
I don't know, you mention "either a L298 or a A4988 " bit I've no idea what you are actually using or how you have wired it all up. A circuit diagram or a scribbled picture or a picture of your setup would give us a clue.
Sorry for my ignorance, i am aware that this is probably pretty easy and my errors are obvious to you, but i can't figure out what i am doing wrong... Is this while loop the wrong approach?
Which should be ok as long as you let go of the button before 200 steps have been done.
(otherwise it will see the button HIGH again and do another 200 steps)
To do anything more complicated, you will have to debounce that button and only do things when the buttonState goes from LOW to HIGH, not just when it is HIGH.
If that does not work, you will have to test the bits separately to figure out what's wrong, like:
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) { // just test the button using Serial Monitor
Serial.println("HIGH");
}else
{
Serial.println("LOW");
}
delay( 100 );
}
and
void loop() {
// Simple test of stepper, do 200 steps, wait 2 seconds, do it again
myStepper.step(-200);
delay( 2000 );
}
This is one of the rare cases where a Fritzing is fairly readable, even though the button is still ambiguous (which of the four pins are connected to one another?).
It's more common and often better to wire the button between the pin and the GND, then enable the internal pull-up resistor by setting the pinMode to INPUT_PULLUP. The button is now active LOW, and you don't need the external resistor.
wvmarle:
It's more common and often better to wire the button between the pin and the GND, then enable the internal pull-up resistor by setting the pinMode to INPUT_PULLUP.
Completely agree with you there. +V on switches: it'll all end in tears.
Did notice his Fritthing is actually the diagram from the Debounce Tutorial - why are the 'official' tutorials recommending this ?
I know, I see them all the time.
Fritzings can be a useful help in wiring up stuff - but at the very least they should add a proper circuit diagram as well. Much clearer, and if you want to get anywhere in this field you must learn to read and draw them anyway.
Back when I learned electronics (now some 30 years ago) pen and paper was all we had!
hi i am having the same problem can u help me? i need the code for my stepper motor with a4988 driver to rotate in 360 degrees everytime i will press the button
NEWBIE1999:
hi i am having the same problem can u help me? i need the code for my stepper motor with a4988 driver to rotate in 360 degrees everytime i will press the button
Have you read through this Thread carefully and studied all the links in it?