Simple test

Ensure your device works with this simple test.

examples/sths34pf80_simpletest.py
 1# SPDX-FileCopyrightText: Copyright (c) 2025 Liz Clark for Adafruit Industries
 2#
 3# SPDX-License-Identifier: MIT
 4
 5"""
 6Simple test example for the STHS34PF80 IR presence and motion sensor
 7"""
 8
 9import time
10
11import board
12
13import adafruit_sths34pf80
14
15# Create I2C bus
16i2c = board.I2C()
17
18# Create sensor instance
19sensor = adafruit_sths34pf80.STHS34PF80(i2c)
20
21print("-" * 40)
22
23while True:
24    # wait for new data
25    if sensor.data_ready:
26        # temperature values
27        ambient_temp = sensor.ambient_temperature
28        object_temp = sensor.object_temperature
29        comp_object_temp = sensor.compensated_object_temperature
30
31        # detection values
32        presence_val = sensor.presence_value
33        motion_val = sensor.motion_value
34        temp_shock_val = sensor.temperature_shock_value
35
36        # detection true/false
37        presence = sensor.presence
38        motion = sensor.motion
39        temp_shock = sensor.temperature_shock
40
41        print(f"Ambient Temp: {ambient_temp:.2f}°C")
42        print(f"Object Temp (raw): {object_temp}")
43        print(f"Object Temp (compensated): {comp_object_temp}")
44        print(f"Presence Value: {presence_val} {'[DETECTED]' if presence else ''}")
45        print(f"Motion Value: {motion_val} {'[DETECTED]' if motion else ''}")
46        print(f"Temp Shock Value: {temp_shock_val} {'[DETECTED]' if temp_shock else ''}")
47        print("-" * 40)