Notifications
Clear all

Simple code

1 Posts
1 Users
0 Reactions
1,762 Views
Qaribpour
Posts: 13
Topic starter
(@qaribpour)
Active Member
Joined: 5 years ago

Hi everybody;

I have question about programing

I plan to just rotate the motor so I used the ( Thonny Python IDE) of Raspbian Firmware instead of Fabscanpi for programming the step motor, but the motor don’t rotate at all by this code.

Please note I don’t want remove the FabScan HAT from setup

thank everybody;

This is the code which I used:

from time import sleep
import RPi.GPIO as GPIO

DIR = 20   # Direction GPIO Pin
STEP = 21  # Step GPIO Pin
CW = 1     # Clockwise Rotation
CCW = 0    # Counterclockwise Rotation
SPR = 48   # Steps per Revolution (360 / 7.5)

GPIO.setmode(GPIO.BCM)
GPIO.setup(DIR, GPIO.OUT)
GPIO.setup(STEP, GPIO.OUT)
GPIO.output(DIR, CW)

step_count = SPR
delay = .0208

for x in range(step_count):
    GPIO.output(STEP, GPIO.HIGH)
    sleep(delay)
    GPIO.output(STEP, GPIO.LOW)
    sleep(delay)

sleep(.5)
GPIO.output(DIR, CCW)
for x in range(step_count):
    GPIO.output(STEP, GPIO.HIGH)
    sleep(delay)
    GPIO.output(STEP, GPIO.LOW)
    sleep(delay)

GPIO.cleanup()

I have found the code from these sources

https://www.rototron.info/raspberry-pi-stepper-motor-tutorial/

https://github.com/binbash12/raspberrypi-stepper/blob/master/drive.py

Reply
Share: