raspberry pi 5 convert rpi.GPIO code to gpiod

March 31, 2024, 09:54

enclave.dll

i've got this example code
py
import RPi.GPIO as GPIO

pins = [18, 23, 24]

pin_led_states = [
  [1, 0, -1], # A
  [0, 1, -1], # B
  [-1, 1, 0], # C
  [-1, 0, 1], # D
  [1, -1, 0], # E
  [0, -1, 1]  # F
]

GPIO.setmode(GPIO.BCM)

def set_pin(pin_index, pin_state):
    if pin_state == -1:
        GPIO.setup(pins[pin_index], GPIO.IN)
    else:
        GPIO.setup(pins[pin_index], GPIO.OUT)
        GPIO.output(pins[pin_index], pin_state)

def light_led(led_number):
    for pin_index, pin_state in enumerate(pin_led_states[led_number]):
        set_pin(pin_index, pin_state)

set_pin(0, -1)
set_pin(1, -1)
set_pin(2, -1)

while True:
    x = int(input("Pin (0 to 5):"))
    light_led(x)
and i would like someone who understands better than me to help convert it to gpiod the gpiod documantation is a mess. Your help will be appreciated!

enclave.dll

Hello can anybody help?

k9t33n

i do not no gpiod, no.

oops.se

When you don't provides URL and don't describe what you think is a mess then I don't bother to look at it. If you provide info and more than general comments the chance is higher that someone gets interested and assist you.

enclave.dll

okay i am sorry i dont have the link right now ill find it later

enclave.dll

why not rpi.GPIO doesnt work on rpi 5

k9t33n

have you tried gpio zero?

enclave.dll

oh, no i have not

enclave.dll

i only know the rpi.GPIO module and how it works if you know gpio zero could you translate the code because i dont have time to read the documandation carefully?

k9t33n

I don't really have the most of time for that unfortunately. I also do not like spoon feeding.

enclave.dll

you are right i dont like it either ill do my best to read the documandation and try it