#!/usr/bin/python3 import RPi.GPIO as GPIO import time from adafruit_motorkit import MotorKit kit = MotorKit() GPIO.setmode(GPIO.BCM) #22 LED Active #23 Input Active GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #24 LED Recording #25 Input Recording GPIO.setup(25, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #5 Button Even (pulled up) # GPIO.setup(5, GPIO.IN) #6 Sound sensor GPIO.setup(6, GPIO.IN, pull_up_down=GPIO.PUD_UP) i=0 try: while True: # HEAD if GPIO.input(23): #print(".") kit.motor1.throttle = 1
import time import board from adafruit_motorkit import MotorKit wheels = MotorKit(i2c=board.I2C()) class robotManuevers: def turnLeft90Over(): wheels.motor3.throttle = 0 wheels.motor4.throttle = 0 time.sleep(.5) wheels.motor3.throttle = 0.80 wheels.motor4.throttle = -0.67 time.sleep(.84) wheels.motor3.throttle = 0 wheels.motor4.throttle = 0 time.sleep(.5) def turnLeft90(): wheels.motor3.throttle = 0 wheels.motor4.throttle = 0 time.sleep(.5) wheels.motor3.throttle = 0.7 wheels.motor4.throttle = -0.65 time.sleep(.93) wheels.motor3.throttle = 0 wheels.motor4.throttle = 0 time.sleep(.5) def turnRight90():
#!/usr/bin/python # # NOTE - Only for use on Raspberry Pi or other SBC. # import time import atexit import threading import random import board from adafruit_motor import stepper as STEPPER from adafruit_motorkit import MotorKit # create a default object, no changes to I2C address or frequency kit = MotorKit(i2c=board.I2C()) # create empty threads (these will hold the stepper 1 and 2 threads) st1 = threading.Thread() # pylint: disable=bad-thread-instantiation st2 = threading.Thread() # pylint: disable=bad-thread-instantiation # recommended for auto-disabling motors on shutdown! def turnOffMotors(): kit.stepper1.release() kit.stepper2.release() atexit.register(turnOffMotors) stepstyles = [ STEPPER.SINGLE, STEPPER.DOUBLE, STEPPER.INTERLEAVE, STEPPER.MICROSTEP ]
"""Simple test for using adafruit_motorkit with a stepper motor""" from adafruit_motor import stepper from adafruit_motorkit import MotorKit import time kit = MotorKit(0x6f, None, 2) NotDone = True myRange = 400 delay = 3 while NotDone: print("Single coil steps") for i in range(myRange): kit.stepper2.onestep(direction=stepper.FORWARD, style=stepper.SINGLE) for i in range(myRange): kit.stepper2.onestep(direction=stepper.BACKWARD, style=stepper.SINGLE) time.sleep(delay) print("Double coil steps") for i in range(myRange): kit.stepper2.onestep(direction=stepper.FORWARD, style=stepper.DOUBLE) for i in range(myRange): kit.stepper2.onestep(direction=stepper.BACKWARD, style=stepper.DOUBLE) time.sleep(delay) print("Interleaved coil steps") for i in range(myRange): kit.stepper2.onestep(direction=stepper.FORWARD, style=stepper.INTERLEAVE) for i in range(myRange): kit.stepper2.onestep(direction=stepper.BACKWARD, style=stepper.INTERLEAVE)
def __init__(self, _address): self.kit = MotorKit(address=_address) self.kit.stepper2.release() self.status = 'up'
def __init__(self): self.kit = MotorKit() self.speed = 0
import os import time from adafruit_motorkit import MotorKit folder_name = "5_14_turnleft" ## image saved name => " date +action type" times = 100 ## number of image kit = MotorKit() ## wheel1 =right ,wheel 2 = left for i in range(times): kit.motor1.throttle = 0 ## set wheel1 speed kit.motor2.throttle = 0.5 ## set wheel 2 speed time.sleep(0.2) kit.motor1.throttle = 0 ## wheel1 stop kit.motor2.throttle = 0 ## wheel 2stop a = "raspistill -o " b = folder_name c = str(i) # the ith photo d = ".jpg" command = a + b + c + d os.system(command)
class ControllerType(Enum): none = 0 PID = 1 class LimitAction(Enum): none = 0 Abort = 1 Disable = 2 NegDisable = 3 PosDisable = 4 Home = 5 Count = 0 kit = MotorKit(0x6f) class Axis(object): ''' def __init__(self, number, axis_type, feedback, pos_lim_switch, neg_lim_switch, home_switch=None): if axis_type == AxisType.Stepper: return _Stepper(number) elif axis_type == AxisType.Motor: return _Motor(number, feedback, pos_lim_switch, neg_lim_switch, home_switch) else: Axis.error("Unknown motor type.") ''' def __init__(self, number, feedback, pos_lim_switch, neg_lim_switch, home_switch=None): self.Number = number
"""Simple test for using adafruit_motorkit with a stepper motor""" import sys import time import board import ntplib from datetime import datetime, timezone import pytz from adafruit_motorkit import MotorKit from adafruit_motor import stepper import RPi.GPIO as GPIO # ir sensor on GPIO pin 4 ir = 4 GPIO.setup(ir, GPIO.IN) clock = MotorKit(i2c=board.I2C()) c = ntplib.NTPClient() # if sensor is high, step off of it if GPIO.input(ir) == 1: for i in range(144): clock.stepper1.onestep(style=stepper.DOUBLE) time.sleep(0.005) # find home position = 0 while GPIO.input(ir) == 0:
elif togo == 2: goForward() elif barcodeData == '4': togo = random.randint(1, 3) if togo == 1: goLeft() elif togo == 2: goForward() elif togo == 3: goRight() if __name__ == "__main__": motor = MotorKit() def_speed = 50 error = 0 last_error = 0 output = 0 kp = 1.2 kd = 1.5 running = True goReadBar = False res_change = False turnBar = 0 timeforreadBar = 3000 millis = 0 startmillis = False barcodeData = None
# please install the libraries from here # https://github.com/adafruit/Adafruit_CircuitPython_DHT # adafruit libraries import board import adafruit_dht import time # Initial the dht device, with data pin connected to: dhtDevice = adafruit_dht.DHT22(board.D4) #motor hat section from adafruit_motorkit import MotorKit kit = MotorKit(0x40) while True: try: # Print the values to the serial port temperature_c = dhtDevice.temperature temperature_f = temperature_c * (9 / 5) + 32 humidity = dhtDevice.humidity print("Temp: {:.1f} F / {:.1f} C Humidity: {}% ".format( temperature_f, temperature_c, humidity)) # motor direction based on temperature if ((temperature_c >= 24.0) and (temperature_c <= 29.0)): # moves forward kit.motor1.throttle = 1.0 kit.motor2.throttle = 1.0
pass # ------------------ Initialize IMU ------------------ if imu_activated: imu = IMU() # ------------------ Initialize IR ------------------- if ir_sensor_activated: #ir = IR(17) pass # ---------------- Initialize Motors ----------------- #print("motor1") if motors_running: robot = MotorKit() if arm_active: arm = Arm(0x61) # ---------------- Initialize Cube Sensor ----------------- if cubesensor_active: ser = serial.Serial(port='/dev/ttyS0', baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=1) # ---------------- Initialize USFS ----------------- if usfs_active: MAG_RATE = 100
def init(): global kit kit = MotorKit()