Raspberry Pi Advanced Guide (wiringPi Tutorial, C Programming, GPIO Buttons, POSIX Multi-Threading)

Опубликовано: 11 Октябрь 2024
на канале: M Heidenreich
7,813
174

*****************************************
Update, March 2024:

WiringPi has been updated to support the latest Raspberry Pi 4/5, but it is not included with default Raspberry Pi OS image. You can use the following commands in your Raspberry Pi Terminal to get WiringPi installed:

git clone https://github.com/mheidenreich/wirin...
cd wiringPiBasics
chmod u+x update_wiringpi.sh
sudo ./update_wiringpi.sh

The above will give you access to the 'gpio' command and you will be able to compile C programs that use wiringPi library, for example:

gcc -Wall blink.c -lwiringPi -o blink
*****************************************

This 2-part Raspberry Pi GPIO tutorial shows how to correctly use buttons with wiringPi (C Programming). While I use the buttons to control LEDs, you can use the same approach with any other electronic components (or code in a subroutine/function in general).

If you are using Raspberry Pi 4 you may receive an error when attempting to use the gpio command. Follow this guide to fix it:
http://wiringpi.com/wiringpi-updated-...

Part 1 video gives a general overview of wiringPi as of today, explains the concept of pull-up and pull-down resistors and demonstrates the circuit used in this tutorial.

Part 2 video covers the C coding part of this project, including:
GPIO port initialization and safe deactivation
Asynchronous button handlers using wiringPi interrupts
Button de-bouncing using time and sampling methods
Button callbacks using POSIX multi-threading

0:00 Intro
0:14 Basic Program Setup
2:24 Basic Button (Naive Method)
3:10 Basic Button (Interrupt Method)
4:52 Button De-Bouncing (Method 1 - Time Interval)
7:51 Multi-Threaded Button Callbacks
10:10 Button De-Bouncing (Method 2 - Sampling)
11:30 Wrap-Up

Full code: https://github.com/mheidenreich/butto...
(Note: code posted may contain small updates and/or bug fixes not shown in the video)

Disclaimer:
"Raspberry Pi" and the distinct logo are a trademark of the Raspberry Pi Foundation.

Music: Endless Motion By Bensound.com, https://www.bensound.com/