time.sleep(0.0635)
# Read the temperature value (2 bytes).
temp_bytes = i2c.readfrom(HDC1080_ADDR, 2)
# Calculate the temperature in Celsius.
temp_celsius = (int.from_bytes(temp_bytes, "big") / 2 ** 16) * 165 - 40
# Change the pointer to 0x01 (Temperature register)
i2c.writeto(HDC1080_ADDR, bytearray([REG_HUM]))
# Wait for the humidity measure to complete (per data sheet).
time.sleep(0.065)
# Read the humidity value (2 bytes).
humidity_bytes = i2c.readfrom(HDC1080_ADDR, 2)
# Calculate the humidity in HR.
humidity_hr = (int.from_bytes(humidity_bytes, "big") / 2 ** 16) * 100
# Print results:
print("- Temperature: %s C" % round(temp_celsius, 2))
print("- Humidity: %s %%" % round(humidity_hr, 2))
print("")
time.sleep(5)
if temp_celsius > 30:
else:
Luis Thayer Ojeda 0115 Of. 1105, Providencia, Santiago, Chile
+56 2 23339579 | www.mcielectronics.cl | www.arduino.cl |
MANUAL DE USUARIO TIC XBEE 3
led_pin.value(1)
led_pin.value(0)
Código de ejemplo 2. Sensor HDC1080 y activación de Relé.
info@mcielectronics.cl
Página 16 de 19