Is there a simple gpio input method?

Is there a simple python library like RPi.GPIO but for rockPi? I can write to the gpio-pins, but I am not sure how to read them, especially at a frequency that will allow me to communicate via uart/i2c, or read ultrasonic sensors.

uart/i2c should be treated as uart/i2c, and not as gpio.

I don’t use python, but what you want to look for are python libraries for smbus for i2c. This looks probable;

And for uart, this looks good;

Now ultrasonic sensor… you’re referring to rangefinders? So you’re looking at 2 gpio pins – output and input, and calculating distance based on the input pulse width. Ideally, you would use interrupts for this, otherwise you will have to poll it very quickly in order to minimize the measurement error due to the time between the actual inputs and when it is read. This looks ok; – It looks like you set up a blocking poll for an interrupt. It doesn’t call an ISR however, which makes it a bit weird in my view, but not critically so.

Now here is the thing about the ultrasonic rangefinder… I DOUBT that you will find the performance through python using that library to be adequate. I think you will find extremely inconsistent and inaccurate calculation. What you really want is an actual kernel driver. Here is one such; – they talk about pi hardware, and the makefile is for pi, but the driver looks portable. Build, install, and configure the driver, then from your python code, read the measure file in a loop. This way python and userspace and all the different uncertainties will NOT impact the measurement, but will be able to do calculations based on it.

Or better yet, use an i2c sensor with an upstream driver, like sx9500, and configure it in the devicetree. Then you again just read from the hardware with your python script and take away all the timing errors.

1 Like

I have read quite a few posts that to be honest with GPIO I just wonder why they purchased a RockPi4.
For ÂŁ1 and less boards

You can link them and even program them via the RockPi or even maybe use an output to a gpio interupt assigned pin, i2c or many ways and many of them.
The linux core is far from real time as the rk3399 is an application cpu and the rockpi is an application sbc that is an entry level desktop or low power server.
Even if you do find a RT linux core its still far from latency free.
You could link dozens of those boards to a rock pi but you outsource high frequency time sensitive measurements to devices that are fractions of a ÂŁ?

I will try using it. Do you know of any guides with code for the rockpi (ideally in python) to work with this device?