The next plan is to connect a stepper motor to the focus knob of a microscope
As I have Meccano lying around I decided to use that.
I tried the belt from an old scanner, but that was too thin.
I have an old Dyson vacuum cleaner so butchered that for the drive belt, much better.
The drive belt was a bit short so I used gears so I could fix the motor to a base and raise the drive wheel high enough so the belt drive would connect to the fine focus knob.
Pictures to follow.
First attempt at code for combining taking picture with rotating motor
import time
import picamera
import RPi.GPIO as GPIO
delay = 0.0055
steps = 500
GPIO.setmode(GPIO.BCM)
GPIO.setup(25, GPIO.IN, GPIO.PUD_UP)
GPIO.setup(8, GPIO.IN, GPIO.PUD_UP)
GPIO.setwarnings(False)
# Enable GPIO pins for ENA and ENB for stepper
enable_a = 18
enable_b = 22
# Enable pins for IN1-4 to control step sequence
coil_A_1_pin = 23
coil_A_2_pin = 24
coil_B_1_pin = 4
coil_B_2_pin = 17
# Set pin states
GPIO.setup(enable_a, GPIO.OUT)
GPIO.setup(enable_b, GPIO.OUT)
GPIO.setup(coil_A_1_pin, GPIO.OUT)
GPIO.setup(coil_A_2_pin, GPIO.OUT)
GPIO.setup(coil_B_1_pin, GPIO.OUT)
GPIO.setup(coil_B_2_pin, GPIO.OUT)
# Set ENA and ENB to high to enable stepper
GPIO.output(enable_a, True)
GPIO.output(enable_b, True)
# Function for step sequence
def setStep(w1, w2, w3, w4):
GPIO.output(coil_A_1_pin, w1)
GPIO.output(coil_A_2_pin, w2)
GPIO.output(coil_B_1_pin, w3)
GPIO.output(coil_B_2_pin, w4)
picstart = input("Frame start number? ")
with picamera.PiCamera() as camera:
camera.start_preview()
frame = float(picstart)
while True:
if GPIO.input(25) == GPIO.LOW:
camera.capture('/home/pi/Desktop/frame%03d.jpg' % frame)
frame += 1
for i in range(0, steps):
setStep(1,0,1,0)
time.sleep(delay)
setStep(0,1,1,0)
time.sleep(delay)
setStep(0,1,0,1)
time.sleep(delay)
setStep(1,0,0,1)
time.sleep(delay)
elif GPIO.input(8) == GPIO.LOW:
break
As I have Meccano lying around I decided to use that.
I tried the belt from an old scanner, but that was too thin.
I have an old Dyson vacuum cleaner so butchered that for the drive belt, much better.
The drive belt was a bit short so I used gears so I could fix the motor to a base and raise the drive wheel high enough so the belt drive would connect to the fine focus knob.
Pictures to follow.
First attempt at code for combining taking picture with rotating motor
import time
import picamera
import RPi.GPIO as GPIO
delay = 0.0055
steps = 500
GPIO.setmode(GPIO.BCM)
GPIO.setup(25, GPIO.IN, GPIO.PUD_UP)
GPIO.setup(8, GPIO.IN, GPIO.PUD_UP)
GPIO.setwarnings(False)
# Enable GPIO pins for ENA and ENB for stepper
enable_a = 18
enable_b = 22
# Enable pins for IN1-4 to control step sequence
coil_A_1_pin = 23
coil_A_2_pin = 24
coil_B_1_pin = 4
coil_B_2_pin = 17
# Set pin states
GPIO.setup(enable_a, GPIO.OUT)
GPIO.setup(enable_b, GPIO.OUT)
GPIO.setup(coil_A_1_pin, GPIO.OUT)
GPIO.setup(coil_A_2_pin, GPIO.OUT)
GPIO.setup(coil_B_1_pin, GPIO.OUT)
GPIO.setup(coil_B_2_pin, GPIO.OUT)
# Set ENA and ENB to high to enable stepper
GPIO.output(enable_a, True)
GPIO.output(enable_b, True)
# Function for step sequence
def setStep(w1, w2, w3, w4):
GPIO.output(coil_A_1_pin, w1)
GPIO.output(coil_A_2_pin, w2)
GPIO.output(coil_B_1_pin, w3)
GPIO.output(coil_B_2_pin, w4)
picstart = input("Frame start number? ")
with picamera.PiCamera() as camera:
camera.start_preview()
frame = float(picstart)
while True:
if GPIO.input(25) == GPIO.LOW:
camera.capture('/home/pi/Desktop/frame%03d.jpg' % frame)
frame += 1
for i in range(0, steps):
setStep(1,0,1,0)
time.sleep(delay)
setStep(0,1,1,0)
time.sleep(delay)
setStep(0,1,0,1)
time.sleep(delay)
setStep(1,0,0,1)
time.sleep(delay)
elif GPIO.input(8) == GPIO.LOW:
break