Simple test
Ensure your device works with this simple test.
examples/sen6x_simpletest.py
1# SPDX-FileCopyrightText: Copyright (c) 2025 Liz Clark for Adafruit Industries
2#
3# SPDX-License-Identifier: MIT
4
5# Simpletest for the SEN6x Driver
6# Uncomment the init for your SEN6x sensor
7import time
8
9import board
10
11import adafruit_sen6x
12
13# Initialize I2C
14i2c = board.I2C()
15
16# Initialize the sensor:
17sensor = adafruit_sen6x.SEN66(i2c) # SEN66 sensors
18# sensor = adafruit_sen6x.SEN63C(i2c) # SEN63C sensors
19
20# Read sensor info
21print(f"Product: {sensor.product_name}")
22print(f"Serial: {sensor.serial_number}")
23
24# Check device status
25status = sensor.device_status
26print(f"Device {status}")
27
28# Optional: Configure sensor before starting
29# sensor.temperature_offset(offset=-2.0, slot=0) # Apply -2°C offset
30# sensor.voc_algorithm_tuning(index_offset=100) # Adjust VOC baseline
31# print(sensor.voc_algorithm) # Print VOC baseline
32
33# CO2 configuration examples:
34# sensor.co2_automatic_self_calibration = False # Disable ASC for greenhouses
35# sensor.ambient_pressure = 1020 # Set pressure in hPa
36# sensor.sensor_altitude = 500 # Or set altitude in meters
37
38# Start measurements
39sensor.start_measurement()
40
41# Wait for first measurement to be ready
42print("Waiting for first measurement...")
43time.sleep(2)
44print("-" * 40)
45
46# Read data continuously
47while True:
48 if sensor.data_ready:
49 # Check for errors before reading
50 sensor.check_sensor_errors()
51
52 # Read all measurements
53 data = sensor.all_measurements()
54
55 # Display values (None = sensor still initializing)
56 print(
57 f"Temperature: {data['temperature']:.1f}°C"
58 if data["temperature"]
59 else "Temperature: initializing..."
60 )
61 print(
62 f"Humidity: {data['humidity']:.1f}%"
63 if data["humidity"]
64 else "Humidity: initializing..."
65 )
66 print(f"PM2.5: {data['pm2_5']:.1f} µg/m³" if data["pm2_5"] else "PM2.5: initializing...")
67 try: # if sensor does not have VOC/NOx readings, skip
68 print(
69 f"VOC Index: {data['voc_index']:.1f}"
70 if data["voc_index"]
71 else "VOC Index: initializing..."
72 )
73 print(
74 f"NOx Index: {data['nox_index']:.1f}"
75 if data["nox_index"]
76 else "NOx Index: initializing..."
77 )
78 except KeyError:
79 pass
80 print(f"CO2: {data['co2']} ppm" if data["co2"] else "CO2: initializing...")
81 print("-" * 40)
82 time.sleep(2)