Python Forum

Full Version: Stepper motor/Easy Driver/HELP
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a camera slider that ATM uses an Arduino controller written Airi Clenz miniEngine. It works well, except, I can't change the functionality of it as the code is quite intense (read that as beyond my capabilities) and it uses a dot matrix screen with a few buttons to make changes.

I have recently started playing around with Raspberry Pi's and was thinking why not switch it to Pi and use a touch screen and add the setting features I want that I cant change in the old system.

I currently use a nema17 (3volt version), Easydriver step motor controller and an Aduino Mega and the whole lot runs of a USB-C Battery brick I use for my Macbook pro when 'Im away. It works great. The power supply I have tried with the Pi and motor etc and it works without a fault.

I would like to keep the Nema an easydriver as these work well and are very smooth in their operation. I started doing the googling and playing around with code and I mumbled my way around this code I found, but the problem is it uses the MSI pins and therefore I dont have the frequency adjustment I used to have the movement is very mechanical. RpiMotorLib only has 4 settings for the A3967 Stepper Driver EasyDriver, the rotations are not as fluid like it used to be, (my old system doesnt use the MSI pins. I tried a different stepper motor (from the local electronics store), but this requires12v minimum and that would mean heavy power source to carry on long treks,. So I would like to stick with the easydriver. I manged to fumble my way around and add the sleep sections to make the motor wait till a period of time for the shutter to do its stuff. but the motor is not smooth.

import RPi.GPIO as GPIO

from RpiMotorLib import RpiMotorLib
from time import sleep    
 
GPIO_pins = (6, 13) 
direction= 24       
step = 23   
shutter = 23

mymotortest = RpiMotorLib.A3967EasyNema(direction, step, GPIO_pins)
steps = 200
exposure = 1
interval = 0.5
shots = 5
i = shots

while shots > 0:  # loop 
  mymotortest.motor_move(0.01, steps,  True, True, 1000, 0.5)
  sleep(exposure)
  #insert shutter trigger code here
  print("shot taken")
  print (shots)
  sleep(interval)
  shots -= 1
print ("Timelapse Complete")

GPIO.cleanup()
I found this code by Domoticz than I can get to work with the motor being very smooth when it rotates but no matter what I try I cant seem to "understand" how to get it to stop and allow the Shutter operation to do its bit then restart.

import RPi.GPIO as GPIO, time


GPIO.setmode(GPIO.BOARD)
GPIO.setup(16, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)
GPIO.setwarnings(False)
GPIO.output(16, True)

#iemand anders 500
p = GPIO.PWM(16, 5000)

def SpinMotor(direction, num_steps):
    p.ChangeFrequency(500)
    GPIO.output(18, direction)

    while num_steps > 0:
        p.start(1)
        time.sleep(0.01)
        num_steps -= 1
    p.stop()
      
    GPIO.cleanup()
    return True

direction_input = 'O'
num_steps = 150
if direction_input == 'C':
    SpinMotor(False, num_steps)
else:
    SpinMotor(True, num_steps)
When ever I try and get it run based on the number of shots instead of steps, the motor just rotates and doesnt stop.

I can build anything physical, but I cant get my 60 year old brain around code as quickly>

I hope I wrote this out correctly and someone can pont me in the right direction. Once I can get it to stop and continue, I can figure the rest out myself.

Thank you
Sorted the code out to work how I wanted it to.