Python Forum
Stepper motor/Easy Driver/HELP
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stepper motor/Easy Driver/HELP
#1
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
Reply
#2
Sorted the code out to work how I wanted it to.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 1,170 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  python 3 raspberry pi 4 dual control motor programming problem yome 0 1,307 Mar-21-2021, 05:17 PM
Last Post: yome
Photo Raspberry PI writing to RS485 driver, DIR pin not holding state zazas321 2 1,180 Oct-30-2020, 06:23 AM
Last Post: zazas321
  stepper motor and servo key control cel 4 1,595 Jul-27-2020, 06:26 AM
Last Post: DPaul
  Stepper Motor key control cel 2 1,228 Jul-25-2020, 12:19 AM
Last Post: cel
  EOF error using stepper motor cel 1 1,204 Jul-24-2020, 01:27 PM
Last Post: Larz60+
  Control 2 stepper motor simultaneously jihene 2 2,949 May-08-2019, 05:27 PM
Last Post: DeaD_EyE
  Writing device driver to stop electric supply to any I/O port sumandas89 0 1,245 May-02-2019, 10:22 AM
Last Post: sumandas89
  How to use servo motor with TFMini Distance Sensor in python script? programerguy 1 2,551 Dec-04-2018, 04:57 PM
Last Post: Larz60+
  how to upload a file to my gmail driver after login ?? evilcode1 5 3,015 Nov-06-2018, 07:33 AM
Last Post: evilcode1

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020