Articole similare

GPIO in Pyton pe Raspberry Pi

 

1. Configureaza Raspberry Pi pentru Python

2. Descarca arhiva: RPi.GPIO-0.3.1a.tar.gz si instaleaza:

sudo python setup.py install

Acum se poate importa libraria RPi.GPIO intr-un program Python.

Exemplu cod Python pentru GPIO

#import GPIO libray
import RPi.GPIO as GPIO
#select pin numbering methods: BOARD or BCM
GPIO.setmode(GPIO.BOARD)
#configure GPIO pin as output
GPIO.setup(myOutput, GPIO.OUT)
    
#configure GPIO pin as input
GPIO.setup(myInput, GPIO.IN)
    
#set output high (1)
GPIO.output(myOutput, True)
    
#set output low (0)
GPIO.output(myOutput, False)
    
#read input pin value
inputPinValue = GPIO.input(myInput)