From 1fef0af738810aca2e72b5661ba9f67870d0036a Mon Sep 17 00:00:00 2001 From: william3031 Date: Tue, 1 Oct 2019 23:27:21 +1000 Subject: [PATCH 1/4] renamed files --- ...uous_servo.py => motor_pca9685_continuous_servo_simpletest.py} | 0 ...r_pca9685_dc_motor.py => motor_pca9685_dc_motor_simpletest.py} | 0 ...685_servo_sweep.py => motor_pca9685_servo_sweep_simpletest.py} | 0 ...stepper_motor.py => motor_pca9685_stepper_motor_simpletest.py} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename examples/{motor_pca9685_continuous_servo.py => motor_pca9685_continuous_servo_simpletest.py} (100%) rename examples/{motor_pca9685_dc_motor.py => motor_pca9685_dc_motor_simpletest.py} (100%) rename examples/{motor_pca9685_servo_sweep.py => motor_pca9685_servo_sweep_simpletest.py} (100%) rename examples/{motor_pca9685_stepper_motor.py => motor_pca9685_stepper_motor_simpletest.py} (100%) diff --git a/examples/motor_pca9685_continuous_servo.py b/examples/motor_pca9685_continuous_servo_simpletest.py similarity index 100% rename from examples/motor_pca9685_continuous_servo.py rename to examples/motor_pca9685_continuous_servo_simpletest.py diff --git a/examples/motor_pca9685_dc_motor.py b/examples/motor_pca9685_dc_motor_simpletest.py similarity index 100% rename from examples/motor_pca9685_dc_motor.py rename to examples/motor_pca9685_dc_motor_simpletest.py diff --git a/examples/motor_pca9685_servo_sweep.py b/examples/motor_pca9685_servo_sweep_simpletest.py similarity index 100% rename from examples/motor_pca9685_servo_sweep.py rename to examples/motor_pca9685_servo_sweep_simpletest.py diff --git a/examples/motor_pca9685_stepper_motor.py b/examples/motor_pca9685_stepper_motor_simpletest.py similarity index 100% rename from examples/motor_pca9685_stepper_motor.py rename to examples/motor_pca9685_stepper_motor_simpletest.py From a5a037e15e9fa89e1fdfbd9b397e2d77b2241024 Mon Sep 17 00:00:00 2001 From: william3031 Date: Wed, 2 Oct 2019 06:45:53 +1000 Subject: [PATCH 2/4] renamed files --- ...tor_pca9685_continuous_servo_simpletest.py | 39 ------------ examples/motor_pca9685_dc_motor_simpletest.py | 62 ------------------- .../motor_pca9685_servo_sweep_simpletest.py | 56 ----------------- .../motor_pca9685_stepper_motor_simpletest.py | 39 ------------ examples/motor_servo_sweep.py | 52 ---------------- 5 files changed, 248 deletions(-) delete mode 100644 examples/motor_pca9685_continuous_servo_simpletest.py delete mode 100644 examples/motor_pca9685_dc_motor_simpletest.py delete mode 100644 examples/motor_pca9685_servo_sweep_simpletest.py delete mode 100644 examples/motor_pca9685_stepper_motor_simpletest.py delete mode 100644 examples/motor_servo_sweep.py diff --git a/examples/motor_pca9685_continuous_servo_simpletest.py b/examples/motor_pca9685_continuous_servo_simpletest.py deleted file mode 100644 index 2bd12f5..0000000 --- a/examples/motor_pca9685_continuous_servo_simpletest.py +++ /dev/null @@ -1,39 +0,0 @@ -import time - -from board import SCL, SDA -import busio - -# Import the PCA9685 module. Available in the bundle and here: -# https://github.com/adafruit/Adafruit_CircuitPython_PCA9685 -from adafruit_pca9685 import PCA9685 - -from adafruit_motor import servo - -i2c = busio.I2C(SCL, SDA) - -# Create a simple PCA9685 class instance. -pca = PCA9685(i2c) -# You can optionally provide a finer tuned reference clock speed to improve the accuracy of the -# timing pulses. This calibration will be specific to each board and its environment. See the -# calibration.py example in the PCA9685 driver. -# pca = PCA9685(i2c, reference_clock_speed=25630710) -pca.frequency = 50 - -# The pulse range is 750 - 2250 by default. -servo7 = servo.ContinuousServo(pca.channels[7]) -# If your servo doesn't stop once the script is finished you may need to tune the -# reference_clock_speed above or the min_pulse and max_pulse timings below. -# servo7 = servo.ContinuousServo(pca.channels[7], min_pulse=750, max_pulse=2250) - -print("Forwards") -servo7.throttle = 1 -time.sleep(1) - -print("Backwards") -servo7.throttle = -1 -time.sleep(1) - -print("Stop") -servo7.throttle = 0 - -pca.deinit() diff --git a/examples/motor_pca9685_dc_motor_simpletest.py b/examples/motor_pca9685_dc_motor_simpletest.py deleted file mode 100644 index 01e629f..0000000 --- a/examples/motor_pca9685_dc_motor_simpletest.py +++ /dev/null @@ -1,62 +0,0 @@ -# This example uses an Adafruit Stepper and DC Motor FeatherWing to run a DC Motor. -# https://www.adafruit.com/product/2927 - -import time - -from board import SCL, SDA -import busio - -# Import the PCA9685 module. Available in the bundle and here: -# https://github.com/adafruit/Adafruit_CircuitPython_PCA9685 -from adafruit_pca9685 import PCA9685 - -from adafruit_motor import motor - -i2c = busio.I2C(SCL, SDA) - -# Create a simple PCA9685 class instance for the Motor FeatherWing's default address. -pca = PCA9685(i2c, address=0x60) -pca.frequency = 100 - -# Motor 1 is channels 9 and 10 with 8 held high. -# Motor 2 is channels 11 and 12 with 13 held high. -# Motor 3 is channels 3 and 4 with 2 held high. -# Motor 4 is channels 5 and 6 with 7 held high. - -# DC Motors generate electrical noise when running that can reset the microcontroller in extreme -# cases. A capacitor can be used to help prevent this. The demo uses motor 4 because it worked ok -# in testing without a capacitor. -# See here for more info: https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/faq#faq-13 -pca.channels[7].duty_cycle = 0xffff -motor4 = motor.DCMotor(pca.channels[5], pca.channels[6]) - -print("Forwards slow") -motor4.throttle = 0.5 -print("throttle:", motor4.throttle) -time.sleep(1) - -print("Forwards") -motor4.throttle = 1 -print("throttle:", motor4.throttle) -time.sleep(1) - -print("Backwards") -motor4.throttle = -1 -print("throttle:", motor4.throttle) -time.sleep(1) - -print("Backwards slow") -motor4.throttle = -0.5 -print("throttle:", motor4.throttle) -time.sleep(1) - -print("Stop") -motor4.throttle = 0 -print("throttle:", motor4.throttle) -time.sleep(1) - -print("Spin freely") -motor4.throttle = None -print("throttle:", motor4.throttle) - -pca.deinit() diff --git a/examples/motor_pca9685_servo_sweep_simpletest.py b/examples/motor_pca9685_servo_sweep_simpletest.py deleted file mode 100644 index 037a47f..0000000 --- a/examples/motor_pca9685_servo_sweep_simpletest.py +++ /dev/null @@ -1,56 +0,0 @@ -import time - -from board import SCL, SDA -import busio - -# Import the PCA9685 module. Available in the bundle and here: -# https://github.com/adafruit/Adafruit_CircuitPython_PCA9685 -from adafruit_pca9685 import PCA9685 -from adafruit_motor import servo - -i2c = busio.I2C(SCL, SDA) - -# Create a simple PCA9685 class instance. -pca = PCA9685(i2c) -# You can optionally provide a finer tuned reference clock speed to improve the accuracy of the -# timing pulses. This calibration will be specific to each board and its environment. See the -# calibration.py example in the PCA9685 driver. -# pca = PCA9685(i2c, reference_clock_speed=25630710) -pca.frequency = 50 - -# To get the full range of the servo you will likely need to adjust the min_pulse and max_pulse to -# match the stall points of the servo. -# This is an example for the Sub-micro servo: https://www.adafruit.com/product/2201 -# servo7 = servo.Servo(pca.channels[7], min_pulse=580, max_pulse=2350) -# This is an example for the Micro Servo - High Powered, High Torque Metal Gear: -# https://www.adafruit.com/product/2307 -# servo7 = servo.Servo(pca.channels[7], min_pulse=500, max_pulse=2600) -# This is an example for the Standard servo - TowerPro SG-5010 - 5010: -# https://www.adafruit.com/product/155 -# servo7 = servo.Servo(pca.channels[7], min_pulse=400, max_pulse=2400) -# This is an example for the Analog Feedback Servo: https://www.adafruit.com/product/1404 -# servo7 = servo.Servo(pca.channels[7], min_pulse=600, max_pulse=2500) -# This is an example for the Micro servo - TowerPro SG-92R: https://www.adafruit.com/product/169 -# servo7 = servo.Servo(pca.channels[7], min_pulse=500, max_pulse=2400) - -# The pulse range is 750 - 2250 by default. This range typically gives 135 degrees of -# range, but the default is to use 180 degrees. You can specify the expected range if you wish: -# servo7 = servo.Servo(pca.channels[7], actuation_range=135) -servo7 = servo.Servo(pca.channels[7]) - -# We sleep in the loops to give the servo time to move into position. -for i in range(180): - servo7.angle = i - time.sleep(0.03) -for i in range(180): - servo7.angle = 180 - i - time.sleep(0.03) - -# You can also specify the movement fractionally. -fraction = 0.0 -while fraction < 1.0: - servo7.fraction = fraction - fraction += 0.01 - time.sleep(0.03) - -pca.deinit() diff --git a/examples/motor_pca9685_stepper_motor_simpletest.py b/examples/motor_pca9685_stepper_motor_simpletest.py deleted file mode 100644 index 39020af..0000000 --- a/examples/motor_pca9685_stepper_motor_simpletest.py +++ /dev/null @@ -1,39 +0,0 @@ -# This example uses an Adafruit Stepper and DC Motor FeatherWing to run a Stepper Motor. -# https://www.adafruit.com/product/2927 - -import time - -from board import SCL, SDA -import busio - -# Import the PCA9685 module. Available in the bundle and here: -# https://github.com/adafruit/Adafruit_CircuitPython_PCA9685 -from adafruit_pca9685 import PCA9685 - -from adafruit_motor import stepper - -i2c = busio.I2C(SCL, SDA) - -# Create a simple PCA9685 class instance for the Motor FeatherWing's default address. -pca = PCA9685(i2c, address=0x60) -pca.frequency = 1600 - -# Motor 1 is channels 9 and 10 with 8 held high. -# Motor 2 is channels 11 and 12 with 13 held high. -# Motor 3 is channels 3 and 4 with 2 held high. -# Motor 4 is channels 5 and 6 with 7 held high. - -pca.channels[7].duty_cycle = 0xffff -pca.channels[2].duty_cycle = 0xffff -stepper_motor = stepper.StepperMotor(pca.channels[4], pca.channels[3], # Motor 3 - pca.channels[5], pca.channels[6]) # Motor 4 - -for i in range(100): - stepper_motor.onestep() - time.sleep(0.01) - -for i in range(100): - stepper_motor.onestep(direction=stepper.BACKWARD) - time.sleep(0.01) - -pca.deinit() diff --git a/examples/motor_servo_sweep.py b/examples/motor_servo_sweep.py deleted file mode 100644 index ca99dd0..0000000 --- a/examples/motor_servo_sweep.py +++ /dev/null @@ -1,52 +0,0 @@ -import time -import board -import pulseio -from adafruit_motor import servo - -# create a PWMOut object on the control pin. -pwm = pulseio.PWMOut(board.D5, duty_cycle=0, frequency=50) - -# To get the full range of the servo you will likely need to adjust the min_pulse and max_pulse to -# match the stall points of the servo. -# This is an example for the Sub-micro servo: https://www.adafruit.com/product/2201 -# servo = servo.Servo(pwm, min_pulse=580, max_pulse=2350) -# This is an example for the Micro Servo - High Powered, High Torque Metal Gear: -# https://www.adafruit.com/product/2307 -# servo = servo.Servo(pwm, min_pulse=500, max_pulse=2600) -# This is an example for the Standard servo - TowerPro SG-5010 - 5010: -# https://www.adafruit.com/product/155 -# servo = servo.Servo(pwm, min_pulse=400, max_pulse=2400) -# This is an example for the Analog Feedback Servo: https://www.adafruit.com/product/1404 -# servo = servo.Servo(pwm, min_pulse=600, max_pulse=2500) -# This is an example for the Micro servo - TowerPro SG-92R: https://www.adafruit.com/product/169 -# servo = servo.Servo(pwm, min_pulse=500, max_pulse=2400) - -# The pulse range is 750 - 2250 by default. This range typically gives 135 degrees of -# range, but the default is to use 180 degrees. You can specify the expected range if you wish: -# servo = servo.Servo(board.D5, actuation_range=135) -servo = servo.Servo(pwm) - -# We sleep in the loops to give the servo time to move into position. -print("Sweep from 0 to 180") -for i in range(180): - servo.angle = i - time.sleep(0.01) -print("Sweep from 180 to 0") -for i in range(180): - servo.angle = 180 - i - time.sleep(0.01) - -print("Move to 90 degrees") -servo.angle = 90 -time.sleep(1) -print("Release servo motor for 10 seconds") -servo.fraction = None -time.sleep(10) - -# You can also specify the movement fractionally. -print("Sweep from 0 to 1.0 fractionally") -fraction = 0.0 -while fraction < 1.0: - servo.fraction = fraction - fraction += 0.01 - time.sleep(0.01) From 04c33fc7b0a5f127762148a27284a70970cacb89 Mon Sep 17 00:00:00 2001 From: william3031 Date: Wed, 2 Oct 2019 06:55:53 +1000 Subject: [PATCH 3/4] renamed files --- ...tor_pca9685_continuous_servo_simpletest.py | 39 ------------ examples/motor_pca9685_dc_motor_simpletest.py | 62 ------------------- .../motor_pca9685_servo_sweep_simpletest.py | 56 ----------------- .../motor_pca9685_stepper_motor_simpletest.py | 39 ------------ examples/motor_servo_sweep.py | 52 ---------------- 5 files changed, 248 deletions(-) delete mode 100644 examples/motor_pca9685_continuous_servo_simpletest.py delete mode 100644 examples/motor_pca9685_dc_motor_simpletest.py delete mode 100644 examples/motor_pca9685_servo_sweep_simpletest.py delete mode 100644 examples/motor_pca9685_stepper_motor_simpletest.py delete mode 100644 examples/motor_servo_sweep.py diff --git a/examples/motor_pca9685_continuous_servo_simpletest.py b/examples/motor_pca9685_continuous_servo_simpletest.py deleted file mode 100644 index 2bd12f5..0000000 --- a/examples/motor_pca9685_continuous_servo_simpletest.py +++ /dev/null @@ -1,39 +0,0 @@ -import time - -from board import SCL, SDA -import busio - -# Import the PCA9685 module. Available in the bundle and here: -# https://github.com/adafruit/Adafruit_CircuitPython_PCA9685 -from adafruit_pca9685 import PCA9685 - -from adafruit_motor import servo - -i2c = busio.I2C(SCL, SDA) - -# Create a simple PCA9685 class instance. -pca = PCA9685(i2c) -# You can optionally provide a finer tuned reference clock speed to improve the accuracy of the -# timing pulses. This calibration will be specific to each board and its environment. See the -# calibration.py example in the PCA9685 driver. -# pca = PCA9685(i2c, reference_clock_speed=25630710) -pca.frequency = 50 - -# The pulse range is 750 - 2250 by default. -servo7 = servo.ContinuousServo(pca.channels[7]) -# If your servo doesn't stop once the script is finished you may need to tune the -# reference_clock_speed above or the min_pulse and max_pulse timings below. -# servo7 = servo.ContinuousServo(pca.channels[7], min_pulse=750, max_pulse=2250) - -print("Forwards") -servo7.throttle = 1 -time.sleep(1) - -print("Backwards") -servo7.throttle = -1 -time.sleep(1) - -print("Stop") -servo7.throttle = 0 - -pca.deinit() diff --git a/examples/motor_pca9685_dc_motor_simpletest.py b/examples/motor_pca9685_dc_motor_simpletest.py deleted file mode 100644 index 01e629f..0000000 --- a/examples/motor_pca9685_dc_motor_simpletest.py +++ /dev/null @@ -1,62 +0,0 @@ -# This example uses an Adafruit Stepper and DC Motor FeatherWing to run a DC Motor. -# https://www.adafruit.com/product/2927 - -import time - -from board import SCL, SDA -import busio - -# Import the PCA9685 module. Available in the bundle and here: -# https://github.com/adafruit/Adafruit_CircuitPython_PCA9685 -from adafruit_pca9685 import PCA9685 - -from adafruit_motor import motor - -i2c = busio.I2C(SCL, SDA) - -# Create a simple PCA9685 class instance for the Motor FeatherWing's default address. -pca = PCA9685(i2c, address=0x60) -pca.frequency = 100 - -# Motor 1 is channels 9 and 10 with 8 held high. -# Motor 2 is channels 11 and 12 with 13 held high. -# Motor 3 is channels 3 and 4 with 2 held high. -# Motor 4 is channels 5 and 6 with 7 held high. - -# DC Motors generate electrical noise when running that can reset the microcontroller in extreme -# cases. A capacitor can be used to help prevent this. The demo uses motor 4 because it worked ok -# in testing without a capacitor. -# See here for more info: https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/faq#faq-13 -pca.channels[7].duty_cycle = 0xffff -motor4 = motor.DCMotor(pca.channels[5], pca.channels[6]) - -print("Forwards slow") -motor4.throttle = 0.5 -print("throttle:", motor4.throttle) -time.sleep(1) - -print("Forwards") -motor4.throttle = 1 -print("throttle:", motor4.throttle) -time.sleep(1) - -print("Backwards") -motor4.throttle = -1 -print("throttle:", motor4.throttle) -time.sleep(1) - -print("Backwards slow") -motor4.throttle = -0.5 -print("throttle:", motor4.throttle) -time.sleep(1) - -print("Stop") -motor4.throttle = 0 -print("throttle:", motor4.throttle) -time.sleep(1) - -print("Spin freely") -motor4.throttle = None -print("throttle:", motor4.throttle) - -pca.deinit() diff --git a/examples/motor_pca9685_servo_sweep_simpletest.py b/examples/motor_pca9685_servo_sweep_simpletest.py deleted file mode 100644 index 037a47f..0000000 --- a/examples/motor_pca9685_servo_sweep_simpletest.py +++ /dev/null @@ -1,56 +0,0 @@ -import time - -from board import SCL, SDA -import busio - -# Import the PCA9685 module. Available in the bundle and here: -# https://github.com/adafruit/Adafruit_CircuitPython_PCA9685 -from adafruit_pca9685 import PCA9685 -from adafruit_motor import servo - -i2c = busio.I2C(SCL, SDA) - -# Create a simple PCA9685 class instance. -pca = PCA9685(i2c) -# You can optionally provide a finer tuned reference clock speed to improve the accuracy of the -# timing pulses. This calibration will be specific to each board and its environment. See the -# calibration.py example in the PCA9685 driver. -# pca = PCA9685(i2c, reference_clock_speed=25630710) -pca.frequency = 50 - -# To get the full range of the servo you will likely need to adjust the min_pulse and max_pulse to -# match the stall points of the servo. -# This is an example for the Sub-micro servo: https://www.adafruit.com/product/2201 -# servo7 = servo.Servo(pca.channels[7], min_pulse=580, max_pulse=2350) -# This is an example for the Micro Servo - High Powered, High Torque Metal Gear: -# https://www.adafruit.com/product/2307 -# servo7 = servo.Servo(pca.channels[7], min_pulse=500, max_pulse=2600) -# This is an example for the Standard servo - TowerPro SG-5010 - 5010: -# https://www.adafruit.com/product/155 -# servo7 = servo.Servo(pca.channels[7], min_pulse=400, max_pulse=2400) -# This is an example for the Analog Feedback Servo: https://www.adafruit.com/product/1404 -# servo7 = servo.Servo(pca.channels[7], min_pulse=600, max_pulse=2500) -# This is an example for the Micro servo - TowerPro SG-92R: https://www.adafruit.com/product/169 -# servo7 = servo.Servo(pca.channels[7], min_pulse=500, max_pulse=2400) - -# The pulse range is 750 - 2250 by default. This range typically gives 135 degrees of -# range, but the default is to use 180 degrees. You can specify the expected range if you wish: -# servo7 = servo.Servo(pca.channels[7], actuation_range=135) -servo7 = servo.Servo(pca.channels[7]) - -# We sleep in the loops to give the servo time to move into position. -for i in range(180): - servo7.angle = i - time.sleep(0.03) -for i in range(180): - servo7.angle = 180 - i - time.sleep(0.03) - -# You can also specify the movement fractionally. -fraction = 0.0 -while fraction < 1.0: - servo7.fraction = fraction - fraction += 0.01 - time.sleep(0.03) - -pca.deinit() diff --git a/examples/motor_pca9685_stepper_motor_simpletest.py b/examples/motor_pca9685_stepper_motor_simpletest.py deleted file mode 100644 index 39020af..0000000 --- a/examples/motor_pca9685_stepper_motor_simpletest.py +++ /dev/null @@ -1,39 +0,0 @@ -# This example uses an Adafruit Stepper and DC Motor FeatherWing to run a Stepper Motor. -# https://www.adafruit.com/product/2927 - -import time - -from board import SCL, SDA -import busio - -# Import the PCA9685 module. Available in the bundle and here: -# https://github.com/adafruit/Adafruit_CircuitPython_PCA9685 -from adafruit_pca9685 import PCA9685 - -from adafruit_motor import stepper - -i2c = busio.I2C(SCL, SDA) - -# Create a simple PCA9685 class instance for the Motor FeatherWing's default address. -pca = PCA9685(i2c, address=0x60) -pca.frequency = 1600 - -# Motor 1 is channels 9 and 10 with 8 held high. -# Motor 2 is channels 11 and 12 with 13 held high. -# Motor 3 is channels 3 and 4 with 2 held high. -# Motor 4 is channels 5 and 6 with 7 held high. - -pca.channels[7].duty_cycle = 0xffff -pca.channels[2].duty_cycle = 0xffff -stepper_motor = stepper.StepperMotor(pca.channels[4], pca.channels[3], # Motor 3 - pca.channels[5], pca.channels[6]) # Motor 4 - -for i in range(100): - stepper_motor.onestep() - time.sleep(0.01) - -for i in range(100): - stepper_motor.onestep(direction=stepper.BACKWARD) - time.sleep(0.01) - -pca.deinit() diff --git a/examples/motor_servo_sweep.py b/examples/motor_servo_sweep.py deleted file mode 100644 index ca99dd0..0000000 --- a/examples/motor_servo_sweep.py +++ /dev/null @@ -1,52 +0,0 @@ -import time -import board -import pulseio -from adafruit_motor import servo - -# create a PWMOut object on the control pin. -pwm = pulseio.PWMOut(board.D5, duty_cycle=0, frequency=50) - -# To get the full range of the servo you will likely need to adjust the min_pulse and max_pulse to -# match the stall points of the servo. -# This is an example for the Sub-micro servo: https://www.adafruit.com/product/2201 -# servo = servo.Servo(pwm, min_pulse=580, max_pulse=2350) -# This is an example for the Micro Servo - High Powered, High Torque Metal Gear: -# https://www.adafruit.com/product/2307 -# servo = servo.Servo(pwm, min_pulse=500, max_pulse=2600) -# This is an example for the Standard servo - TowerPro SG-5010 - 5010: -# https://www.adafruit.com/product/155 -# servo = servo.Servo(pwm, min_pulse=400, max_pulse=2400) -# This is an example for the Analog Feedback Servo: https://www.adafruit.com/product/1404 -# servo = servo.Servo(pwm, min_pulse=600, max_pulse=2500) -# This is an example for the Micro servo - TowerPro SG-92R: https://www.adafruit.com/product/169 -# servo = servo.Servo(pwm, min_pulse=500, max_pulse=2400) - -# The pulse range is 750 - 2250 by default. This range typically gives 135 degrees of -# range, but the default is to use 180 degrees. You can specify the expected range if you wish: -# servo = servo.Servo(board.D5, actuation_range=135) -servo = servo.Servo(pwm) - -# We sleep in the loops to give the servo time to move into position. -print("Sweep from 0 to 180") -for i in range(180): - servo.angle = i - time.sleep(0.01) -print("Sweep from 180 to 0") -for i in range(180): - servo.angle = 180 - i - time.sleep(0.01) - -print("Move to 90 degrees") -servo.angle = 90 -time.sleep(1) -print("Release servo motor for 10 seconds") -servo.fraction = None -time.sleep(10) - -# You can also specify the movement fractionally. -print("Sweep from 0 to 1.0 fractionally") -fraction = 0.0 -while fraction < 1.0: - servo.fraction = fraction - fraction += 0.01 - time.sleep(0.01) From 3b6f3df56dc6fea6b56e5ea7b562766657dca39d Mon Sep 17 00:00:00 2001 From: William Lai <44103957+william3031@users.noreply.github.com> Date: Wed, 2 Oct 2019 07:00:01 +1000 Subject: [PATCH 4/4] renamed files closes #31 --- examples/motor_pca9685_continuous_servo.py | 39 ++++++++++++++ examples/motor_pca9685_dc_motor.py | 62 ++++++++++++++++++++++ examples/motor_pca9685_servo_sweep.py | 56 +++++++++++++++++++ examples/motor_pca9685_stepper.py | 39 ++++++++++++++ examples/motor_servo_sweep_simpletest.py | 52 ++++++++++++++++++ 5 files changed, 248 insertions(+) create mode 100644 examples/motor_pca9685_continuous_servo.py create mode 100644 examples/motor_pca9685_dc_motor.py create mode 100644 examples/motor_pca9685_servo_sweep.py create mode 100644 examples/motor_pca9685_stepper.py create mode 100644 examples/motor_servo_sweep_simpletest.py diff --git a/examples/motor_pca9685_continuous_servo.py b/examples/motor_pca9685_continuous_servo.py new file mode 100644 index 0000000..5bb03e4 --- /dev/null +++ b/examples/motor_pca9685_continuous_servo.py @@ -0,0 +1,39 @@ +import time + +from board import SCL, SDA +import busio + +# Import the PCA9685 module. Available in the bundle and here: +# https://github.com/adafruit/Adafruit_CircuitPython_PCA9685 +from adafruit_pca9685 import PCA9685 + +from adafruit_motor import servo + +i2c = busio.I2C(SCL, SDA) + +# Create a simple PCA9685 class instance. +pca = PCA9685(i2c) +# You can optionally provide a finer tuned reference clock speed to improve the accuracy of the +# timing pulses. This calibration will be specific to each board and its environment. See the +# calibration.py example in the PCA9685 driver. +# pca = PCA9685(i2c, reference_clock_speed=25630710) +pca.frequency = 50 + +# The pulse range is 750 - 2250 by default. +servo7 = servo.ContinuousServo(pca.channels[7]) +# If your servo doesn't stop once the script is finished you may need to tune the +# reference_clock_speed above or the min_pulse and max_pulse timings below. +# servo7 = servo.ContinuousServo(pca.channels[7], min_pulse=750, max_pulse=2250) + +print("Forwards") +servo7.throttle = 1 +time.sleep(1) + +print("Backwards") +servo7.throttle = -1 +time.sleep(1) + +print("Stop") +servo7.throttle = 0 + +pca.deinit() diff --git a/examples/motor_pca9685_dc_motor.py b/examples/motor_pca9685_dc_motor.py new file mode 100644 index 0000000..5cd8e21 --- /dev/null +++ b/examples/motor_pca9685_dc_motor.py @@ -0,0 +1,62 @@ +# This example uses an Adafruit Stepper and DC Motor FeatherWing to run a DC Motor. +# https://www.adafruit.com/product/2927 + +import time + +from board import SCL, SDA +import busio + +# Import the PCA9685 module. Available in the bundle and here: +# https://github.com/adafruit/Adafruit_CircuitPython_PCA9685 +from adafruit_pca9685 import PCA9685 + +from adafruit_motor import motor + +i2c = busio.I2C(SCL, SDA) + +# Create a simple PCA9685 class instance for the Motor FeatherWing's default address. +pca = PCA9685(i2c, address=0x60) +pca.frequency = 100 + +# Motor 1 is channels 9 and 10 with 8 held high. +# Motor 2 is channels 11 and 12 with 13 held high. +# Motor 3 is channels 3 and 4 with 2 held high. +# Motor 4 is channels 5 and 6 with 7 held high. + +# DC Motors generate electrical noise when running that can reset the microcontroller in extreme +# cases. A capacitor can be used to help prevent this. The demo uses motor 4 because it worked ok +# in testing without a capacitor. +# See here for more info: https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/faq#faq-13 +pca.channels[7].duty_cycle = 0xffff +motor4 = motor.DCMotor(pca.channels[5], pca.channels[6]) + +print("Forwards slow") +motor4.throttle = 0.5 +print("throttle:", motor4.throttle) +time.sleep(1) + +print("Forwards") +motor4.throttle = 1 +print("throttle:", motor4.throttle) +time.sleep(1) + +print("Backwards") +motor4.throttle = -1 +print("throttle:", motor4.throttle) +time.sleep(1) + +print("Backwards slow") +motor4.throttle = -0.5 +print("throttle:", motor4.throttle) +time.sleep(1) + +print("Stop") +motor4.throttle = 0 +print("throttle:", motor4.throttle) +time.sleep(1) + +print("Spin freely") +motor4.throttle = None +print("throttle:", motor4.throttle) + +pca.deinit() diff --git a/examples/motor_pca9685_servo_sweep.py b/examples/motor_pca9685_servo_sweep.py new file mode 100644 index 0000000..ee2f20a --- /dev/null +++ b/examples/motor_pca9685_servo_sweep.py @@ -0,0 +1,56 @@ +import time + +from board import SCL, SDA +import busio + +# Import the PCA9685 module. Available in the bundle and here: +# https://github.com/adafruit/Adafruit_CircuitPython_PCA9685 +from adafruit_pca9685 import PCA9685 +from adafruit_motor import servo + +i2c = busio.I2C(SCL, SDA) + +# Create a simple PCA9685 class instance. +pca = PCA9685(i2c) +# You can optionally provide a finer tuned reference clock speed to improve the accuracy of the +# timing pulses. This calibration will be specific to each board and its environment. See the +# calibration.py example in the PCA9685 driver. +# pca = PCA9685(i2c, reference_clock_speed=25630710) +pca.frequency = 50 + +# To get the full range of the servo you will likely need to adjust the min_pulse and max_pulse to +# match the stall points of the servo. +# This is an example for the Sub-micro servo: https://www.adafruit.com/product/2201 +# servo7 = servo.Servo(pca.channels[7], min_pulse=580, max_pulse=2350) +# This is an example for the Micro Servo - High Powered, High Torque Metal Gear: +# https://www.adafruit.com/product/2307 +# servo7 = servo.Servo(pca.channels[7], min_pulse=500, max_pulse=2600) +# This is an example for the Standard servo - TowerPro SG-5010 - 5010: +# https://www.adafruit.com/product/155 +# servo7 = servo.Servo(pca.channels[7], min_pulse=400, max_pulse=2400) +# This is an example for the Analog Feedback Servo: https://www.adafruit.com/product/1404 +# servo7 = servo.Servo(pca.channels[7], min_pulse=600, max_pulse=2500) +# This is an example for the Micro servo - TowerPro SG-92R: https://www.adafruit.com/product/169 +# servo7 = servo.Servo(pca.channels[7], min_pulse=500, max_pulse=2400) + +# The pulse range is 750 - 2250 by default. This range typically gives 135 degrees of +# range, but the default is to use 180 degrees. You can specify the expected range if you wish: +# servo7 = servo.Servo(pca.channels[7], actuation_range=135) +servo7 = servo.Servo(pca.channels[7]) + +# We sleep in the loops to give the servo time to move into position. +for i in range(180): + servo7.angle = i + time.sleep(0.03) +for i in range(180): + servo7.angle = 180 - i + time.sleep(0.03) + +# You can also specify the movement fractionally. +fraction = 0.0 +while fraction < 1.0: + servo7.fraction = fraction + fraction += 0.01 + time.sleep(0.03) + +pca.deinit() diff --git a/examples/motor_pca9685_stepper.py b/examples/motor_pca9685_stepper.py new file mode 100644 index 0000000..cb431ce --- /dev/null +++ b/examples/motor_pca9685_stepper.py @@ -0,0 +1,39 @@ +# This example uses an Adafruit Stepper and DC Motor FeatherWing to run a Stepper Motor. +# https://www.adafruit.com/product/2927 + +import time + +from board import SCL, SDA +import busio + +# Import the PCA9685 module. Available in the bundle and here: +# https://github.com/adafruit/Adafruit_CircuitPython_PCA9685 +from adafruit_pca9685 import PCA9685 + +from adafruit_motor import stepper + +i2c = busio.I2C(SCL, SDA) + +# Create a simple PCA9685 class instance for the Motor FeatherWing's default address. +pca = PCA9685(i2c, address=0x60) +pca.frequency = 1600 + +# Motor 1 is channels 9 and 10 with 8 held high. +# Motor 2 is channels 11 and 12 with 13 held high. +# Motor 3 is channels 3 and 4 with 2 held high. +# Motor 4 is channels 5 and 6 with 7 held high. + +pca.channels[7].duty_cycle = 0xffff +pca.channels[2].duty_cycle = 0xffff +stepper_motor = stepper.StepperMotor(pca.channels[4], pca.channels[3], # Motor 3 + pca.channels[5], pca.channels[6]) # Motor 4 + +for i in range(100): + stepper_motor.onestep() + time.sleep(0.01) + +for i in range(100): + stepper_motor.onestep(direction=stepper.BACKWARD) + time.sleep(0.01) + +pca.deinit() diff --git a/examples/motor_servo_sweep_simpletest.py b/examples/motor_servo_sweep_simpletest.py new file mode 100644 index 0000000..c911fb6 --- /dev/null +++ b/examples/motor_servo_sweep_simpletest.py @@ -0,0 +1,52 @@ +import time +import board +import pulseio +from adafruit_motor import servo + +# create a PWMOut object on the control pin. +pwm = pulseio.PWMOut(board.D5, duty_cycle=0, frequency=50) + +# To get the full range of the servo you will likely need to adjust the min_pulse and max_pulse to +# match the stall points of the servo. +# This is an example for the Sub-micro servo: https://www.adafruit.com/product/2201 +# servo = servo.Servo(pwm, min_pulse=580, max_pulse=2350) +# This is an example for the Micro Servo - High Powered, High Torque Metal Gear: +# https://www.adafruit.com/product/2307 +# servo = servo.Servo(pwm, min_pulse=500, max_pulse=2600) +# This is an example for the Standard servo - TowerPro SG-5010 - 5010: +# https://www.adafruit.com/product/155 +# servo = servo.Servo(pwm, min_pulse=400, max_pulse=2400) +# This is an example for the Analog Feedback Servo: https://www.adafruit.com/product/1404 +# servo = servo.Servo(pwm, min_pulse=600, max_pulse=2500) +# This is an example for the Micro servo - TowerPro SG-92R: https://www.adafruit.com/product/169 +# servo = servo.Servo(pwm, min_pulse=500, max_pulse=2400) + +# The pulse range is 750 - 2250 by default. This range typically gives 135 degrees of +# range, but the default is to use 180 degrees. You can specify the expected range if you wish: +# servo = servo.Servo(board.D5, actuation_range=135) +servo = servo.Servo(pwm) + +# We sleep in the loops to give the servo time to move into position. +print("Sweep from 0 to 180") +for i in range(180): + servo.angle = i + time.sleep(0.01) +print("Sweep from 180 to 0") +for i in range(180): + servo.angle = 180 - i + time.sleep(0.01) + +print("Move to 90 degrees") +servo.angle = 90 +time.sleep(1) +print("Release servo motor for 10 seconds") +servo.fraction = None +time.sleep(10) + +# You can also specify the movement fractionally. +print("Sweep from 0 to 1.0 fractionally") +fraction = 0.0 +while fraction < 1.0: + servo.fraction = fraction + fraction += 0.01 + time.sleep(0.01)