Jul-25-2020, 12:30 AM
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.
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()