예제 #1
0
def main():
    th02 = grove.TH02()
    print(th02.name())
    # Create the temperature sensor object using AIO pin 0
    temp = th02.getTemperature()
    print(temp)

    # Read the temperature ten times, printing both the Celsius and
    # equivalent Fahrenheit temperature, waiting one second between readings
    for i in range(0, 1000):
        temp = th02.getTemperature()
        temp1 = th02.getHumidity()
        print(temp, temp1)
        time.sleep(1)

    # Delete the temperature sensor object
    del temp
예제 #2
0
def publish_message():
   '''
    Description: 
       This function publish tempurature and humidity data taken from sensors to the google cloud Pub/Sub.
    Args: 
       None
    Returns:
       None
    Raise:
       Throw an exception on failure
   '''   
   try:
       thsensor = th02.TH02()
       while True:
          temp = thsensor.getTemperature()
          humidity = thsensor.getHumidity()
          args.message = "Temperature(C),Humidity: (%d,%d)" % (temp, humidity)
          cloudApisObj.publish_message_to_subpub(args.project_id, args.registry_id, args.device_id, args.message_type, args.base_url, args.cloud_region, args.algorithm, args.private_key_file, args.message_data_type, args.message)
          time.sleep(2)    
   except Exception, e:
       print e
예제 #3
0
#Reto 1
#Trabajar con LCD I2C y TH02

#importa bibliotecas
#Biblioteca Sensor temperatura y humedad
from upm import pyupm_th02 as tyhupm
#Biblioteca del LCD RGB
from upm import pyupm_jhd1313m1 as lcd
import time

#Se inicializa el sensor pirolico en el puerto 2
tyh = tyhupm.TH02(bus=0, addr=64)
#Direcciones del LCD segun el fabricante
mylcd = lcd.Jhd1313m1(0, 0x3E, 0x62)
#Limpia display
mylcd.clear()
#Asigna color de led al LCD
mylcd.setColor(0, 113, 197)

while True:
    humedad = tyh.getHumidity()
    temperatura = tyh.getTemperature()
    #Se pone el curso en (0,0)
    mylcd.setCursor(0, 0)
    mylcd.write("T: " + str(temperatura))
    mylcd.setCursor(1, 0)
    mylcd.write("H: " + str(humedad))
    time.sleep(2)
예제 #4
0
import mraa, requests, time
from upm import pyupm_th02
from upm import pyupm_grove
from upm import pyupm_jhd1313m1

display = pyupm_jhd1313m1.Jhd1313m1(0,0x3E, 0x62)
photo = pyupm_grove.GroveLight(0)
th02 = pyupm_th02.TH02(6,0x40)
pir = mraa.Gpio(7)
ledtest = mraa.Gpio(13)
buzzer = mraa.Gpio(2)

pir.dir(mraa.DIR_IN)
ledtest.dir(mraa.DIR_OUT)
buzzer.dir(mraa.DIR_OUT)

temperature = 0
humidity = 0
light = 0
event = 0
error = 0

display.setColor(255,255,255)
display.setCursor(0,0)
display.write('Connecting...')
time.sleep(3)

while True:

    temperature = round(th02.getTemperature(),2)
    humidity = round(th02.getHumidity(),2)
예제 #5
0
파일: sensores.py 프로젝트: ivoayala/Edison
import mraa, upm, time, sys
from upm import pyupm_jhd1313m1
from upm import pyupm_th02

display = pyupm_jhd1313m1.Jhd1313m1(0,0x3E, 0x62)
display.setColor(0,0,255)

sensores = pyupm_th02.TH02(6,0x40)

Switch = 0
Temperature = 0
Humidity = 0

while True:

    Temperature = round(sensores.getTemperature(),1)
    Humidity = round(sensores.getHumidity(),1)
    
    print "La temperatura es de %.1f C y la humedad de %.1f%% \n" %(Temperature, Humidity)
#    print 'La temperatura es: '  + str(Temperature)
#    print 'La humedad es:     ' + str(Humidity) 
    display.setCursor(0,0)
    display.write('TEMP: ' + str(Temperature))
    display.setCursor(1,0)
    display.write('HUMI:  ' + str(Humidity))
    time.sleep(1.5)
    exit()