Universal GPIO Access
The library libgpiod provides universal access to GPIOs of any device running Linux. It detects available GPIO, can read and write data to them, and wait for events to be triggered. With this, you can write ow code to talk UART to any connected device.
To install it, run the following commands:
If compilation and installation is successful, in the subfolder ./tools
you will find binaries like gpiodetect
and gpioinfo
that you can use to explore the GPIOs. See the following examples.
If you want to work with the library, read this article for a detailed introduction.
Conclusion
For working with I2C, SPI and UART on the Raspberry Pi, not only Python, but C++ libraries can be used as well. Specifically, you need to activate the I2C and SPI functions via raspi-config
, which infernally loads the appropriate Kernel modules. Then you choose a client library and other necessary C++ headers. Working with the libraries follows the same principles: Determine the connected device file, configure a connection object, open the device file, then read from/write to it. Finally, the handy library libgpiod can help you to access all GPIO pins directly, which can be helpful for debugging.
Last updated