To use raspberry pi’s GPIO pins in python you must first download the ‘RPi.GPIO’ library. To do so, open the terminal in the raspberry pi and run the following command:
Code: Select all
sudo apt-get update
Code: Select all
sudo apt-get install rpi.gpio
RPi.GPIO as GPIO
Then we must the mode of the pins. In this you have two options, the first mode is ‘BOARD’ mode where use the physical numbering of the pins (you can simply count with your finger!!). The second mode is the ‘BCM’ mode, when use this mode you need to follow the number after ‘GPIO’ in the figure below:

To set the mode to ‘BOARD’ we use:
Code: Select all
GPIO.setmode(GPIO.BOARD)
Code: Select all
GPIO.setmode(GPIO.BCM)
Code: Select all
GPIO.setup(pin,GPIO.IN)
GPIO.setup(pin,GPIO.OUT)
Ex: In BOARD pin number 3 is pin number 2 in BCM.
- See more at:
https://www.zeroohm.com/blog/introducti ... pberry-pi/