Python_with_RaspberryPi_Interfacing_Notes
Python_with_RaspberryPi_Interfacing_Notes
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
Wiring:
Code:
GPIO.setup(18, GPIO.OUT)
while True:
GPIO.output(18, GPIO.HIGH)
time.sleep(1)
GPIO.output(18, GPIO.LOW)
time.sleep(1)
2.2 Buzzer
GPIO.setup(23, GPIO.OUT)
GPIO.output(23, GPIO.HIGH)
time.sleep(0.5)
GPIO.output(23, GPIO.LOW)
while True:
if GPIO.input(17) == GPIO.LOW:
print("Button Pressed")
time.sleep(0.2)
GPIO.setup(24, GPIO.IN)
while True:
if GPIO.input(24):
print("Motion Detected")
else:
print("No Motion")
time.sleep(1)
Python Programming with Raspberry Pi: Interfacing External Gadgets
Libraries:
Code:
import spidev
spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 1350000
def read_adc(channel):
return data
while True:
value = read_adc(0)
time.sleep(1)
GPIO.setup(pin, GPIO.OUT)
while True:
GPIO.output(18, GPIO.HIGH)
time.sleep(2)
GPIO.output(18, GPIO.LOW)
GPIO.output(23, GPIO.HIGH)
time.sleep(1)
GPIO.output(23, GPIO.LOW)
GPIO.output(24, GPIO.HIGH)
time.sleep(2)
GPIO.output(24, GPIO.LOW)
6. Cleanup Code
GPIO.cleanup()