How to Use Push Buttons With Raspberry Pi GPIO (with Python gpiozero)

preview_player
Показать описание
This video is an introduction to how to use buttons with the Raspberry Pi.
I am a big fan of the gpiozero library and dislike RPi.GPIO. And it shows!

0:00 Intro
0:14 How to do it wrong!
1:40 Why infinite while loops are bad
2:20 Why I dislike RPi.GPIO
3:10 Why gpiozero is the right choice
3:48 Event-driven programming primer
4:20 Basic gpiozero button program
5:38 Button press event handling
7:34 Callbacks with lambda:
8:15 User-defined event callback
8:55 Putting it all together
9:50 Full code

(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: Pull Up Riddim by Konrad OldMoney, YouTube Music Library
Рекомендации по теме
Комментарии
Автор

Very good tutorial, much better than anything else out there.

jonani
Автор

Oh, and you are also on my recommendations list, since before spring arrived.
I keep all the advanced electronic videos on the bottom, due to not that many people
will probably go there, but if they do go there, they will find the best people about
the raspberry pi machine. You are one of them people who actually helped me lay out my
Pi the way I've got set up. Please know and see that I took your advice. If you look,
you will find. I did EXACTLY AS YOU TAUGHT ME!-:)) I do not regret it. You are the best at
my layout design. I took it right after you, in the very same image. I use a breadboard
by itself as the power to all the other breadboards I have three on a Jamiko Breadboard
set tray. I use the other, forth one as my power, separate from the Jamiko ones. The one
I use came with an electronics kit, I bought and so far I only lost a light because I forgot
a resistor. lol I can only hope you look at my Raspberry Pi videos. I hope you like them.
Thanks so much again...

Compuscience-Python-Prog-Exps
Автор

As this code is in its own module, any constants (led1, led2) should be declared ahead of a function where they're used (go_blink). This makes understanding scope a little easier for beginners, IMO. My only beef -- thanks for the tutorial!

nb
Автор

Excellent video!!! This modality definitely worked better for the code I am implement. Thank you very much, and look forward to checking out the rest of the tutorials :)

shawnbakhtiar
Автор

This is a very helpful tutorial. I am planning to use this sort of code along with PYQT5 to create a water tank automation.

BartdeBoisblanc
Автор

This is awesome! The new library is simple and easy to use. Love the event features. I have a problem with my button triggering multiple times with one press randomly. Is there a way to ignore multiple button presses within a specified time?

tumieengineering
Автор

I've been facing problems with my project for weeks and your video solved it in seconds! If I want to use the same button on multiple screens to activate different functions, would I get the GPIO conflict error like what happens with the RPi.GPIO library?

biancafioretti
Автор

Thank you so much, just that global you put it there, really really kills, e/

igoutta
Автор

God I wish I knew about this library when I was working on my last project. It works the way I've written it, but it is so clunky and ham-fisted compared to this XD

philbateman
Автор

I keep readying that if you have a button you need to attach a resistor to it to protect the pi. Is that true?

spawnreaper
Автор

Thank you, can i replace the LED to a relay and just press button ON and press same button OFF.

kasdiqiu
Автор

The problem is you are not limiting the current through the pin if it's accidentally set as an output. I explained, more but it just got deleted by YT.

TooSlowTube
visit shbcf.ru