RPi4 GPIO using in LibreELEC

  • Dear All,


    Is it possible use GPIO pins with LibreELEC on RPi4? My idea is use some GPIO pin for LED in the power button for signaling that system is running. Now I´m using only standard shut down funtion in Kodi and RPi4 weak-up function with button on GPIO pins 5 and 6 made by this manual:

    How to Add a Power Button to Your Raspberry Pi - howchoo


    All manuals I found for this is for NOOBS but not for LibreELEC


    Thanks


    Radek

  • I've been installed a power button and a status LED on my RPi3B+. This works for RPi4B, too. After SSH login, you can use the nano editor to create or edit all necessary files.


    Power Button Hardware Part

    Use GPIO03 (Pin #05) and the opposite Ground (Pin #06) to connect a push button for power on / off.


    Power Button Scripting Part

    Add dtoverlay=gpio-shutdown to config.txt.

    Switching off will let the shutdown menu appear.

    To shutdown instantly instead, create this /storage/.kodi/userdata/keymaps/keyboard.xml:

    Code
    <keymap>
        <global>
            <keyboard>
                <power>shutdown</power>
            </keyboard>
        </global>
    </keymap>


    Status LED Hardware Part

    Use GPIO13 (Pin #33) and the opposite Ground (Pin #34) to connect an LED. Also use a resistor with 330 Ohms or more.


    Status LED Add-On Part

    Install the Raspberry Pi Tools add-on to use the GPIO programming library in Python.


    Status LED Scripting Part

    The status LED will be triggered from autostart.sh, which calls the Python script status_led.py . It will switch off automatically at shutdown, no script action required for this part.


    Create this /storage/.config/autostart.sh :

    Bash
    #!/bin/sh
    
    (
        python /storage/scripts/status_led.py
    ) &


    Create this /storage/scripts/status_led.py :

    Reboot.

    Flexin' vinyl, jammin' break beats. 8)

    Edited 6 times, last by Da Flex ().

  • Thank you for this procedure. I did all from the list, use the same GPIO pin and it´s working. Thank you for your help :thumbup:


    More informations about this project:

    Raspberry Pi4 case with LED power button by Foxbiker - Thingiverse


    How it´s work:

    External Content www.youtube.com
    Content embedded from external sources will not be displayed without your consent.
    Through the activation of external content, you agree that personal data may be transferred to third party platforms. We have provided more information on this in our privacy policy.

    Edited once, last by Foxbiker: Aditional informations ().

  • Da Flex

    Thank you for linking your work on the other post.

    1. Can I add "dtoverlay=gpio-shutdown" in config.txt from SD card while it's plugged to desktop using Notepad++

    2. The pin 33 and pin 34 will work for ON/OFF plus led status?

    3. For the executed command (chmod +x ), is there a way without the need command from terminal? Like, right click the file (.py & .sh) and change something in Properties?


    is "/storage" mean there's a folder inside SD card name "/storage"?

  • 1. Can I add "dtoverlay=gpio-shutdown" in config.txt from SD card while it's plugged to desktop using Notepad++

    Yes.

    2. The pin 33 and pin 34 will work for ON/OFF plus led status?

    No, that's just for the LED. Use pin 5 and 6 for the power button. If you only want the power button, then you can ignore the LED part.

    3. For the executed command (chmod +x ), is there a way without the need command from terminal? Like, right click the file (.py & .sh) and change something in Properties?

    On a Linux PC (maybe OSX, too), making files executable by right-click-option should work fine. You maybe need root status to do this. I'm not 100% sure whether chmod +x is necessary, so you can try it without this step first.

    is "/storage" mean there's a folder inside SD card name "/storage"?

    When you plug the microSD card into your desktop PC, then the /storage folder will be represented by the STORAGE partition.

    Flexin' vinyl, jammin' break beats. 8)

    Edited once, last by Da Flex ().

  • Hello friends ! for two days i am trying to put the power button on my rpi 4b + libreelec 9.02 following this tutorial but it is not working! I need help, I did everything as described so I could not put the files as executable because the command described generates an error !! what do I need to do? when I press the push button nothing happens!

    Foxbiker and Da Flex

  • Hello friends ! for two days i am trying to put the power button on my rpi 4b + libreelec 9.02 following this tutorial but it is not working! I need help, I did everything as described so I could not put the files as executable because the command described generates an error !! what do I need to do? when I press the push button nothing happens!

    Foxbiker and Da Flex

    Please show the command you try and the error message you get.

    Flexin' vinyl, jammin' break beats. 8)

  • Da Flex I found the power button problem! first I had to update the boot firmware, then it started working to restart, looking in the forum I found the error in the instruction dtoverlay = gpio-shutdown is wrong, it should be written: dtoverlay gpio-shutdown so it worked! now the led script is not working! I don't know why he doesn't perform!

  • You did a typo, it's chmod +x, not chmod + x.


    LE does the firmware update. If you do it yourself, then stuff like a change of the config.txt syntax can happen. So I don't suggest this.


    Is there any cause why you don't update to the latest LE version?

    Flexin' vinyl, jammin' break beats. 8)

  • Da Flex Before updating the firmware, the command for wakeup did not work, but after I updated the bootloader, I turned the LE off and when I used the power button it turned on, but it didn't! after I changed the command “dtoverlay” as described above he started to turn LE off by the power button! but now the led script is not working! I would like help! do you have a log where you can see if the script is being executed by autostart.sh?

  • I updated the boot firmware and not the LE!

    That's what I mean, too. LE updates include boot firmware updates, whenever necessary.


    You can verify script execution by creating a file. Do an internet research to learn how to do so.


    I can only continue to help you, if you answer my questions. Investing energy to get the latest boot firmware, but ignoring LE updates is a mismatch to me. LE updates are more important to get stability and best performance.


    If you did a typo like at chmod +x, you should inform us about it's correction. Other users will benefit while reading the thread.

    Flexin' vinyl, jammin' break beats. 8)

  • Da Flex

    Does this work incase LE is frozen?

    I mean is it only sending a clean shutdown command?

    Does a long press do a reset?

    Might need the reset button through the RUN pins for reset..

  • Mario77 No, the dtoverlay implementation only does the shutdown, no reset by long-press. I did a test to be sure.


    Here is the original implementation that I used before dtoverlay. You can implement reset by long-press easily from there:

    Flexin' vinyl, jammin' break beats. 8)

  • Da Flex

    Thanks for your reply..

    That's a shame.

    So if I understand correctly..

    connections are gpio 3 and ground for switch and gpio 13 and ground for led..no transistors involved to run led?Perhaps it might need a resistance?Is there enough power in gpio 13 to run LED?

  • Mario77 Yes, that's right. I use a resistor with the LED, but I forgot the value. You'll find on the web, how to connect an LED to GPIO.

    Flexin' vinyl, jammin' break beats. 8)