Simple test¶
Ensure your device works with this simple test.
import time
from machine import Pin, I2C
from micropython_hts221 import hts221
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
hts = hts221.HTS221(i2c)
while True:
print(f"Humidity :{hts.relative_humidity:.2f}%")
print()
time.sleep(0.5)
Data rate settings¶
Example showing the Data rate setting
import time
from machine import Pin, I2C
from micropython_hts221 import hts221
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
hts = hts221.HTS221(i2c)
hts.data_rate = hts221.ONE_SHOT
while True:
for data_rate in hts221.data_rate_values:
print("Current Data rate setting: ", hts.data_rate)
for _ in range(10):
print(f"Humidity :{hts.relative_humidity:.2f}%")
print()
time.sleep(0.5)
hts.data_rate = data_rate
Block data update settings¶
Example showing the Block data update setting
import time
from machine import Pin, I2C
from micropython_hts221 import hts221
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
hts = hts221.HTS221(i2c)
hts.block_data_update = hts221.BDU_ENABLED
while True:
for block_data_update in hts221.block_data_update_values:
print("Current Block data update setting: ", hts.block_data_update)
for _ in range(10):
while True:
print(f"Humidity :{hts.relative_humidity:.2f}%")
print()
time.sleep(0.5)
hts.block_data_update = block_data_update