stepper motor and servo key control - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: stepper motor and servo key control (/thread-28589.html) |
stepper motor and servo key control - cel - Jul-25-2020 Hello, I've been working on a turret that uses a 24-byj stepper motor to control the x axis and an sg-90 servo to control the y axis. Through my raspberry pi I was able to control both with a program I wrote. The problem I'm having is that when both are running, the stepper motor moves slower to the left than usual and does not move to the right at all, and I have tried using an external power source. import RPi.GPIO as GPIO import time import curses servo_value = 9 screen = curses.initscr() curses.noecho() curses.cbreak() screen.keypad(True) try: GPIO.setmode(GPIO.BOARD) GPIO.setup(3, GPIO.OUT) servo1 = GPIO.PWM(3, 50) ControlPin = [7,11,13,15] for pin in ControlPin: GPIO.setup (pin, GPIO.OUT) GPIO.output (pin, 0) seq2 = [[1,0,0,0], [1,0,0,0], [0,1,0,0], [0,1,0,0], [0,0,1,0], [0,0,1,0], [0,0,0,1], [0,0,0,1], [1,0,0,0],] seq3 = [[1,0,0,0], [0,0,0,1], [0,0,0,1], [0,0,1,0], [0,0,1,0], [0,1,0,0], [0,1,0,0], [1,0,0,0], [1,0,0,0],] while True: servo1.start(servo_value) char = screen.getch() if char == ord('q'): break elif char == curses.KEY_UP: print("key up pressed") servo_value = servo_value + 0.25 servo1.ChangeDutyCycle(servo_value) print(servo_value) time.sleep(0.001) elif char == curses.KEY_DOWN: print("key down pressed") servo_value = servo_value - 0.25 servo1.ChangeDutyCycle(servo_value) print(servo_value) time.sleep(0.001) # right turning elif char == curses.KEY_RIGHT: for i in range(15): print("right") for halfstep in range(9): for pin in range(4): GPIO.output(ControlPin[pin], seq2[halfstep][pin]) time.sleep(0.001) # left turning elif char == curses.KEY_LEFT: for i in range(15): print("left") for halfstep in range(9): for pin in range(4): GPIO.output(ControlPin[pin], seq3[halfstep][pin]) time.sleep(0.001) GPIO.cleanup() except AttributeError: servo1.stop() GPIO.cleanup() RE: stepper motor and servo key control - DPaul - Jul-25-2020 This is some time ago for me, but is it a software or hardware problem? They sell controllers ('drivers) to connect multiple motors working together in the same project. (6 servo, 12 servo, 24 servo...etc). There are zillions of models like : https://www.pololu.com/product/1350 I am unsure if you can connect 2 different types to the same controller though.(servo,stepper) Paul RE: stepper motor and servo key control - Larz60+ - Jul-25-2020 see also: https://pypi.org/search/?q=stepper&o=-zscore RE: stepper motor and servo key control - cel - Jul-25-2020 The servo is connected directly to the pi but im using a UNL2003 driver for the stepper motor. RE: stepper motor and servo key control - DPaul - Jul-27-2020 OK, UNL2003 is the one for the stepper. Judging a hardware project from a distance is tricky. One suggestion/test: invest in a second servo to replace the stepper and a controller for the 2 servos. (Should be around 10$) They do articulated cranes with 4 servos, not unlike a turret. Doing that , i would look into post #3, seems interesting. If you have tower pros, always check on their webpage if you have the genuine article; They are the best, but also the most faked. You can tell by the way the logo is printed Paul |