raspberry-piraspberry-pi5

Raspberry Pi 5 GPIOZERO


I just started learning how to use the raspberry pi. One of the first issues I encountered with the raspberry pi was that the most common library (the one that all tutorials use) RPi.GPIO does not work with the raspberry pi 5 due to hardware changes. This means I have to use a library that supports the new hardware like the gpiod or GPIOZERO. I was told to use GPIOZERO as it is more begginer friendly and has more features like pwm and built in pull up resistors.

Upon trying to turn on a led with the GPIOZERO library, I encountered an issue where my code wasn’t making the gpio pin output any voltage (I tested this with a multimeter). Here is my python code:

from gpiozero import LED
led = LED(17)
led.on()

When I try to use the gpiod library it works perfectly fine: Here is the code:

import gpiod
LED_PIN = 17
chip = gpiod.Chip('gpiochip4')
led_line = chip.get_line(LED_PIN)
led_line.request(consumer="LED", type=gpiod.LINE_REQ_DIR_OUT)
led_line.set_value(1)

The reason why I don't want to use the gpiod library in the long term is that I'm pretty sure it doesn't support internal pull up resistors or pwm.

I wonder if it is an issue with the new chip system on the raspberry pi 5. Does anyone know how I can fix this?

I tried switching around the gpio pin from 17 to 11, nothing changed, I've tried researching if it might be something to do with the new chip system, but I found that this exact code and wiring worked for other Pi 5 users.


Solution

  • After several attempts to solve this problem, I found that the solution is in cat /sys/kernel/debug/gpio this will show the pinout of pi5 this is an example

    gpio-586 (GPIO15 ) gpio-587 (GPIO16 ) gpio-588 (GPIO17 ) gpio-589 (GPIO18 ) gpio-590 (GPIO19 ) gpio-591 (GPIO20 ) gpio-592 (GPIO21 ) gpio-593 (GPIO22 ) so as you can see that the GPIO17 is gpio-588 so when i used it in my code it worked perfectly this was my code

    const Gpio = require('onoff').Gpio; // Import the onoff library
    //const led = new Gpio(17, 'out'); 
    const led = new Gpio(588, 'out');    // Set GPIO pin 588 instead of 17
    
    // Turn the LED on
    led.writeSync(1);
    console.log('LED ON');
    
    // Wait for 1 second, then turn the LED off
    setTimeout(() => {
    led.writeSync(0);  // Turn the LED off
    console.log('LED OFF');
    led.unexport();     // Clean up GPIO
     }, 1000);
    

    so the line will be

    const led = new Gpio(588, 'out');

    instead of const led = new Gpio(17, 'out');