Simple test¶
Ensure your device works with this simple test.
examples/hdc1080_simpletest.py¶
import time
from machine import Pin, I2C
from micropython_hdc1080 import hdc1080
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
hdc = hdc1080.HDC1080(i2c)
while True:
temperature, humidity = hdc.measurements
print("Temperature: {:.2f} C".format(temperature))
print("Humidity: {:.2f} %%".format(humidity))
print("")
time.sleep(0.5)
Operation mode settings¶
Example showing the Operation mode setting
examples/hdc1080_operation_mode.py¶
import time
from machine import Pin, I2C
from micropython_hdc1080 import hdc1080
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
hdc = hdc1080.HDC1080(i2c)
hdc.operation_mode = hdc1080.TEMP_OR_HUM
while True:
for operation_mode in hdc1080.operation_mode_values:
print("Current Operation mode setting: ", hdc.operation_mode)
for _ in range(10):
temp = hdc.temperature
print("Temperature: {:.2f}C".format(temp))
print()
time.sleep(0.5)
hdc.operation_mode = operation_mode
Temperature resolution settings¶
Example showing the Temperature resolution setting
examples/hdc1080_temperature_resolution.py¶
import time
from machine import Pin, I2C
from micropython_hdc1080 import hdc1080
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
hdc = hdc1080.HDC1080(i2c)
hdc.temperature_resolution = hdc1080.TEMP_RES_14BIT
while True:
for temperature_resolution in hdc1080.temperature_resolution_values:
print("Current Temperature resolution setting: ", hdc.temperature_resolution)
for _ in range(10):
temp = hdc.temperature
print("Temperature: {:.2f}C".format(temp))
print()
time.sleep(0.5)
hdc.temperature_resolution = temperature_resolution
Humidity resolution settings¶
Example showing the Humidity resolution setting
examples/hdc1080_humidity_resolution.py¶
import time
from machine import Pin, I2C
from micropython_hdc1080 import hdc1080
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
hdc = hdc1080.HDC1080(i2c)
hdc.humidity_resolution = hdc1080.HUM_RES_11BIT
while True:
for humidity_resolution in hdc1080.humidity_resolution_values:
print("Current Humidity resolution setting: ", hdc.humidity_resolution)
for _ in range(10):
temp = hdc.temperature
print("Temperature: {:.2f}C".format(temp))
print()
time.sleep(0.5)
hdc.humidity_resolution = humidity_resolution