LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Embedded & Single-board computer (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/)
-   -   Configuring GPIO pin mapping for libgpiod (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/configuring-gpio-pin-mapping-for-libgpiod-4175716852/)

bthomas 09-17-2022 07:55 AM

Configuring GPIO pin mapping for libgpiod
 
Hi

I installed a bare minimal Debian 11 (Bullseye) distribution on a Nano Pi M1 single board computer. I would like to use it to control external devices using its GPIO pins. I was not able to find a suitable port of Python packages such RPi.GPIO for this purpose. Besides I understand the current best practice for controlling gpio pins is to use libgpiod. The gpio device is detected by the kernel as shown below

Code:

$ sudo gpiodetect
gpiochip0 [1c20800.pinctrl] (224 lines)
gpiochip1 [1f02c00.pinctrl] (32 lines)

However the pins are not named and so it is not obvious how the libgpiod pin numbers map to pins on the Nano Pi M1 board as shown below

Code:

$ sudo gpioinfo gpiochip0
gpiochip0 - 224 lines:
        line  0:      unnamed      unused  input  active-high
        line  1:      unnamed      unused  input  active-high
        line  2:      unnamed      unused  input  active-high
        line  3:      unnamed      unused  input  active-high
        line  4:      unnamed      unused  input  active-high
        line  5:      unnamed      unused  input  active-high
        line  6:      unnamed      unused  input  active-high
        line  7:      unnamed      unused  input  active-high
        line  8:      unnamed      unused  input  active-high
        line  9:      unnamed      unused  input  active-high
        line  10:      unnamed "nanopi:blue:status" output active-high [used]

How do I find out what libgpiod pin numbers map to what pins on the Nano Pi M1 board ? As I understand this may require a Device Tree Overlay. If this is indeed what is required, how do I understand how to write the Device Tree Overlay file to give me the required pin mapping. I have familiarised myself the device tree source file format but even to write the DTS file I need to know the pin mapping in the first place.

Thank you

smallpond 09-19-2022 12:27 PM

Maybe not needed. Do you have a /sys/class/gpio directory?

bthomas 09-21-2022 03:39 PM

As I understand libgpiod was created to avoid use of /sys/class/gpio.

Emerson 09-21-2022 04:00 PM

You searched thoroughly their documentation and it all was useless? You could use a voltmeter and find out mapping by switching pins one by one, time consuming though.

bthomas 09-22-2022 05:00 AM

That is a good idea indeed. I was thinking along the lines of setting up a gpiod event to monitor and then set a 3.3v volt pull up or down resistor on each pin with a switch and see which gpio lines detect it. Apart from being tedious I am not sure if this will work for all the pins though it may be enough to give me an idea of the pin layout.

The problem with their documentation is that they list the pin numbers which are (I think) "logical" pin numbers and may not correspond to the numbering that is used by the gpiod driver. There is a circuit diagram available and I am trying to figure out how the gpiod numbering corresponds with the pin numbers in the circuit diagram.


All times are GMT -5. The time now is 07:34 PM.