gpiolib and gpiomem, RPi

Discussions related specifically to the Windows, Linux (86), Mac OS-X and Raspberry Pi editions of BB4W and BBCSDL
Newlands
Posts: 29
Joined: Mon 29 Jan 2024, 16:18

Re: gpiolib and gpiomem, RPi

Post by Newlands »

Looking at the[url] Toms Hardware[/url] link it talks about addressing pins (obviously with Python code) as follows:
3. Tell the code where to find the GPIO. Originally the Raspberry Pi had a single gpiomem device, which was mapped into memory and we could use it with Python modules such as RPi.GPIO. With the Raspberry Pi 5 and the RP1 chip we now have dynamically split devices, and our GPIO is at gpiomem4.

chip = gpiod.Chip('gpiochip4')
4. Create a variable called led_line and store a reference to the LED GPIO pin. The gpiod module uses lines to refer to the GPIO pins.

led_line = chip.get_line(LED_PIN)
Is there a difference between gpiomem4 and gpiochip4? Does the gpiod library give any indications about gpiomem devices?
But I agree there is a contradiction, which I can't explain.
Newlands
Posts: 29
Joined: Mon 29 Jan 2024, 16:18

Re: gpiolib and gpiomem, RPi

Post by Newlands »

There appears to be a couple of libraries that Python users can use for the Pi 5:
Unfortunately the key code is in the Python gpiod library which I haven't found (nor looked for, TBH).
from HERE
The only issue is that RPi.GPIO does not work on the Raspberry Pi 5 due to a changed memory mapping. Whereas everything was handled by the /dev/gpiomem device before, now everything is dynamically split into multiple gpiomem devices. The 40-pin GPIO header happens to fall into /dev/gpiomem4.
So this means it’s time to look at a couple of new options that do work on the Raspberry Pi 5. The two biggest contenders are libgpiod and gpiozero, though there does appear to be a pure Python version of libgpiod called gpiod.
I would guess from the above that libgpiod is similar to gpiod, but I'm way out of my depth here. I do remember that libgpiod is already installed in the Pi 5 distro - as I mentioned above I have actually stuck an led on pin 21 and done this:
In Terminal, gpioset gpiochip4 21=1 to set a pin high and gpioset gpiochip4 21=0 to set it low, and that works. (The '21' refers to gpio21 which is pin no. 40)
Newlands
Posts: 29
Joined: Mon 29 Jan 2024, 16:18

Re: gpiolib and gpiomem, RPi

Post by Newlands »

That's very impressive. All I've managed to achieve in the last couple of hours is to thoroughly confuse myself even more with the help of Google. Very good to hear that the Pi 5 has earned its keep!!
Newlands
Posts: 29
Joined: Mon 29 Jan 2024, 16:18

Re: gpiolib and gpiomem, RPi

Post by Newlands »

I've just looked at the specs for the stepper motor drivers I have in mind and it says the logic signal current has min, avg and max values of 7,10 and 16mA. I don't know if that varies according to the output current (which can be set between 1.8 and 5.6 Amps (peak, not RMS). Of course, the GPIO pins don't have to be connected directly to the stepper driver inputs - a simple transistor or triac would solve the current problem, but it might be nice to have a bit more than 4mA.
Newlands
Posts: 29
Joined: Mon 29 Jan 2024, 16:18

Re: gpiolib and gpiomem, RPi

Post by Newlands »

These are the specs of the DM556T stepper drivers (from Stepperonline). As suggested the inputs are opto-isolaters. Pulse signal voltage is given at 4 to 5v HI and 0 to 0.5v LO:
stepper03.png
stepper01.png
stepper02.png
You do not have the required permissions to view the files attached to this post.
Newlands
Posts: 29
Joined: Mon 29 Jan 2024, 16:18

Re: gpiolib and gpiomem, RPi

Post by Newlands »

Yes, its not a problem - I have had to do similar on my cnc router controller, which uses the same stepper drivers.