-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_sensorbridge_sgp40.py
33 lines (27 loc) · 1.31 KB
/
example_sensorbridge_sgp40.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import time
from sensirion_shdlc_driver import ShdlcSerialPort, ShdlcConnection
from sensirion_shdlc_sensorbridge import SensorBridgePort, \
SensorBridgeShdlcDevice, SensorBridgeI2cProxy
from sensirion_i2c_driver import I2cConnection
from sensirion_i2c_sgp4x import Sgp40I2cDevice
# Connect to the SensorBridge with default settings:
# - baudrate: 460800
# - slave address: 0
with ShdlcSerialPort(port='COM1', baudrate=460800) as port:
bridge = SensorBridgeShdlcDevice(ShdlcConnection(port), slave_address=0)
print("SensorBridge SN: {}".format(bridge.get_serial_number()))
# Configure SensorBridge port 1 for SGP40
bridge.set_i2c_frequency(SensorBridgePort.ONE, frequency=100e3)
bridge.set_supply_voltage(SensorBridgePort.ONE, voltage=3.3)
bridge.switch_supply_on(SensorBridgePort.ONE)
# Create SGP40 device
i2c_transceiver = SensorBridgeI2cProxy(bridge, port=SensorBridgePort.ONE)
sgp40 = Sgp40I2cDevice(I2cConnection(i2c_transceiver))
print("SGP40 Serial Number: {}".format(sgp40.get_serial_number()))
# Measure every second for one minute
for _ in range(60):
time.sleep(1)
sraw_voc = sgp40.measure_raw()
# use default formatting for printing output:
print("SRAW VOC: {}".format(sraw_voc))
bridge.switch_supply_off(SensorBridgePort.ONE)