Ive just bought your great piece of proto plate .
Im all new to hardware programming and is about to start my first little button project with my kid.
The guides keep refering to GPIO pin numbers.
Ive read the manual from your site but i dont think i understand it.
On the plate theres alot of ports named #17 #4 and so forth. Does this refer to the pins? In the case that i want to something like this should i connect my button to #17?
Code: Select all
With your switch connected, let’s now look at how to read its state from Python. Start Python (as root so you can access the GPIO pins) with
sudo python
In your Python console:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
This will import the necessary libraries in the GPIO namespace and set the pin numbering to correspond to your breakout board.
Now we need to set the pin as input, pin 17 is used in this example.
GPIO.setup(17,GPIO.IN)
Reading the pin is now as easy as:
input = GPIO.input(17)
If we want to print “Button Pressed” each time a button is pressed (and assuming we’ve set up the switch so the pin goes high when pressed):
while True:
if (GPIO.input(17)):
print("Button Pressed")