In the last couple of years I have implemented two projects on Rpi Pico Based Smart Vehicle. Now Rpi5 is coming. So I am thinking of updating my Pico based projects to Rpi5.
I have preordered a Rpi5 and hope to get it some time in 2023dec. Now I am just reading documentation and tutorials.
The first Rpi5 topic I hope to begin is Rpi5 GPIO, and as usual I hope to write a Blinky program. For now I am collecting references.
References
(1) How to Control the Raspberry Pi 5 GPIO with Python 3 - Les Pounder, 2023oct28
(2) Raspberry Pi 5 RP1 Peripherals - Raspberry Pi Ltd 2023-11-07
RP1 has 28 multi-functional General-Purpose Input/Output pins available to implement the standard Raspberry Pi 40-pin GPIO connector.
The pins are in a single electrical bank (VDDIO0). The GPIO bank (IO_BANK0) can be powered from 1.8V or 3.3V, but interface timings have been specified at 3.3V. Each pin can be controlled directly by software, or by a number of other
functional blocks.
Interrupt generation from pin level or edge transitions
The functional blocks and their locations on the GPIO pins have been chosen to match user-facing functions on the 40-pin header of a Raspberry Pi 4 Model B.
When you plug your Raspberry Pi into power for the first time it will automatically turn on and boot into the operating system without having to push the button.
If you are running the Raspberry Pi Desktop you can initiate a clean shutdown by briefly pressing the power button located on the left-hand side of the board, and then releasing it. This will cause a Desktop menu to appear asking whether you want to Shutdown, Reboot, or Logout. You can select whether you want to shutdown or reboot, or alternatively pressing the power button briefly for a second time will initiate a clean shutdown.
open(self, device, how:int=1)
@brief Open a GPIO chip.
@param device: String or int describing the GPIO chip.
@param how: Indicates how the chip should be opened.
If the object already holds a reference to an open chip, it will be
closed and the reference reset.
Usage:
chip.open("/dev/gpiochip0")
chip.open(0, chip.OPEN_BY_NUMBER)
Command Line Tools
Gpiod provides a set of command line tools that are very useful for interactively exploring GPIO functions, and can be used in shell scripts to avoid the need to write C or C++ code if you only need to perform basic GPIO functions. The following commands are provided:
gpiodetect - List all GPIO chips present on the system, their names, labels and number of GPIO lines.
gpioinfo - List all lines of specified GPIO chips, their names, consumers, direction, active state and additional flags.
gpioget - Read values of specified GPIO lines.
gpioset - Set values of specified GPIO lines, and potentially keep the lines exported and wait until timeout, user input or signal.
gpiofind - Find the GPIO chip name and line offset given the line name.
gpiomon - Wait for events on GPIO lines, specifying which events to watch, how many events to process before exiting or if the events should be reported to the console.
chips
The gpiodetect program will detect the GPIO chips that are present. The library uses the term “chip” to identify groups of GPIO hardware functions which may or may not correspond to hardware-level chips. In the case of the Raspberry Pi the GPIO hardware is all contained in the Broadcom SOM (system on a module).
The gpioget and gpioset commands allow reading and writing GPIO input and output lines.
A simple example is the following which sets line 24 of the first chip to a high output level for one second and then releases it:
% gpioset --mode=time -s 1 0 24=1
Libgpiod Library API
The C API allows calling the gpiod library from C or languages that support C APIs like C++. The API is well documented, and too extensive to fully cover here. The basic use cases usually follows these steps:
(1) Open the desired GPIO chip by calling one of the gpiod_chip_open functions such as gpiod_chip_open_by_name(). This returns a gpiod_chip struct which is used by subsequent API calls.
(2) Open the desired GPIO line(s) by calling gpiod_chip_get_line() or gpiod_chip_get_lines(), obtaining a gpiod_line struct.
(3) Request use of the line as an input or output by calling gpiod_line_request_input() or gpiod_line_request_output().
(4) Read the value of an input by calling gpiod_line_get_value() or set the level of an output by calling gpiod_line_set_value().
(5) When done, release the lines by calling gpiod_line_release() and chips by calling gpiod_chip_close().
Other APIs are provided for more advanced functions like setting pin modes for pullup or pulldown resistors or defining a callback function to be called when an event occurs, like the level of an input pin changing.