

Strictly speaking, ground is 0V not a -ve voltage (although it does correspond to the -ve terminal on a battery). This is what the above program’s output looks like… Print "Port 25 is 0/GPIO.LOW/False - button not pressed" Print "Port 25 is 1/GPIO.HIGH/True - button pressed" While True: # this will carry on until you hit CTRL+C
Gpi ss4 no flycut code#
Here’s the code with all the extras added to read and display the button’s status, and exit cleanly when CTRL+C is pressed…įrom time import sleep # this lets us have a time delay (see line 12) If you don’t have a breadboard, resistors and buttons, you could cheat and just use a jumper wire to connect two pins directly, but you’ll need to be aware of what you’re doing. We’ll cover a bit more on floating ports, pull-ups and pull-downs in another article (probably part 6). It’s not dangerous, (it could be if you had something like a motor attached) but it’s not fully in control either. If you don’t use the resistors, it might still work, but you risk having a “floating” port. When the button is pressed, GPIO25 is connected to 3.3V. The resistors are used to “pull down” the GPIO25 pin to 0 Volts GND (0V, 0, LOW, False) unless the button is pressed. In order to go any further with this, we need to make up a little circuit.Ĭircuit with button for manipulating GPIO25 (click to enlarge)

…changing Port_or_pin to the number of the GPIO port or pin you want to use. So, with a drumroll and a fanfare of trumpets, it’s now time for us to set up some inputs. # but you can't have both, so only use one!!! So, at the top of every script, after importing the RPi.GPIO module, we set our GPIO numbering mode. It’s also important to be aware of the other system in case you ever need to work on someone elses code. The important thing is to pick the one that makes sense to you and use it. If you want to control the LED on a Pi camera board (GPIO5) you also have to use GPIO numbering. If you want to use the P5 header for GPIO28-31, you have to use GPIO numbering. If you use GPIO numbers, your scripts will make better sense if you use a Gertboard, which also uses GPIO numbering.

You still need to be aware of which pins you can and can’t use though, since some are power and GND. If you use pin numbers, you don’t have to bother about revision checking, as RPi.GPIO takes care of that for you. I habitually use the GPIO numbers, but neither way is wrong. In RPi.GPIO you can use either pin numbers (BOARD) or the Broadcom GPIO numbers (BCM), but you can only use one system in each program.
Gpi ss4 no flycut how to#
How to set up BOARD and GPIO numbering schemes

