DietPi icon indicating copy to clipboard operation
DietPi copied to clipboard

set GPIO (for specified PIN) level on boot (or power on)

Open almirus opened this issue 2 years ago • 5 comments

Creating a feature request

Is your feature request related to a problem? Please describe:

  • I want to set pin 37 (GPIOAO_9) when booting into HIGH level. There is connected switcher for HDMI display (default is OFF) and not showing booting process.

almirus avatar Jul 18 '22 14:07 almirus

Which SBC and Debian version are you using?

MichaIng avatar Jul 22 '22 13:07 MichaIng

radxa zero Bullseye

almirus avatar Jul 22 '22 14:07 almirus

Please try with libgpio:

apt install gpiod
gpioinfo

MichaIng avatar Jul 31 '22 18:07 MichaIng

yes but how to set gpio before load OS (or while booting)?

almirus avatar Aug 01 '22 16:08 almirus

yes but how to set gpio before load OS (or while booting)?

Before loading the OS you obviously have almost nothing running other than the initialization firmware of your board. OS booting is a multistep process, so "while booting" means you need to define exactly at which step your gpio action is needed (ie define precedence, need it before X Y and Z occurs). Did you try issuing the gpio command in /etc/rc.local or via a custom systemd entry?

WolfganP avatar Aug 01 '22 17:08 WolfganP

udev rules should be a clever way to assign GPIO states as fast as the device is detected by the kernel.

MichaIng avatar Sep 18 '22 13:09 MichaIng

@MichaIng hello, do you have any example for this?

almirus avatar Sep 18 '22 13:09 almirus

Like so, setting GPIO 21 of chip 0, as fast as GPIO chip 0 is added/detected:

echo 'SUBSYSTEM=="gpio", KERNEL=="gpiochip0", ACTION=="add", RUN+="/usr/bin/gpioset gpiochip0 21=1"' > /etc/udev/rules.d/99-gpio.rules

MichaIng avatar Sep 18 '22 13:09 MichaIng

Did this work for you?

MichaIng avatar Nov 24 '22 12:11 MichaIng

Marking as closed due to outstanding reply. Please reopen when you have feedback on the suggested udev rule.

MichaIng avatar Dec 30 '22 04:12 MichaIng