Example #1
0
                            msgL2 = str(DS1307._read_hours()) + ":" + str(DS1307._read_minutes()) + ":" + str(DS1307._read_seconds())
                            IOboard.writeLCD(LCDhandler, 0, 0, msgL1)
                            IOboard.writeLCD(LCDhandler, 0, 1, msgL2)
                            msgL3 = str(int(temperature)) + " 'C"
                            msgL4 = str(int(humidity)) + " RH"                       
                            IOboard.writeLCD(LCDhandler, 11, 0, msgL3)
                            IOboard.writeLCD(LCDhandler, 11, 1, msgL4)
                            
                        if Addons["UltraSonic"]:
                            distance = calDistance(GPIO_Trigger, GPIO_Echo)
                            print("The distance measurement of UltraSonic: {0}".format(distance))
                            sendCmd("sensor-update UltraSonic %.2f" % (distance))

                        if Addons["DHTreader"]:
                            try:
                                temperature, humidity = DHTreader.read(typeDHT, pinDHT)
                                if temperature and humidity:
                                    print("Temperature = {0} *C, Humidity = {1} %".format(temperature, humidity))
                                    sendCmd("sensor-update Temperature %.2f" % (temperature))
                                    sendCmd("sensor-update Humidity %.2f" % (humidity))                                       
                                else:
                                    print("Failed to read from sensor, restart.")
                            except:
                                print("Failed to read from sensor, restart.")
                                
                        if Addons["TouchSensor"]:
                            GPIO.setup(touchPin, GPIO.IN, GPIO.PUD_DOWN)
                            print("Touch detect on GPIO %d is %d" %(touchPin, GPIO.input(touchPin)))
                            sendCmd("sensor-update touchSensor %d" % (GPIO.input(touchPin)))

                        if Addons["TiltSensor"]:
Example #2
0
DHTreader.init()

if len(sys.argv) != 3:
    print("usage: {0} [11|22|2302] GPIOpin#".format(sys.argv[0]))
    print("example: {0} 2302 Read from an AM2302 connected to GPIO #4".format(sys.argv[0]))
    sys.exit(2)

dev_type = None
if sys.argv[1] == "11":
    dev_type = DHT11
elif sys.argv[1] == "22":
    dev_type = DHT22
elif sys.argv[1] == "2302":
    dev_type = AM2302
else:
    print("invalid type, only 11, 22 and 2302 are supported for now!")
    sys.exit(3)

DHTpin = int(sys.argv[2])
if DHTpin <= 0:
    print("invalid GPIO pin#")
    sys.exit(3)

print("using pin #{0}".format(DHTpin))
t, h = DHTreader.read(dev_type, DHTpin)
if t and h:
    print("Temp = {0} *C, Hum = {1} %".format(t, h))
else:
    print("Failed to read from sensor, maybe try again?")
Example #3
0
DHTreader.init()

if len(sys.argv) != 3:
    print("usage: {0} [11|22|2302] GPIOpin#".format(sys.argv[0]))
    print("example: {0} 2302 Read from an AM2302 connected to GPIO #4".format(
        sys.argv[0]))
    sys.exit(2)

dev_type = None
if sys.argv[1] == "11":
    dev_type = DHT11
elif sys.argv[1] == "22":
    dev_type = DHT22
elif sys.argv[1] == "2302":
    dev_type = AM2302
else:
    print("invalid type, only 11, 22 and 2302 are supported for now!")
    sys.exit(3)

DHTpin = int(sys.argv[2])
if DHTpin <= 0:
    print("invalid GPIO pin#")
    sys.exit(3)

print("using pin #{0}".format(DHTpin))
t, h = DHTreader.read(dev_type, DHTpin)
if t and h:
    print("Temp = {0} *C, Hum = {1} %".format(t, h))
else:
    print("Failed to read from sensor, maybe try again?")