GPIO questions about edge

Does the library OPi.GPIO work on radxa 5b? Especially GPIO.add_event_detect and the callback. I didn’t see any mention of radxa 5b board in the docs only zero board.

Can gpiomon in gpiod trigger a callback script? I don’t see it mentioned.

I need to run a callback script off of the edge. I want to count the number of button pushes.

Thanks

I think @Nasca is working on that. @Nasca What the status now?

You can use this repository https://github.com/nascs/OPi.GPIO.git then checkout the branch radxa

1 Like

Thanks, will try it today

I ran this today:

from OPi import GPIO as GPIO
import radxa.rock5b

GPIO.setmode(GPIO.BOARD)

GPIO.setwarnings(False)
GPIO.setup(16,GPIO.OUT)
GPIO.output(16,GPIO.HIGH)

if GPIO.input(16) == 1:
print(‘Input was HIGH’)
else:
print(‘Input was not hi’)

time.sleep(20)
GPIO.cleanup()

When I run this, it prints on console: “Input was HIGH”, but when I measure pin 16 voltage is 0, not 3 volts.

Also when I run: gpioinfo gpiochip0 I get:
line 16: unnamed unused input active-high and:
line 19: unnamed “sysfs” output active-high [used]

Which does not seem right.

If I use pin 18 instead of pin 16, I get:
line 18: unnamed “sysfs” output active-high [used]

Looks like the OPi.GPIO-radxa is reading pin_mapping.py and not rock5b.py

Any ideas? Thanks

I tried some other pins and got the same result. Why would GPIO.input(16) == 1 and not show 3v with volt meter, seems screwed up to me.

How have I screwed up?

You will need to set the gpio.mode to use that layout

GPIO.setmode(radxa.rock5b.BOARD) or GPIO.setmode(radxa.rock5b.BCM)

Already tried that on the first time I ran the script and just tried it again and still no 3v on pin 16, tried pin 18 also and no voltage.

Please check the python “BOARD” dict inside radxa/rock5b.py and ensure that the pins has their correct match to the GPIO.
That may be your issue

For board pin 16 (GPIO3_A4) the match must be 100.

Check the pinout and the way to pass from board pin to chip pins here:
https://wiki.radxa.com/Rock5/hardware/5b/gpio

Here is an example:

Will check this out tomorrow. When I run any script using OPi.GPIO I have to run it as root can that be avoided?

You don’t need to run as root, apply the following configuration:

I am confused, on this page: https://wiki.radxa.com/Rock5/hardware/5b/gpio aren’t the gpio numbers on the far left and right of the top connector display at the top of the page? I don’t see any pin showing GPIO4_D5.

I looked at rock5b.py about the pins. It shows
16: 154,
18: 156,
so they don’t appear to match from the wiki page.

which library should I use:


or

I did the udev rules and can now run script as non-root.
Thanks

Let me explain something to you about the pins.
There may be multiple “Pin numbers” for a single GPIO. This is due to the way in which controllers (SOM: System on a chip) are integrated into a SBC (Single board computer):

You start with a single pinout at the controller (You may assume this is like the central processor),
Later, when you put this chip (processor) onto a PCB with some other peripherals and convert the SOM onto an SBC, the pin numbers change from the original ones (as numbered in the SOM chip) to those in the new SBC connectors.

When by software you program the mode to board: GPIO.setmode(radxa.rock5b.BOARD)
You are referring to the BOARD pins circled in red (ordered from 1 to 40)

Otherwise when by software you program the mode to BCM: GPIO.setmode(radxa.rock5b.BCM)
You are referring to the SOM pin numbers circled on blue (I think that the rock 5B SBC uses the Rockchip RK3588 SOM)
Hope you must be curious about why is called BCM :wink:

Final thought:
To refer to a specific GPIO you must finally use the SOM numbering.

The dictionary in rock5b.py must work as a match dictionary to find the right number of the SOM.

GPIO3_A4: corresponds to the pin # 16 on the BOARD and pin number 100 on the SOM. This according to the pinout here: https://wiki.radxa.com/Rock5/hardware/5b/gpio

GPIO4_D5 is not present at the 40-pin connector cause there are just 40 pins for GPIO and other stuff and the designer just doesn’t use it in the board, but may exists at the SOM.

so the rock5b.py may be wrong (It happened to me with another board model). Just update it with the right match and you have it!

I just download the library by means of pip. And locally copy and paste the “Radxa” folder from here:

Hope this can help you.

Ok, will work thru this new stuff, knew about BCM–been using raspberry for a long time.

I understand now to use rm-hull opi and will copy the radxa folder to it and then make the necessary corrections to it.

If I understand right, radxa really uses the BCM numbers.

Do both of these work the same, GPIO.setmode(radxa.rock5b.BOARD) using pin 16 and GPIO.setmode(radxa.rock5b.BCM) using pin 100?

I really appreciate all your help. I am sure I am not the only one who has had trouble with this.

I do have another fairly important problem. I am running Debian 11 and have 3 radxa’s. On new the mouse works ok, on another one I lose the mouse pointer almost all the time, mouse works just can’t see the pointer. I posted a query about this and got no reply. I get the pointer back when I reboot, but that is a real pain.
I will work on gpio more, btw, I understand when the pin is HIGH, the voltage is supposed to be around 3v and mine is never near 3.

Hey Ed,

You definitely will need to edit the rock5b.py file.
Linux understands the pin numbering as the ones at the SOM.
In fact, the dictionary called BOARD must be a match between the pin at the BOARD and the pin at the SOM (But now we know that this file is wrong)

Edit the file and test.
Continue using GPIO.setmode(radxa.rock5b.BOARD) using pin 16 after that correction.

Radxa rock5B physical board pin to GPIO pin

BOARD = {
3: 71,
5: 72,
7: 75,
11: 146,
13: 150,
15: 149,
19: 40,
21: 39,
23: 41,
27: 64,
29: 74,
31: 73,
33: 76,
35: 133,
37: 158,
8: 148,
10: 147,
12: 131,
16: 100,
18: 148,
22: 157,
24: 42,
28: 65,
32: 112,
36: 132,
38: 134,
40: 135,
}

1 Like

Shouldn’t these:
BOARD = {
3: 71,
5: 72,
7: 75,

be:
3: 139,
5: 138,
7: 115,

?

1 Like

Does OPi.GPIO do callbacks, the docs lists it as TODO??