From aa83f5c957f3754b8bf9d8fad81edadcec628c3f Mon Sep 17 00:00:00 2001 From: "Joseph T. Foley" Date: Thu, 2 Jul 2026 16:56:44 +0000 Subject: [PATCH] got an LED to blink on GPIO18 --- lgpio/blink.py | 19 +++++++++++++++++++ lgpio/pwm-test.py | 25 +++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100755 lgpio/blink.py create mode 100755 lgpio/pwm-test.py diff --git a/lgpio/blink.py b/lgpio/blink.py new file mode 100755 index 0000000..7c6b782 --- /dev/null +++ b/lgpio/blink.py @@ -0,0 +1,19 @@ +#!/usr/bin/python +# From https://raspberry.tips/en/raspberrypi-tutorials/raspberry-pi-gpio-python +import lgpio +import time + +# Open GPIO chip (0 = /dev/gpiochip0, on Pi 5 gpiochip4 also possible) +h = lgpio.gpiochip_open(0) + +try: + lgpio.gpio_claim_output(h, 18) # GPIO18 (pin 12) as output (MOTA1) + + for _ in range(5): + lgpio.gpio_write(h, 18, 1) # HIGH + time.sleep(0.5) + lgpio.gpio_write(h, 18, 0) # LOW + time.sleep(0.5) + +finally: + lgpio.gpiochip_close(h) # Always close! diff --git a/lgpio/pwm-test.py b/lgpio/pwm-test.py new file mode 100755 index 0000000..e44f005 --- /dev/null +++ b/lgpio/pwm-test.py @@ -0,0 +1,25 @@ +#!/usr/bin/python +# From https://raspberry.tips/en/raspberrypi-tutorials/raspberry-pi-gpio-python +import lgpio +import time + +# Open GPIO chip (0 = /dev/gpiochip0, on Pi 5 gpiochip4 also possible) +h = lgpio.gpiochip_open(0) + +try: + lgpio.gpio_claim_output(h, 16) # GPIO16 as output (MOTA2) + lgpio.gpio_write(h, 16, 0) # LOW + + # Hardware PWM on GPIO18 (pin 12) must be PWM-capable + # Frequency: 1000 Hz, duty cycle: 50% + lgpio.tx_pwm(h, 18, 1000, 50) + time.sleep(2) + + # Reduce duty cycle to 20% + lgpio.tx_pwm(h, 18, 1000, 20) + time.sleep(2) + + lgpio.tx_pwm(h, 18, 0, 0) # Stop PWM + +finally: + lgpio.gpiochip_close(h) # Always close!