This document discusses connecting sensors, actuators, and other peripherals to a Raspberry Pi using GPIO pins and programming their functionality using Python. It provides code samples for configuring GPIO pins for input and output, controlling relays connected to GPIO pins, reading from a sensor connected to a GPIO pin, and communicating with an AD/DA board over I2C.
1 of 25
More Related Content
Sensors, actuators and the Raspberry PI using Python
13. Relay controller sample code
import RPi.GPIO as GPIO
import time
pins = [22,23,24,25]
for p in pins:
GPIO.setup(p, GPIO.OUT)
while True:
for q in pins:
GPIO.output(q, GPIO.HIGH)
time.sleep(5)
for q in pins:
GPIO.output(q, GPIO.LOW)
time.sleep(5)
18. Sensor sample code
pin = 17
GPIO.setup(pin, GPIO.IN) # make GPIO pin for input
state = GPIO.input(pin) # read GPIO pin
while True:
time.sleep(1)
r = GPIO.input(pin)
if (r != state):
state = r
print "state changed"