From cafc77721f81a4d5d48dc63da69dd91dabe7924b Mon Sep 17 00:00:00 2001 From: John Park Date: Mon, 15 Feb 2021 09:33:28 -0800 Subject: [PATCH 1/2] added h-bridge dc motor example --- examples/motor_h-bridge_dc_motor.py | 69 +++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 examples/motor_h-bridge_dc_motor.py diff --git a/examples/motor_h-bridge_dc_motor.py b/examples/motor_h-bridge_dc_motor.py new file mode 100644 index 0000000..c88640a --- /dev/null +++ b/examples/motor_h-bridge_dc_motor.py @@ -0,0 +1,69 @@ +# This example uses an L9110 H-bridge driver to run a DC Motor using two PWM pins. +# https://www.adafruit.com/product/4489 + +# Hardware setup: +# DC motor via L9110 H-bridge driver on two PWM pins that are on their own channels +# e.g., RP2040 Pico pins GP28, GP27 + +import time +import board +import pwmio +from adafruit_motor import motor + +PWM_PIN_A = board.GP28 # pick any pwm pins on their own channels +PWM_PIN_B = board.GP27 + +# DC motor setup +# DC Motors generate electrical noise when running that can reset the microcontroller in extreme +# cases. A capacitor can be used to help prevent this. +pwm_a = pwmio.PWMOut(PWM_PIN_A, frequency=50) +pwm_b = pwmio.PWMOut(PWM_PIN_B, frequency=50) +motor1 = motor.DCMotor(pwm_a, pwm_b) + +print("***DC motor test***") + +print("\nForwards slow") +motor1.throttle = 0.5 +print(" throttle:", motor1.throttle) +time.sleep(1) + +print("\nStop") +motor1.throttle = 0 +print(" throttle:", motor1.throttle) +time.sleep(1) + +print("\nForwards") +motor1.throttle = 1.0 +print(" throttle:", motor1.throttle) +time.sleep(1) + +print("\nStop") +motor1.throttle = 0 +print("throttle:", motor1.throttle) +time.sleep(1) + +print("\nBackwards") +motor1.throttle = -1.0 +print(" throttle:", motor1.throttle) +time.sleep(1) + +print("\nStop") +motor1.throttle = 0 +print("throttle:", motor1.throttle) +time.sleep(1) + +print("\nBackwards slow") +motor1.throttle = -0.5 +print(" throttle:", motor1.throttle) +time.sleep(1) + +print("\nStop") +motor1.throttle = 0 +print(" throttle:", motor1.throttle) +time.sleep(1) + +print("\nSpin freely") +motor1.throttle = None +print(" throttle:", motor1.throttle) + +print("\n***Motor test is complete***") From 638fe6cf09389e40a762e3a1e5e3b01732a2b7d1 Mon Sep 17 00:00:00 2001 From: John Park Date: Mon, 15 Feb 2021 09:43:08 -0800 Subject: [PATCH 2/2] added copyright notice --- examples/motor_h-bridge_dc_motor.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/motor_h-bridge_dc_motor.py b/examples/motor_h-bridge_dc_motor.py index c88640a..d15e38f 100644 --- a/examples/motor_h-bridge_dc_motor.py +++ b/examples/motor_h-bridge_dc_motor.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + # This example uses an L9110 H-bridge driver to run a DC Motor using two PWM pins. # https://www.adafruit.com/product/4489