[Solved]Help with GPIO not working!

Good morning, everyone.

I am new to DietPi and I have a problem that I cannot solve.

Furthermore, as I do not know English, I am forced to ask for help here, as there is no forum in Italian, using an online translator!

So please excuse me if something is not understandable!!! :(((

I have an old Raspberry Pi 1B+ that I have set up as a print server.

With Raspbian Bullseye Lite, everything works fine, but it is very slow.

So I wanted to try DietPi, which is actually much faster both at start-up/shutdown and when sending documents to print.

However, I am having problems running the script.py that I created to turn on an LED from the GPIO to see when the system is ready. Furthermore, the command to listen to GPIO 3 and invoke poweroff, which works perfectly in Bullseye, does not work either.

When I try to run the script from /Home/DietPi/, I get this error:

Traceback (most recent call last):

File ā€˜/home/dietpi/led.py’, line 1, in <module>

import RPi.GPIO as GPIO

File ā€˜/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py’, line 927, in <module>

RPI_INFO = _get_rpi_info()

^^^^^^^^^^^^^^^

File ā€˜/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py’, line 428, in _get_rpi_info

raise NotImplementedError(

NotImplementedError: This module does not understand old-style revision codes

The script I am using is this:

import RPi.GPIO as GPIO
import time

#Disabilita i Warnings
GPIO.setwarnings(False)

# Usa la numerazione BCM (GPIO17, GPIO18, ecc.)
GPIO.setmode(GPIO.BCM)
# Imposta il pin 17 come output
GPIO.setup(17, GPIO.OUT)

#time.sleep(0.5)
# Aspetta 0.5 secondi

# Accendi (HIGH = 3.3V)
GPIO.output(17, GPIO.HIGH)
#time.sleep(1)
# Spegni (LOW = 0V)
#GPIO.output(17, GPIO.LOW)
# Pulisci le configurazioni alla fine
#GPIO.cleanup()

Of course, I’ve searched the web, but I can’t figure out how to solve it!

Even the command:

dtoverlay=gpio-shutdown,active_low=1

that I entered in:

/boot/config.txt

no longer has any effect!

Can you help me?

Thank you all for your help.

That’s absolutely fine and no problem at all. I can recommend DeepL here. It actually does a pretty good job.

I’m no expert when it comes to GPIO, but have you checked dietpi-config? I think you can activate it there.

You may also need to install RPi.GPIO (ID 69) or similar from dietpi-software.

Yes, thank you, I already use Deepl!

In diet-config, ic2 is already enabled, and I can’t remember what else.

So they are enabled.

RPi GPIO installed, it seems that this library does not work starting from Bookworm!

Searching the web, I tried several solutions, but none of them work!

I installed and then modified the script to install gpiozero, and then the errors multiplied because, for example, the LED used to directly manage the output calls RPi.GPIO I don’t know how many times!

If I could find the image of DietPi RP1 ARMv6 Bullseye, I would use that and be fine, but it no longer exists and I don’t know where to find it…

We dropped support for Bullseye beginning of this year DietPi v10.0 - DietPi.com Docs This includes removing of these images from our server.

Maybe @MichaIng has an idea regarding GPIO.

Yes, of course.
But… I’d like it to work!
I’m not interested in updates for what it needs to do, especially if I have to get involved again!
The only real problem, at that point, would be installing the Splix drivers.
But if I’ve understood all the steps correctly, I could download the new Splix directly from GitHub and compile them directly on the Raspberry, thanks to the detailed instructions provided by the Openprint developer ValdikSS , who created a filter and related .ppd for my Samsung ml1860!
And it works great!

We hope Michalng reads my post and helps me sort this out!

This a legacy API not supported anymore by the RPi kernel. There is a replacement package python3-rpi-lgpio which provides the API on top of the modern lgpio. But I remember one case where this did not work, guess it depends on the software and exact function used, probably no perfect drop-in replacement.

gpiozero as well uses lgpio if available, with highest priority. So yeah, that script requires an update to use a modern low-level or high-level library, or at least python3-rpi-lgpio.

Okay, tanks, so what should I install, rpi.lgpio?

But do I have to uninstall rpi.gpio?

Won’t they conflict with each other?

I could use the script I put together for gpiozero, but that caused problems!

It’s true that I tried it on dietpi Trixie…

I’m no Debian wizard, so I think you’ll have to guide me like a child!!!:rofl::rofl::rofl::rofl:

After much research and trial and error, I solved the problems!

I am leaving this description here in case anyone else needs it in the future.

I started again with a clean installation, in which the only software installed was CUPS and python3, leaving i2c and spi disabled.

Before the first start-up, I modified dietpi.txt on the boot partition, unmasking the logind service by setting the option to 1:

AUTO_UNMASK_LOGIND=1

Since I was already there, I also set the host name and static IP.

Once I had completed the initial start-up by setting passwords, region, time and language, I moved on to testing that logind was actually working:

root@DietPi:~# systemctl status systemd-logind
ā— systemd-logind.service - User Login Management
     Loaded: loaded (/lib/systemd/system/systemd-logind.service; static)
     Active: active (running) since Wed 2023-04-19 16:29:25 BST; 1min 54s ago
       Docs: man:sd-login(3)
             man:systemd-logind.service(8)
             man:logind.conf(5)
             man:org.freedesktop.login1(5)
   Main PID: 422 (systemd-logind)
     Status: "Processing requests..."
      Tasks: 1 (limit: 9203)
     Memory: 1.3M
        CPU: 61ms
     CGroup: /system.slice/systemd-logind.service
             └─422 /lib/systemd/systemd-logind

So I added the following lines to /boot/firmware/config.txt:

#-------poweroff button------



dtoverlay=gpio-shutdown,gpio_pin3,active_low=1,gpio_pull=up


I rebooted and found that finally, by closing gpio3 to GND, the Raspberry shut down.

I then moved on to installing:

sudo apt install python3-gpiozero python3-lgpio

Then I created a led.py file on /home/dietpi/:

import sys

from gpiozero import LED

red = LED(17)

while True:

red.on()

sys.exit()

I launched dietpi-autostart, which creates a bash file

/var/lib/dietpi/dietpi-autostart/custom.sh

and inserted the following line of code:

/usr/bin/python3 /home/dietpi/led.py &

Then I moved on to installing the drivers for the printer, etc.

So I have a print server that I can turn on and off as I please, without compromising the SD card, and which lights up an LED at the end of the start-up process to show that it is operational!

Thanks to everyone who helped me…

See you next time.

Valter :grinning_face: :waving_hand:

1 Like