Skip to content

Instantly share code, notes, and snippets.

@PierfrancescoElia
Created August 30, 2014 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PierfrancescoElia/63f206620372054c2a65 to your computer and use it in GitHub Desktop.
Save PierfrancescoElia/63f206620372054c2a65 to your computer and use it in GitHub Desktop.
Azionamento relè con GPIO
Questo programma permette di azionare relè passo-passo pre-esistenti come quelli delle luci di casa o, di azionare un cancello elettrico, sdoppiando i fili del citofono. Tutto ciò può essere eseguito anche tramite interfaccia Web.
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
# inserire i pin ai quali sono collegati i relè da azioinare
pinList = [3]
# loop through pins and set mode and state to 'low'
for i in pinList:
GPIO.setup(i, GPIO.OUT)
GPIO.output(i, GPIO.HIGH)
# tempo in cui il relè rimane eccitato
SleepTimeL = 0.25
# ciclo
try:
GPIO.output(3, GPIO.LOW)
print "RELE' AZIONATO! :)"
time.sleep(SleepTimeL);
GPIO.cleanup()
# Termine del programma
except KeyboardInterrupt:
print " Quit"
# Reset impostazioni GPIO
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment