Skip to content

Control stepper motor over pigpio using python3 on Raspberry Pi

License

Notifications You must be signed in to change notification settings

stripcode/pigpio-stepper-motor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

pigpio-stepper-motor

I use 28BYJ-48 stepper motor (4096 steps) and ULN2003 driver. I connect to 6, 13, 19, 26 pins and control over pigpio using python3 on Raspberry Pi.

Motor args

motor(pi, pin1, pin2, pin3, pin4, [sequence], [delayAfterStep])

  • pi - pigpio.pi instance
  • pin1, pin2, pin3, pin4 - pins has been connected to the driver
  • sequence - halfStepSequence or fullStepSequence. Default sequence = halfStepSequence
  • delayAfterStep - Delay after step. Default delayAfterStep = 0.0025 second

Examples

I connect driver to 6, 13, 19, 26 pins. I use 28BYJ-48 stepper motor (4096 steps in halfStepSequence, 2048 steps in fullStepSequence) and ULN2003 driver.

Clockwise rotation to 180 degrees

import pigpio
from PigpioStepperMotor import StepperMotor

pi = pigpio.pi()
motor = StepperMotor(pi, 6, 13, 19, 26)
for i in range(2048):
  motor.doСlockwiseStep()

Counterclockwise rotation to 180 degrees

import pigpio
from PigpioStepperMotor import StepperMotor

pi = pigpio.pi()
motor = StepperMotor(pi, 6, 13, 19, 26)
for i in range(2048):
  motor.doСounterclockwiseStep()

Clockwise rotation to 180 degrees. Full-step sequence

import pigpio
from PigpioStepperMotor import StepperMotor, fullStepSequence

pi = pigpio.pi()
motor = StepperMotor(pi, 6, 13, 19, 26, sequence = fullStepSequence)
for i in range(1024):
  motor.doСlockwiseStep()

Clockwise rotation to 180 degrees. Delay = 0.05 second. Slowmotion

import pigpio
from PigpioStepperMotor import StepperMotor

pi = pigpio.pi()
motor = StepperMotor(pi, 6, 13, 19, 26,  delayAfterStep = 0.05)
for i in range(2048):
  motor.doСlockwiseStep()

Control stepper motor using keyboard left and right keys

import pigpio
import curses
from PigpioStepperMotor import StepperMotor

pi = pigpio.pi()
stdscr = curses.initscr()
stdscr.keypad(True)
curses.cbreak()
curses.noecho()

try:
  motor = StepperMotor(pi, 6, 13, 19, 26)
  while True:
    key = stdscr.getkey()
    if key == "KEY_LEFT":
      motor.doСlockwiseStep()
    elif key == "KEY_RIGHT":
      motor.doСounterclockwiseStep()
except Exception as e:
  print(e)
finally:
  curses.endwin()
  pi.stop()

License

MIT License

Copyright (c) 2016 stripcode

About

Control stepper motor over pigpio using python3 on Raspberry Pi

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages