Skip to content

sen5x adapter demos #2810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions SEN5x_Adapter_Demos/Python/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
#
# SPDX-License-Identifier: MIT

import time
from sensirion_i2c_driver import I2cConnection, LinuxI2cTransceiver
from sensirion_i2c_sen5x import Sen5xI2cDevice

i2c = LinuxI2cTransceiver('/dev/i2c-1')
device = Sen5xI2cDevice(I2cConnection(i2c))

# Print some device information
print(f"Version: {device.get_version()}")
print(f"Product Name: {device.get_product_name()}")
print(f"Serial Number: {device.get_serial_number()}")

# Perform a device reset (reboot firmware)
device.device_reset()
# Start measurement
device.start_measurement()
time.sleep(1)

def read_data():
try:
# Wait until next result is available
print("Waiting for new data...")
while device.read_data_ready() is False:
time.sleep(0.1)
# Read measured values -> clears the "data ready" flag
values = device.read_measured_values()
print(values)
# Access a specific value separately (see Sen5xMeasuredValues)
# mass_concentration = values.mass_concentration_2p5.physical
# ambient_temperature = values.ambient_temperature.degrees_celsius
# Read device status
status = device.read_device_status()
print("Device Status: {}\n".format(status))
except Exception as e: # pylint: disable = broad-except
print(f"Error: {e}")

while True:
read_data()
time.sleep(5)