Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5526

General discussion • Re: pi5 gpio pin voltage not toggling low

$
0
0
I can confirm that. I have similar programs that I wrote for my Raspberry Pi 5.
The first uses the gpiod library while the second uses the lgpio library.
Note both gpiod and lgpio use BCM so PIN 17 = BCM GPIO17 = board pin 11.

Code:

#!/usr/bin/env python3import gpiodfrom time import sleepPIN = 17def setup():    chipname = "gpiochip4"    chip = gpiod.Chip(chipname)    Relay = chip.get_line(PIN)    Relay.request(consumer="LED", type=gpiod.LINE_REQ_DIR_OUT)    return Relaydef set(val):    if val:        print("Relay ON")        relay.set_value(False)    else:        print("Relay OFF")        relay.set_value(True)def loop():    while True:        set(True)        sleep(1)        set(False)        sleep(1) def destroy():    relay.set_value(True)    relay.release()    if __name__ == "__main__":    relay = setup()    try:        loop()    except KeyboardInterrupt:        destroy()

Code:

#!/usr/bin/env python3import lgpiofrom time import sleepRelayPin = 17    # pin11def setup():    chip = lgpio.gpiochip_open(4)    lgpio.gpio_claim_output(chip, RelayPin)    return chipdef set(val):    if val:        print("Setting relay: ON")        lgpio.gpio_write(chip, RelayPin, False)    else:        print("Setting relay: OFF")        lgpio.gpio_write(chip, RelayPin, True)def loop():    while True:        #'...relayd on'        set(True)        sleep(3)        #'relay off...'        set(False)        sleep(3)        def destroy():    set(False)if __name__ == '__main__':     # Program start from here    chip = setup()    try:        loop()    except KeyboardInterrupt:  # When 'Ctrl+C' is pressed, the child program destroy() will be  executed.        destroy()

Statistics: Posted by MisterEd — Tue Mar 19, 2024 5:06 pm



Viewing all articles
Browse latest Browse all 5526

Trending Articles