SHARE
TWEET

Raspberry relay and DS18b20 test

TringaliLuca Jan 21st, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python3
  2. import RPi.GPIO as GPIO
  3. import w1thermsensor
  4. import sys, os
  5. from time import sleep
  6.  
  7. # Numerazione dei PIN GPIO
  8. GPIO.setmode(GPIO.BCM)
  9.  
  10. # Il pin del relay va in output
  11. GPIO.setup(23, GPIO.OUT)
  12. #Devono essere abilitati i 1-Wire
  13. os.system('sudo modprobe w1-gpio')
  14. os.system('sudo modprobe w1-therm')
  15. #Cerco il sensore
  16. sensor = w1thermsensor.W1ThermSensor()
  17.  
  18. while (True):
  19.     # Accendo il relay
  20.     GPIO.output(23, GPIO.HIGH)
  21.     #Leggo la temperatura
  22.     temperature_in_celsius = sensor.get_temperature()
  23.     print("Temperatura:"+str(temperature_in_celsius)+"° C")
  24.     # Aspetto 5 secondi
  25.     sleep(5)
  26.     # Spengo il relay
  27.     GPIO.output(23, GPIO.LOW)
  28.     #Leggo la temperatura
  29.     temperature_in_celsius = sensor.get_temperature()
  30.     print("Temperatura:"+str(temperature_in_celsius)+"° C")
  31.     # Aspetto 5 secondi
  32.     sleep(5)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top