Remember to change gpiochip0 to gpiochip4 if you are running on a Pi 5.
You can see that now the request is to set an input line and the reading part of the program uses get and then displays the values in the data structure.
Summary
A Linux-based approach for GPIO access from the Raspberry Pi offers advantages. The first is portability - your program, with potentially minor adjustments, can be ported to other Linux machines equipped with GPIO hardware.
Furthermore, the GPIO driver grants access without requiring root privileges or direct memory manipulation. Moreover, it facilitates a straightforward mechanism for handling I/O events from user space, making it a complementary option to the BCM2835 library in certain scenarios.
While sysfs GPIO is still in the Linux kernel it has been deprecated since 2008 and should not be used for new projects.
The new Linux GPIO character driver replaces the well-known sysfs GPIO driver. It is harder to use from the command line and mostly uses ioctl calls to access the GPIO lines.
If you install the gpiod library you get a set of utility functions that do allow command line use.
The raw GPIO character is easy to use once you know the sysctl operations supported and their structs.
The GPIO character driver is about twice as fast as the sysfs-based interface, but still ten times slower than direct access.
The GPIO lines have to remain open while you use them and you need to remember to close them when you have finished using them.
Amazon recently disclosed that developers spend an average of just one hour per day coding. This finding was reported in an announcement that Amazon Q Developer can now document your code by [ ... ]