gpiod C and python examples in /var/lib/cloud9

Beaglers:
I’ve just created some gpiod examples in both C and python. You can get to them via:

bone$ cd /var/lib/cloud9
bone$ git pull
bone$ git checkout v2020.08
bone$ cd BeagleBone/Black/gpiod
bone$ sudo apt update; sudo apt install libgpiod-dev

(Or go to https://github.com/beagleboard/cloud9-examples/tree/v2020.08/BeagleBone/Black/gpiod)

Here’s the ReadMe.md

libgpiod is a new C library and tools for interacting with the linux GPIO character device. Detailed information is here and Adafruit also has information.

One of the advantages of gpiod is that it can toggle multiple bits on the same gpio chip at the same time. The toggle2 examples show how it’s done.

The directory contains examples of using gpiod with C and python to read/write a gpio pin.

FileDescription
toggle1
Toggles one pin as fast as possible. (300KHz in C, 57KHz in python)
toggle2
Toggles two pins as fast as possible. (280KHz in C, 55KHz in python)
get
Reads an input pin and prints its value.
getset
Reads an input pin and writes its value to an output pin. (5us delay in C, 20 us Delay in python)
getsetEvent
Like getset, but uses events. (40 us delay in C, 75 us delay in python)
toggleLED
Toggles the four built in USR LEDs.

Tip: Use gpioinfo to lookup chip and line numbers for various pins.

Feedback is welcome.

–Mark