How to use buttons for stepper motor movement

I have a working KS1 on a Raspberry pi zero w.

Are there any instructions on using a button for triggering clockwise and another for counterclockwise?

How about any other sensors that can trigger movement?

Any ideas, links, thoughts would be helpful.

I was in the middle of trying to integrate the Skywriter Hat, but it appeared to brick after one session.

piborg's picture

I would first start with our standard example: zbStepper.py.

This should provide a MoveStep function which can be given a number of steps to move the stepper by either clockwise or counterclockwise. As standard it will ask for the number of steps each time, negative values rotate the opposite way to positive ones.

To make these moves happen from a button press or some kind of sensor you will want to change the code inside the while True: section towards the bottom. There are a number of ways to detect these events depending on what you want to use.

For buttons the easiest way to do this would probably be to use a GPIO pin to detect if the button is pressed or not. Raspi.TV has a quick guide which explains how to wire a button to the GPIO and do something when it is pressed or released: http://raspi.tv/2014/rpi-gpio-update-and-detecting-both-rising-and-falli...

Fantastic! Brilliant! That is exactly the start I was looking for.
Any additional sensor, no matter how odd or off-the-wall, would also be welcome.
Cheers

Subscribe to Comments for "How to use buttons for stepper motor movement"