This is a continuation of a discussion at: New pigpio - GPIO wrapper for Raspberry Pi If anyone has more information on libgpiod, then feel free to add it here so that everyone can learn more about this library.
For those who are new at programming electronics on the Raspberry Pi with Xojo, there are currently two main libraries to work with the GPIO pins on a Raspberry Pi: wiringPi, and pigpiod.
The wiringPi library is deprecated and is not recommended for future work since there are no more public updates to the code. When a new OS, or system is released there is a good chance that the wiringPi will have issues with code. (Older book available at: https://scispec.ca/index.php/books/28-program-raspberry-pi-2-b-with-xojo). There is a large amount of code that uses the wiringPi library on the internet.
PIGPIO (also called pigpiod) is the latest compatible library to be ported to Xojo and works well, although the library is harder to configure on a Raspberry Pi since it uses a server-type method of controlling the GPIO pins. The update to PIGPIO also happened when Raspberry Pi created their own OS, appropriately called Raspberry Pi OS. PIGPIO does not like to share processes with other programs, which can be hindering in some applications. There is some code available for PIGPIO on the internet, which is less than wiringPi, and more example code than libgpiod.
The libgpiod library is free and can be downloaded from github at: https://github.com/brgl/libgpiod, and is written in C, so a library would need to be created to port it to Xojo. There is a low amount of code available for libgpiod and it might be something positive to examine in the future. Libgpiod is being actively developed and there are lots of frequent updates (as of 16 Dec 2020) that can be viewed here: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/
I’ll work on a ‘Hello-world’ example with Libgpiod and see how it is to setup.
PIGPIO has 2 libraries. You do not have to use the server one, you can simply connect to the local one.
But its somehow harder than the old wiringp I admit, I been trying to convert some of my examples. (Or my mentality is just to stuck on the old ways).
For me then it also comes down to what will work on other boxes, with Wiring PI I was taking for example things and running them without changing anything on Orange PI boxes (using Orange PI adapted Wiringpi, which I guess was part of what made its author enrage)
Libgpiod is the linux native gpio library ntively embedded in the kernel already. No need to download/compile on later pi Os systems
WiringPi is deprecated.
Pigpiod has multiple interfaces but can only be used by 1 application.
I’d go where the Pi foundation is going libgpiod in the kernel. Better support, etc…
If this is where the foundation is moving, then it is a good idea to follow them. After a day of searching I was not able to find APIs. Do you have a link for the Libgpiod API’s so that I can test some declares?
you can browse trough the sources. do note that pigpiod has more high level stuff (as wiring pi had).
libgpio is lower level but could practically do everything.
Derk is correct that a single application can access the GPIO at one time. This is for increased safety of the Raspberry Pi board. One application can accept and coordinate input/output from the board. Multiple programs accessing the same input/output ports can accidentally overload an input pin and short the chip.
I have good news about the existing pigpio library, as it makes very limited use of sysfs (the deprecated OS calls). Sysfs will be maintained in Linux for the forseeable future and there are no plans to remove it from the Linux kernel. In this sense, deprecation means no new features will be added and the existing code will be maintained.
Most of the calls in the pigpio library for Xojo use pigpio and pigpiod_if2 dynamic libraries. Only the gpioISR function in the pigpio library use the sysfs, which is the part that uses interrupts. Xojo does not recommend interrupts on any machine. There is a discussion about some workarounds in this part of the forums (gpio event at level change).
There is a newer library wrapper that I can create which uses the newer gpiochip interface that @DerkJ mentioned, which will be getting more updates and an increased number of functions.
I would like to know your thoughts and below is a poll and you can vote for one or both.
Would you like the newer pgiochip wrapper or keep the existing pigpio interface for Xojo Raspberry Pi?
I created a Blink example with lgpio that exclusively uses the newer c-language functions (libgpiod - gpiochip) for the Raspberry Pi, and is available at the following github link: Eugene’s Github lgpio. This can be downloaded for free.
When I can confirm that all of the functions work (I2C, SPI, etc.) then I’ll write a book.
This is a wrapper/library to make the c-language calls easier understand and work with. If this library was not created, then I would need to build one from scratch - which would have similar type of installation instructions to make it Xojo-friendly.
I am used to a single-installer on Windows, and it is typical on Linux for the source code to be compiled on the Linux machine (which are these instructions). Its just a different way of doing the same thing