This tutorial originally appeared on William Wilson’s (jawn-smith) blog and was contributed and modified here with permission.
As of Linux kernel 5.11, the old methods of communicating with header pins on the Raspberry Pi no longer work. This means packages such as RPi.GPIO no longer function properly with newer kernels. This post by Dave Jones (waveform) explains the reasons for the changes. But fear not, there is a new package in Ubuntu 21.04 called LGPIO that allows full control over the header pins with the latest kernel version. This tutorial covers some basic functionality of LGPIO, including examples using basic GPIO control, I²C, PWM, and SPI.
If you already have Ubuntu 21.04 or newer set up on a Raspberry Pi, you are ready for this tutorial. Otherwise, please see how to install Ubuntu Server on your Raspberry Pi and make it 21.04.
What you’ll learn
- How to install and get started with GPIO pins on Ubuntu
- Basic GPIO operations
- Basic I2C operations
- Basic PWM operations
What you’ll need
- A Raspberry 3 or 4 with Ubuntu 21.04 setup and installed
Optionally for the examples:
- A simple breadboard
- 7x 330ohm resistors
- A single red, green or blue LED
- 10 male jumper wires
- 20 female to male jumper wires
- An Arduino Uno
- 5V PWM fan
- A RGB LED
- A rotary encoder
- An MCP3008 analog to digital converter