Best approach Raspberry Pi 5?

Should be 2 more examples also in that first version.

One of them will list all the lines and their names and such.

In the upcoming version, I have entered a bit the deep waters…as in there are parts of libgpiod that are terrible fit for Xojo due to Xojo’s lack of real threads.

But I have in the upcoming version solved one such case where it can monitor Line Info async in native thread.

(Need to apply same solution for async reading of the Line values but those might not be there until 3rd phase, and the line values I will have little chance to test since I am 100 km away from the Raspberry and so far all my tests have been by remoting into it. I imagine to test async line value monitoring then we will actually have to set it like board with button on some pin and do it physically)

But i will release 2nd phase in this week where it should add enough to pass 3 more official examples, making the examples passed go to 6.

1 Like

I put out massive update, and moved the updates for the plugin to my own thread to not permanently hijack this thread.

I posted here:

3 Likes

Nice work! I will test it today

I believe you can just make a commercial plugin wrapper for this:
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/about/
top line states: SPDX-License-Identifier: CC-BY-SA-4.0
Which is a creative commons license that seems to allow commercial use.

We will most likely benefit the most if this is maintained as stable as it gets.
This is ofcourse just a side node, not a requirement.

Nah its fine, I felt this one was good candidate for open source, it helps then new Plugin makers as they get source code to look at.

Bob’s Math plugins that I been attempting to maintain are not good place for new plugin author to look as things there are not done in ideal way and there will be long time until I get any grip there on just basic memory fault. So getting fresh plugin from scratch with this complexity level out in the community is good I think.

(And all my Plugins have always been free on Linux anyhow).

4 Likes

If I am understanding this article correctly:

https://medium.com/geekculture/raspberry-pi-c-libraries-for-working-with-i2c-spi-and-uart-4677f401b584

Then we will eventually need another plugin of some sort to cover I2C and then another for SPI.

libgpiod only covers GPIO as far as I am understanding it.

I have written a wrapper for Xojo and the libgpiod library and have been using the GPIO pins for about 4 years. It works will all Raspberry Pi’s and works on the latest Raspberry Pi 5.

Eugene’s free lgpio GPIO GitHub

I have written quite a few articles (about 7 so far and more to be published) in the xDev magazine which use the latest version of the libgpoid. Examples include I2C, SPI, and many other examples. More sensor and output examples will be published in future xDev magazine publications.

This library has been used by me for the last 4 years or so, and no issues so far. I am not sure how it works with Orange Pi or other variants.

//Initialize the Raspberry Pi lgpio
MyChipHandle = lgGpiochipOpen(4) //dev/gpiochip4 for Raspberry Pi 5
//MyChipHandle = lgGpiochipOpen(0) //dev/gpiochip0 for Raspberry Pi 4 or older

Raspberry Pi 5 has a different chipset, so the lgGPiochipOpen command handle function is to be set to 4, whereas earlier Raspberry Pi versions than 4 are set to zero.

I hope this helps.

Eugene

3 Likes

I think you are confusing though libgpiod and lgpio ?, looks like yours is using lgpio.

Those are two very different libraries.

2 Likes

Eugene, if you like some feedback on your efforts, read this:

I just downloaded the project and tried it out with my Pi5 (64bit raspi OS). It failed in so many ways.

The README.md is badly markdown formatted, so that neither Marked 2 nor MacDown would show the text well.

The apt install commands lead to an error on my Pi system. I can compile the code regardless, though.

Next, the website of the built helper tool says that one needs to launch it, but yours doesn’t mention that, so it’s unclear what’s needed here.

When I run your test project, it doesn’t blink the LED, not even when I change the argument for the lgGpiochipOpen from 0 to 4. And the code doesn’t report the fact that the handle is zero, so I needed to run it in the debugger to figure out where the problem was. I still don’t know why the demo gets a zero handle, and there’s no guidance.

So, what I’m trying to say: It could be a lot more carefully done, considering all the things that can go wrong, to be of better help.

OTOH, when I tried Björn’s module and test project, they ran flawlessly. No problems at all.

2 Likes

Thanks form the feedback Thomas. I’ll reformat the Raspberry Pi again and double-check the instructions.

Warm regards.

Edit: Which library were you using (I have written 3 different libraries). :slight_smile:

1 Like

Hi Eugene,

I think it was from GitHub - eugenedakin/lgpio-GPIO: Wrapper uses the new C-language gpiochip functions for the Raspberry Pi
Though I see now that github renders the md file better.

But the major thing that needs improvement is error handling, and making the code smarter to handle the possible cases. E.g,: check if the handle is invalid and then warn the user. or even better: detect whether it’s a pi5 or older, and then set the open argument accordingly. Always add error checks in the demos, even if it’s just a break cmd with a comment, so that at least one sees something in the debugger if things are not working as expected.

The point is: If you provide a lib that does things (like here, the GPIO access), then your test program needs to be perfectly handling all cases. Leaving this to the user, i.e. figuring out all the pitfalls, is okay if you provide general examples where people learn from, but if it’s the only “example” project, it needs to handle all the cases because users will try to use that as a basis for their projects - users do not read docs, they use existing code and build on it :slight_smile:
So, if your example is incomplete, you’re not doing them a favor.

I just bring that up because I had some frustrating experiences recently with some hardware add-ons for my Pi5: An LCD and a Thermal camera. The camera, for instance, had no foolproof example that I could simply run to check whether the camera works. Instead, I was expected to install libs, compile downloads from dubious sources, including override options that were supposed to “potentially break your python installation”. In the end, I had to send the $130 module back because I was not able to even run the demo, and I was not able to figure out whether it was because I made some errors installing the software or if simply the module was defective.

So, my point is: Provide at least one demo that is foolproof, which you can always ask people to run first if they contact you if something isn’t working in their opinion. Then you can ask them to run your example and if that works, you can tell them: use that demo as an example and compare it to what you did, and find your mistake. Without having that, anyone might assume that the error is not on their side but on yours, and then you’ll have much more work to prove them wrong :slight_smile:

Oh, reading the README again, here’s some more practical improvements:

You show quite a few commands one has to execute on the Pi - it’s not good to list them with enumerations or as tables, because they’re hard to copy then. Instead, always put those code / cmd line into either `…` or lead them with 4 spaces. There’s no need to put numbers in front. Without the numbers, it’ll be easier to copy multiple line and paste them all at once into Terminal, for instance.

An example (I’m using ``` lines before and after the comds here to mark the entire block as code. Also always add an empty line before such blocks, as it’ll conform better with markdown):

Install instructions are:

sudo apt install swig python-dev python3-dev
sudo apt install python-setuptools python3-setuptools
wget http://abyz.me.uk/lg/lg.zip

Initialize the Raspberry Pi 4 lgpio

MyChipHandle = lgGpiochipOpen(0) //dev/gpiochip0 for Raspberry Pi 4 or older

I hope this helps.

Thomas

2 Likes

Hello Thomas,

Thank you for the suggestions and for providing ways to make the examples better. Yes, your right, I will create an example that has better error handling. Although I can’t guarantee that the example will be foolproof, the example can contain much more error checking and handling.

I use the library in real-world applications for many projects, and the libraries are shared so that others can potentially use the drivers that I have created, or that are contained in the wrapper. Since the wrapper has been used many times by me, I unfortunately end up believing that everyone else thinks and understands projects like I do - which is incorrect, and I like your feedback.

I am writing and installing a system in the field at-the-moment, and when I return to my working computer, I’ll create a better example for error handling.

Thank you for the kind feedback, I greatly appreciate your thoughts.

6 Likes