I'm trying to get readings from a number of SHT11 sensors and turn on a LED for each sensor that returns a measurement.
The sensors share a common clk on pin 7.
Pins 11, 13 and 15 are dedicated data pins, one for each of the 3 sensors.
Pins 8, 10, 12 are used for LEDs, one for each sensor.
The program works, but acts very odd. It read data from the sensors that are present, but when I try to turn on the corresponding LED it only blinks and doesn't stay lit as it should.
It seems the LED's are only lit until I use oi.output() the next time even if it's for a completely different pin. Why doesn't the pins keep the level I set them at?
My entire program is below.
And a last question.
in the set_light() function I have to include io.setup() for the pin I want or I get an error saying the pin isn't setup even though I do this at the start of the main function. What gives? Python seems to be behaving oddly.
Code: Select all
from sht1x.Sht1x import Sht1x as SHT1x
import time
import RPi.GPIO as io
def set_light(light):
io.setup(light, io.OUT)
io.output(light,1)
def measure(data, clk, light):
try:
sht1x = SHT1x(data, clk, SHT1x.GPIO_BOARD)
temp = sht1x.read_temperature_C()
hum = sht1x.read_humidity()
dew = sht1x.calculate_dew_point(temp,hum)
set_light(light)
time.sleep(2)
print 'Temp: %f, hum: %f' % (temp, hum)
except:
print 'Sensor not responding'
if __name__ == '__main__':
io.setmode(io.BOARD)
io.setup(8, io.OUT, initial = 0)
io.setup(10, io.OUT, initial = 0)
io.setup(12, io.OUT, initial = 0)
io.output(12,1)
data = 11
clk = 7
light = 8
for i in range(0,3):
print 'Sensor %d' % (i+1)
measure(data,clk,light)
data = data + 2
light = light + 2