I want to program a simple thermostat, but for some reason the commands GPIO.output(21, 1) or GPIO.output(21, 0) do not change anything.
In a similar vein, GPIO.setup(20, GPIO.OUT, initial=0) does indeed setup the pin for output, but it's automatically on, despite the initial=0...
Here's the code:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(20, GPIO.OUT, initial=0)
ventein = GPIO.output(20, 1)
ventaus = GPIO.output(20, 0)
calling ventein or ventaus further down the line does not do anything. The pin is just always on. I suspected that maybe it has something to do with user permissions, so I added both root and the user to the gpio group - didn't do anything.
Toggling the pin with the gpio command line tool works just fine. What could be the problem?
And here's the complete code, just in case:
from w1thermsensor import W1ThermSensor
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(20, GPIO.OUT, initial=0)
ventein = GPIO.output(20, 1)
ventaus = GPIO.output(20, 0)
muro = W1ThermSensor(W1ThermSensor.THERM_SENSOR_DS18B20, "011445ff9daa")
murotemp = muro.get_temperature()
try:
while True:
if murotemp > 20:
ventein
print(murotemp)
print("Temperatur ist hoeher als 20 Grad, schalte ein...")
time.sleep(0.5)
muro = W1ThermSensor(W1ThermSensor.THERM_SENSOR_DS18B20, "011445ff9daa")
murotemp = muro.get_temperature()
elif murotemp < 20:
ventaus
print(murotemp)
print("Temperatur ist niedriger als 20 Grad, schalte aus...")
time.sleep(0.5)
muro = W1ThermSensor(W1ThermSensor.THERM_SENSOR_DS18B20, "011445ff9daa")
murotemp = muro.get_temperature()
except KeyboardInterrupt:
GPIO.cleanup()
print("exiting...")
murotemp == 20
it's normal ?ventein = GPIO.output(20, 1) ventaus = GPIO.output(20, 0)
are not in the loop in a conditionnal scope or other... then you init the same GPIO number at HIGH and then at LOW state for the global scope. That it's a logic problem because you use the same pin forventein
andventaus
20 Grad
ventein = GPIO.output(20, 1) ventaus = GPIO.output(20, 0)
it works!