From f79b9985db52610662e7ed162f13c98f6a16594b Mon Sep 17 00:00:00 2001 From: "Joseph T. Foley" Date: Sat, 4 Jul 2026 19:34:38 +0000 Subject: [PATCH] The motor sweeps through the speeds (tested) --- lgpio/motor-test.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 lgpio/motor-test.py diff --git a/lgpio/motor-test.py b/lgpio/motor-test.py new file mode 100755 index 0000000..c7893fb --- /dev/null +++ b/lgpio/motor-test.py @@ -0,0 +1,34 @@ +#!/usr/bin/python +# This test assumes you are trying to control a motor through a DRV8833 motor +# controller chip. This general approach should work for other motors as well. +import lgpio +import time + +# pin assignments +gpio_pwm = 18 #MOTA1 +gpio_reverse = 16 #MOTA2 +gpio_notsleep = 24 #MSLEEP +# parameters +pwm_freq = 1000 + + +h = lgpio.gpiochip_open(0) +try: + lgpio.gpio_claim_output(h, gpio_reverse) + lgpio.gpio_claim_output(h, gpio_notsleep) + lgpio.gpio_write(h, gpio_reverse, 0) # low on reverse pin to turn off h-bridge MOTA2 + lgpio.gpio_write(h, gpio_notsleep, 1) # high on /sleep to enable both h-bridges + + while True: + for pwm_level in range(0,100): + lgpio.tx_pwm(h, gpio_pwm, pwm_freq, pwm_level) + pwm_level += 10 + time.sleep(0.05) + for pwm_level in range(100,0,-1): + lgpio.tx_pwm(h, gpio_pwm, pwm_freq, pwm_level) + pwm_level += 10 + time.sleep(0.05) + +finally: + lgpio.gpio_write(h, gpio_notsleep, 1) # high on /sleep to disable + lgpio.gpiochip_close(h) # Always close!