File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
SEN5x_Adapter_Demos/Python Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ # SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ import time
6
+ from sensirion_i2c_driver import I2cConnection , LinuxI2cTransceiver
7
+ from sensirion_i2c_sen5x import Sen5xI2cDevice
8
+
9
+ i2c = LinuxI2cTransceiver ('/dev/i2c-1' )
10
+ device = Sen5xI2cDevice (I2cConnection (i2c ))
11
+
12
+ # Print some device information
13
+ print (f"Version: { device .get_version ()} " )
14
+ print (f"Product Name: { device .get_product_name ()} " )
15
+ print (f"Serial Number: { device .get_serial_number ()} " )
16
+
17
+ # Perform a device reset (reboot firmware)
18
+ device .device_reset ()
19
+ # Start measurement
20
+ device .start_measurement ()
21
+ time .sleep (1 )
22
+
23
+ def read_data ():
24
+ try :
25
+ # Wait until next result is available
26
+ print ("Waiting for new data..." )
27
+ while device .read_data_ready () is False :
28
+ time .sleep (0.1 )
29
+ # Read measured values -> clears the "data ready" flag
30
+ values = device .read_measured_values ()
31
+ print (values )
32
+ # Access a specific value separately (see Sen5xMeasuredValues)
33
+ # mass_concentration = values.mass_concentration_2p5.physical
34
+ # ambient_temperature = values.ambient_temperature.degrees_celsius
35
+ # Read device status
36
+ status = device .read_device_status ()
37
+ print ("Device Status: {}\n " .format (status ))
38
+ except Exception as e : # pylint: disable = broad-except
39
+ print (f"Error: { e } " )
40
+
41
+ while True :
42
+ read_data ()
43
+ time .sleep (5 )
You can’t perform that action at this time.
0 commit comments