DesignSpark Electrical Logolinkedin
菜单 搜寻
提问问题

DockerPi Sensor Hub树莓派HAT开箱测试报告

这是DockerPi Sensor Hub开发板的首次外观,该Sensorhub是IoT中的环境参数。它包括温度传感器,湿度传感器,气压传感器,照明和红外热传感器。本文将分为两个部分,硬件设置和软件设置。

硬件部分

首先,在硬件部分,让我们看一下盒子里面的东西,我们有一个Sensor Hub开发板,4个M2.5x12铜棒,4对M2.5x6螺钉和螺母,一个NTC温度传感器(防水)。

盒子的東西

现在让我们开始动手实践。

首先,我们必须使用铜棒和M2.5 * 6螺母固定Sensorhub。

现在我们要用树莓派强制SensorHub,如下所示

然后,我们必须使用4个M2.5x6螺钉用SensorHub锁定树莓派

完成如下

最后,我们必须插入NTC温度传感器

完成如下

软件部分

我在树莓派的桌面上使用以下代码创建ep0106.py

这是软件部分。该程序如下

import smbus

DEVICE_BUS = 1
DEVICE_ADDR = 0x17

TEMP_REG = 0x01
LIGHT_REG_L = 0x02
LIGHT_REG_H = 0x03
STATUS_REG = 0x04
ON_BOARD_TEMP_REG = 0x05
ON_BOARD_HUMIDITY_REG = 0x06
ON_BOARD_SENSOR_ERROR = 0x07
BMP280_TEMP_REG = 0x08
BMP280_PRESSURE_REG_L = 0x09
BMP280_PRESSURE_REG_M = 0x0A
BMP280_PRESSURE_REG_H = 0x0B
BMP280_STATUS = 0x0C
HUMAN_DETECT = 0x0D

bus = smbus.SMBus(DEVICE_BUS)

aReceiveBuf = []

aReceiveBuf.append(0x00) # 占位符

for i in range(TEMP_REG,HUMAN_DETECT + 1):
    aReceiveBuf.append(bus.read_byte_data(DEVICE_ADDR, i))

if aReceiveBuf[STATUS_REG] & 0x01 :
    print("Off-chip temperature sensor overrange!")
elif aReceiveBuf[STATUS_REG] & 0x02 :
    print("No external temperature sensor!")
else :
    print("Current off-chip sensor temperature = %d Celsius" % aReceiveBuf[TEMP_REG])


if aReceiveBuf[STATUS_REG] & 0x04 :
    print("Onboard brightness sensor overrange!")
elif aReceiveBuf[STATUS_REG] & 0x08 :
    print("Onboard brightness sensor failure!")
else :
    print("Current onboard sensor brightness = %d Lux" % (aReceiveBuf[LIGHT_REG_H] << 8 | aReceiveBuf[LIGHT_REG_L]))

print("Current onboard sensor temperature = %d Celsius" % aReceiveBuf[ON_BOARD_TEMP_REG])
print("Current onboard sensor humidity = %d %%" % aReceiveBuf[ON_BOARD_HUMIDITY_REG])

if aReceiveBuf[ON_BOARD_SENSOR_ERROR] != 0 :
    print("Onboard temperature and humidity sensor data may not be up to date!")

if aReceiveBuf[BMP280_STATUS] == 0 :
    print("Current barometer temperature = %d Celsius" % aReceiveBuf[BMP280_TEMP_REG])
    print("Current barometer pressure = %d pascal" % (aReceiveBuf[BMP280_PRESSURE_REG_L] | aReceiveBuf[BMP280_PRESSURE_REG_M] << 8 | aReceiveBuf[BMP280_PRESSURE_REG_H] << 16))
else :
    print("Onboard barometer works abnormally!")

if aReceiveBuf[HUMAN_DETECT] == 1 :
    print("Live body detected within 5 seconds!")
else:
    print("No humans detected!")

 

该程序仅运行一次,因此我们需要键入Linux命令以每10秒计算一次以更新脚本.

watch -n 10 python3 ep0106.py

 

您会发现这样显示的数据。

Brian0925 还没写个人简介...

16 Jan 2020, 7:37