从sensiron sgp30读取数据的库
sgp30的Python项目详细描述
从SGP30 sensor中读取eco2和tvoc的库。基于易于使用的smbus2 i2c库。
它应该与Python2和3都兼容,但目前只在Python2.7下进行测试
快速使用示例:
from smbus2 import SMBusWrapper from sgp30 import Sgp30 import time with SMBusWrapper(1) as bus: sgp=Sgp30(bus,baseline_filename="/tmp/mySGP30_baseline") #things thing with the baselinefile is dumb and will be changed in the future print("resetting all i2c devices") sgp.i2c_geral_call() #WARNING: Will reset any device on teh i2cbus that listens for general call print(sgp.read_features()) print(sgp.read_serial()) sgp.init_sgp() print(sgp.read_measurements()) print("the SGP30 takes at least 15 seconds to warm up, 12 hours before the readigs become really stable" for i in range(20): time.sleep(1) print(".",end="") print() print(sgp.read_measurements())
当前设计注意事项:
这个班力求轻便轻便。它当前有点紧绑定到smbus2类。在大多数情况下,我试图使易读性而不是纯粹性或速度。
已知丢失的功能(按重要程度大致列出):
- 基线值的处理并不是很好,应该由最终用户根据需要保存和恢复它们。
- 为所有或至少大多数方法编写文档字符串。
- 读取原始值。
- 一个更“类似于驱动程序”的类,负责所有芯片识别、定期轮询、恢复基线等。
- 在python3下运行真正的硬件测试
硬件注意事项:
如果你有内置电平变换器和电压调节器的Adafruit板,只要你插上SDA to pin 3, SCL to pin 5, VCC to pin 17 and GND to pin 20就可以了。然后,您应该能够使用i2cdetect -y 1
找到sgp30的地址0x58。如果收到错误消息,可能需要使用raspi-config and reboot在内核中启用i2c
请随时与我联系的错误,问题或问题。