一、硬件
树莓派、BH1750FVI模块
二、模块
用的是Adafruit BH1750官方的模块 adafruit_bh1750
三、 接线
(图略)
四、代码
先安装
pip3 install adafruit-circuitpython-bh1750
打开 I2C 功能,运行以下命令,选择 Interface Options 之后开启 I2C 功能
sudo raspi-config
代码示例
import time
import board
import busio
from adafruit_bh1750 import BH1750
import board
# 初始化I2C总线
i2c = busio.I2C(board.SCL, board.SDA)
# 创建BH1750对象
sensor = BH1750(i2c)
# 设置测量模式为连续高分辨率模式
sensor.mode = BH1750.CONTINUOUS_HIGH_RES_MODE
while True:
# 读取光照强度值
light_intensity = sensor.lux
print("Light intensity:", light_intensity, "lux")
time.sleep(1)