从Adafruit的TSL2591库转换的TSL2591传感器的社区编码Python模块。使用风险自负。
python-tsl2591的Python项目详细描述
TSL2591 Python库
这是一个简单的用于adafruit tsl2591断接板的python库,它基于adafruit的Arduino library。它是用来制作覆盆子皮的。
要求
要使用此库,您必须具备以下条件:
- TSL2591传感器(不传感器TSL2561)
- I2C启用设备
- Python3(尽管Python2在技术上仍然可以工作)
安装
此模块可以使用pip安装(并且可以在PyPi上找到此模块的副本)。
pip install python-tsl2591
快速启动
此库附带了一个示例文件,您可以使用该文件,也可以复制和粘贴以下文件:
frompython_tsl2591importtsl2591importtimeif__name__=='__main__':tsl=tsl2591()# initialize# full, ir = tsl.get_full_luminosity() # Read raw values (full spectrum and infared spectrum).# lux = tsl.calculate_lux(full, ir) # Convert raw values to Lux.whileTrue:print(tsl.get_current())# Return object with all values.# print (lux, full, ir)time.sleep(2)
从源安装
您还可以从源代码安装此python模块:
git clone https://github.com/kyletaylored/python-tsl2591
cd python-tsl2591
python setup.py install
在覆盆子pi上启用i2c
您可以按照Adafruit上的说明在覆盆子pi上启用i2c。
快速版本是:
- 运行
sudo raspi-config
- 选择
Advanced Options
- 启用I2C
- 重新启动(
sudo reboot
)
当测试I2C(^{
常见问题解答
致命错误(已弃用)
update:我们集成了smbus2
库,这是一个用python构建的smbus库,不需要像smbus-cffi
或libffi-dev
这样的任何系统包。
如果在安装此库之前没有安装这些raspbian包,则会遇到类似的错误。
fatal error: ffi.h: No such file or directory
#include <ffi.h>
^
compilation terminated.
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
I2C检查静态地址
因为tsl2591通过i2c连接,所以运行i2c检测来验证地址是否被读取总是很好的。与具有可编程地址的tsl2561不同,tsl2591的地址是硬编码的,不能更改,因此它总是显示0x29
。
在下面的示例输出中,可以看到检测到两个I2C设备,一个是TSL2591。
pi@raspberrypi:~ $ sudo i2cdetect -y 10123456789 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- 29 -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
许可证
此存储库中的python文件在MIT license下发布。