Simple test

Ensure your device works with this simple test.

examples/sht4x_simpletest.py
import time
from machine import Pin, I2C
from micropython_sht4x import sht4x

i2c = I2C(1, sda=Pin(2), scl=Pin(3))  # Correct I2C pins for RP2040
sht = sht4x.SHT4X(i2c)

while True:
    temperature, relative_humidity = sht.measurements
    print(f"Temperature: {temperature:.2f}°C")
    print(f"Relative Humidity: {relative_humidity:.2%}%")
    print("")
    time.sleep(0.5)

Temperature precision settings

Example showing the Temperature precision setting

examples/sht4x_temperature_precision.py
import time
from machine import Pin, I2C
from micropython_sht4x import sht4x

i2c = I2C(1, sda=Pin(2), scl=Pin(3))  # Correct I2C pins for RP2040
sht = sht4x.SHT4X(i2c)

sht.temperature_precision = sht4x.MEDIUM_PRECISION

while True:
    for temperature_precision in sht4x.temperature_precision_values:
        print("Current Temperature precision setting: ", sht.temperature_precision)
        for _ in range(10):
            temperature, relative_humidity = sht.measurements
            print(f"Temperature: {temperature:.2f}°C")
            print(f"Relative Humidity: {relative_humidity:.2%}%")
            time.sleep(0.5)
        sht.temperature_precision = temperature_precision

Temperature precision settings

Example showing the Temperature precision setting

examples/sht4x_temperature_precision.py
import time
from machine import Pin, I2C
from micropython_sht4x import sht4x

i2c = I2C(1, sda=Pin(2), scl=Pin(3))  # Correct I2C pins for RP2040
sht = sht4x.SHT4X(i2c)

sht.temperature_precision = sht4x.MEDIUM_PRECISION

while True:
    for temperature_precision in sht4x.temperature_precision_values:
        print("Current Temperature precision setting: ", sht.temperature_precision)
        for _ in range(10):
            temperature, relative_humidity = sht.measurements
            print(f"Temperature: {temperature:.2f}°C")
            print(f"Relative Humidity: {relative_humidity:.2%}%")
            time.sleep(0.5)
        sht.temperature_precision = temperature_precision

Heater power settings

Example showing the Heater power setting

examples/sht4x_heater_power.py
import time
from machine import Pin, I2C
from micropython_sht4x import sht4x

i2c = I2C(1, sda=Pin(2), scl=Pin(3))  # Correct I2C pins for RP2040
sht = sht4x.SHT4X(i2c)

sht.heater_power = sht4x.HEATER20mW

while True:
    for heater_power in sht4x.heater_power_values:
        print("Current Heater power setting: ", sht.heater_power)
        for _ in range(10):
            temperature, relative_humidity = sht.measurements
            print(f"Temperature: {temperature:.2f}°C")
            print(f"Relative Humidity: {relative_humidity:.2%}%")
            print()
            time.sleep(0.5)
        sht.heater_power = heater_power

Heat time settings

Example showing the Heat time setting

examples/sht4x_heat_time.py
import time
from machine import Pin, I2C
from micropython_sht4x import sht4x

i2c = I2C(1, sda=Pin(2), scl=Pin(3))  # Correct I2C pins for RP2040
sht = sht4x.SHT4X(i2c)

sht.heat_time = sht4x.TEMP_1

while True:
    for heat_time in sht4x.heat_time_values:
        print("Current Heat time setting: ", sht.heat_time)
        for _ in range(10):
            temperature, relative_humidity = sht.measurements
            print(f"Temperature: {temperature:.2f}°C")
            print(f"Relative Humidity: {relative_humidity:.2%}%")
            print()
            time.sleep(0.5)
        sht.heat_time = heat_time