Jun-13-2021, 03:28 AM
I am tweaking this code to get it ready for full integration into an animatronics costume setup. The individual pieces work. basically the GPIO triggers are limit switches. I am trying to build things such that if things slip or move that it will move forward if I hit the forward or backward button again and stop once the limit switch is triggered.
The way the libraries are it appears that it will stop as it is running through a for I range loop but will backup once that loop finishes if the gpio gets triggered.
I will keep researching and will probably sleep on things after I spend all evening researching different approaches on this conundrum. I just need to chew on things but more minds can help come up with unexpected solutions.
This is the code:
The way the libraries are it appears that it will stop as it is running through a for I range loop but will backup once that loop finishes if the gpio gets triggered.
I will keep researching and will probably sleep on things after I spend all evening researching different approaches on this conundrum. I just need to chew on things but more minds can help come up with unexpected solutions.
This is the code:
#!/usr/bin/python import cwiid import RPi.GPIO as GPIO import sys from time import * import subprocess import board #this is for stepper motor controls, keyboard initiates movement, Button is limit switches import keyboard #gpiozero is the only library I have found that functions with the current pi and hardware setup I am using from gpiozero import Button #these are part of the Blinka libraries Adafruit has. from adafruit_motorkit import MotorKit from adafruit_motor import stepper kit1 = MotorKit() # this is for stepper motors and servo board from board import SCL, SDA import busio from adafruit_pca9685 import PCA9685 i2c_bus = busio.I2C(SCL, SDA) pca = PCA9685(i2c_bus) pca.frequency = 50 # standard servo declearations for controls from adafruit_servokit import ServoKit kit = ServoKit(channels=16) #12 and 13 are for one motion assembly backing up one full turn button12 = Button(12) button13 = Button(13) #27 and 5 are for the other motion assembly button27 = Button(27) button5 = Button(5) # while True loops endlessly. This can be run as a service using systemd or setup as an init.d script or as an rc.local script. while True: if button12.is_pressed: print("button12 pressed") for i in range (200): kit1.stepper1.onestep(direction=stepper.BACKWARD, style=stepper.DOUBLE) if button13.is_pressed: print("button13 pressed") for i in range (200): kit1.stepper1.onestep(direction=stepper.FORWARD, style=stepper.DOUBLE) if keyboard.is_pressed('f'): print("f is pressed") for i in range (200): kit1.stepper1.onestep(direction=stepper.BACKWARD, style=stepper.DOUBLE) if keyboard.is_pressed('b'): print("b is pressed") for i in range (200): kit1.stepper1.onestep(direction=stepper.FORWARD, style=stepper.DOUBLE) # This is for channel 2 stepper motor. if button27.is_pressed: print("button12 pressed") for i in range (200): kit1.stepper2.onestep(direction=stepper.BACKWARD, style=stepper.DOUBLE) if button5.is_pressed: print("button13 pressed") for i in range (200): kit1.stepper2.onestep(direction=stepper.FORWARD, style=stepper.DOUBLE) if keyboard.is_pressed('r'): print("f is pressed") for i in range (200): kit1.stepper2.onestep(direction=stepper.BACKWARD, style=stepper.DOUBLE) if keyboard.is_pressed('l'): print("b is pressed") for i in range (200): kit1.stepper2.onestep(direction=stepper.FORWARD, style=stepper.DOUBLE)