Stepper Motor – 360 degree rotation over one hour

Designed to mount a time lapse camera for a 360 degree rotation over 1 hour.  That's 1 degree rotation every 10 seconds.

Uses Adafruit LCD i2C board to display rotation information.


#!/usr/bin/env python

import time
from datetime import datetime
import RPi.GPIO as GPIO

from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate

lcd = Adafruit_CharLCDPlate()
lcd.begin(16, 2)
lcd.clear()
lcd.backlight(lcd.ON)

# Use BCM GPIO references
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)

# Define GPIO signals to use
# Pins 18,22,24,26
# GPIO24,GPIO25,GPIO8,GPIO7
StepPins = [24,25,8,7]

# Set all pins as output
for pin in StepPins:
  print "Setup pins"
  GPIO.setup(pin,GPIO.OUT)
  GPIO.output(pin, False)

# Define some settings
StepCounter = 0
WaitTime = 0.87890625
DegreesRun = 0
TotalSteps = 0
start_time = time.time()
ShouldBeTime=0

# Define simple sequence
StepCount1 = 4
Seq1 = []
Seq1 = range(0, StepCount1)
Seq1[0] = [1,0,0,0]
Seq1[1] = [0,1,0,0]
Seq1[2] = [0,0,1,0]
Seq1[3] = [0,0,0,1]

# Define advanced sequence
# as shown in manufacturers datasheet
StepCount2 = 8
Seq2 = []
Seq2 = range(0, StepCount2)
Seq2[0] = [1,0,0,0]
Seq2[1] = [1,1,0,0]
Seq2[2] = [0,1,0,0]
Seq2[3] = [0,1,1,0]
Seq2[4] = [0,0,1,0]
Seq2[5] = [0,0,1,1]
Seq2[6] = [0,0,0,1]
Seq2[7] = [1,0,0,1]

# Choose a sequence to use
Seq = Seq2
StepCount = StepCount2

# Start main loop

while StepCounter < 4096:

    for pin in range(0, 4):
        xpin = StepPins[pin]
        if Seq[StepCounter][pin]!=0:
            #print " Step %i Enable %i - Pin %s" %(StepCounter,xpin, x)
            GPIO.output(xpin, True)
        else:
            GPIO.output(xpin, False)

    StepCounter += 1

    # If we reach the end of the sequence
    # start again
    if (StepCounter==StepCount):
        StepCounter = 0
    if (StepCounter < 0):
        StepCounter = StepCount

    # Wait before moving on
    time.sleep(WaitTime)

    DegreesRun += 0.087890625
    TotalSteps += 1
    RuningTime = time.time() - start_time
    ShouldBeTime += WaitTime

    y=time.strftime('%H:%M:%S', time.gmtime(RuningTime))
    z=time.strftime('%H:%M:%S', time.gmtime(ShouldBeTime))

    lcd.clear()
    lcd.message(str(y) + " S=" + str(TotalSteps) + "\n")
    lcd.message(str(z) + " DR=" + str(round(DegreesRun,1)))

2pcs DC 5V Stepper Motor 28BYJ 48 + ULN2003 Driver Test Module Board for Arduino
2pcs DC 5V Stepper Motor 28BYJ 48 + ULN2003 Driver Test Module Board for Arduino $7.98
End Date: Wednesday Jul-12-2017 8:59:43 PDT
Buy It Now for only: $7.98
Stepper Motor 28BYJ 48 With Drive Test Module Board ULN2003 5 Line 4 Phase 5V
Stepper Motor 28BYJ 48 With Drive Test Module Board ULN2003 5 Line 4 Phase 5V $3.45
End Date: Sunday Jul-2-2017 19:14:34 PDT
Buy It Now for only: $3.45
5pcs DC 5V Stepper Motor Controllers+ULN2003 Driver Module Board 28BYJ 48 TE118
5pcs DC 5V Stepper Motor Controllers+ULN2003 Driver Module Board 28BYJ 48 TE118 $13.92
End Date: Tuesday Jul-18-2017 18:31:54 PDT
Buy It Now for only: $13.92
2pcs DC 5V Stepper Motor 28BYJ 48 + ULN2003 Driver Test Module Board for Arduino
2pcs DC 5V Stepper Motor 28BYJ 48 + ULN2003 Driver Test Module Board for Arduino $7.98
End Date: Monday Jun-26-2017 7:42:57 PDT
Buy It Now for only: $7.98
2pcs DC 5V Stepper Motor 28BYJ 48 + ULN2003 Driver Test Module Board for Arduino
2pcs DC 5V Stepper Motor 28BYJ 48 + ULN2003 Driver Test Module Board for Arduino $8.35
End Date: Thursday Jun-29-2017 17:46:31 PDT
Buy It Now for only: $8.35
5pcs DC 5V Stepper Motor + ULN2003 Driver Test Module Board 28BYJ 48 for Arduino
5pcs DC 5V Stepper Motor + ULN2003 Driver Test Module Board 28BYJ 48 for Arduino $8.80
End Date: Saturday Jul-15-2017 22:53:25 PDT
Buy It Now for only: $8.80
DC 5V Stepper Motor + ULN2003 Driver Test Module Board 28BYJ 48 for Arduino
DC 5V Stepper Motor + ULN2003 Driver Test Module Board 28BYJ 48 for Arduino $5.70
End Date: Friday Jul-21-2017 18:21:09 PDT
Buy It Now for only: $5.70
2PCS Stepper Motor Driver Board Module ULN2003 for 5V 28BYJ 48 Arduino
2PCS Stepper Motor Driver Board Module ULN2003 for 5V 28BYJ 48 Arduino $3.99
End Date: Monday Jul-10-2017 10:58:21 PDT
Buy It Now for only: $3.99
Aiskaer 6 Sets New Stepper Motor 5v Dc 4 phase 5 wire28byj 48+ Uln2003 Driv
Aiskaer 6 Sets New Stepper Motor 5v Dc 4 phase 5 wire28byj 48+ Uln2003 Driv $16.63
End Date: Friday Jun-30-2017 14:44:12 PDT
Buy It Now for only: $16.63
Raogoodcx 6Pcs 5V Stepper Motor 28BYJ 48 With Drive Test Module Board ULN2003 5
Raogoodcx 6Pcs 5V Stepper Motor 28BYJ 48 With Drive Test Module Board ULN2003 5 $16.47
End Date: Monday Jul-24-2017 8:30:54 PDT
Buy It Now for only: $16.47

« Previous12345...910

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>