reTerminal - permission for keys and LEDs - udev rule?

Hello,
I use the python module seed_python_reterminal to control the buttons and the LED, this only works if I run the script with root.

sudo chgrp -R gpio /sys/devices/platform/leds/
sudo chmod -R 775 /sys/devices/platform/leds/

fixes the problem until the next reboot, after that only root has access again.

Is there a udev rule that always overwrites it ? if yes, which one is it ?

Create a user group and add your user, example:

 sudo groupadd leds
 sudo usermod -aG leds pi

Create a udev rule, ex:

sudo nano /etc/udev/rules.d/01-leds.rules

# Fill it with:
# Allow users of group leds to access all leds
SUBSYSTEM=="leds", ACTION=="add", RUN+="/bin/chgrp -R leds /sys%p", RUN+="/bin/chmod -R g=u /sys%p"
SUBSYSTEM=="leds", ACTION=="change", ENV{TRIGGER}!="none", RUN+="/bin/chgrp -R leds /sys%p", RUN+="/bin/chmod -R g=u /sys%p"

Reboot and be happy

To address the issue of permissions resetting after each reboot, you can create a Udev rule to set the correct permissions for your LED control files. Here’s how to do it:

  1. Create a Udev rule file. You can use a text editor to create a new rule file, such as:
sudo nano /etc/udev/rules.d/99-custom-led-permissions.rules


2. In the rule file, add the following line to set the desired permissions:

```shell
SUBSYSTEM=="leds", KERNEL=="leds", GROUP="gpio", MODE="0775"


This rule will ensure that the "gpio" group has the required permissions on LED control files.

3. Save the file and exit the text editor.

4. Reload the Udev rules to apply the changes:

```shell
sudo udevadm control --reload


Now, your custom Udev rule should set the correct permissions for LED control files on each reboot, allowing your Python script to work without root privileges.
1 Like

Create a udev rule to persistently set permissions for GPIO. Add a file, e.g., 99-gpio.rules in /etc/udev/rules.d/ with:

SUBSYSTEM==“leds”, KERNEL==“leds*”, ACTION==“add”, GROUP=“gpio”, MODE=“0775”
Then reload udev rules:

sudo udevadm control --reload-rules
sudo udevadm trigger
Modern Led Light