我尝试使用 AndroidThings 通过 Raspberry Pi 3 和 BMP280 测量温度。
3,3V 我选择是因为 specification of BMP280 :
To power the board, give it the same power as the logic level of your microcontroller
然后我要初始化传感器
mTemperatureSensorDriver = new Bmx280SensorDriver("I2C1");
通过执行我收到以下异常(exception)情况
Error configuring sensor
com.google.android.things.pio.PioException: android.os.ServiceSpecificException: I/O error (code 5)
at com.google.android.things.pio.I2cDeviceImpl.readRegByte(I2cDeviceImpl.java:81)
at com.google.android.things.contrib.driver.bmx280.Bmx280.connect(Bmx280.java:215)
at com.google.android.things.contrib.driver.bmx280.Bmx280.<init>(Bmx280.java:193)
at com.google.android.things.contrib.driver.bmx280.Bmx280.<init>(Bmx280.java:180)
at com.google.android.things.contrib.driver.bmx280.Bmx280SensorDriver.<init>(Bmx280SensorDriver.java:55)
同样通过 5V 电源我收到相同的异常。
我找到了 this .但是我不知道如何检查 BMP280 是否真的通过 adb 连接到 Raspberry。
通过 own testing我通过 device.readRegByte(0xD0)
收到的连接性相同。
这是否意味着 BMP280 未正确连接? 如果是,如何正确连接BMP280和Raspberry?
连接需要一些电阻吗?
更新
通过焊接带头条的 BMP280 解决。
与传感器一起工作还需要权限,只能在命令行中授予权限。 ref
adb shell pm grant app.package com.google.android.things.permission.MANAGE_SENSOR_DRIVERS
最佳答案
查看您的 fritzing 图,您将 SDO 连接到 BCM3?
根据数据表,SDO 引脚决定了传感器的地址。
Connecting SDO to GND results in slave address 1110110 (0x76); connection it to VDDIO results in slave address 1110111 (0x77)
最重要的是:
The SDO pin cannot be left floating; if left floating, the I²C address will be undefined.
com.google.android.things.pio.PioException:android.os.ServiceSpecificException:I/O 错误(代码 5)
因此您的问题可能是未定义的 i2c 地址。
查看您用于 Bmx280SensorDriver 的代码,它使用地址 0x77
因此你应该确保你的 SDO 线连接到你树莓派上的 5V。这将确保您的传感器具有正确的地址。
或者将 SDO 接地并使用此构造函数:
mTemperatureSensorDriver = new Bmx280SensorDriver("I2C1", 0x76);
如果您想了解传感器驱动程序在“幕后”做什么,可以阅读一篇很棒的博客文章和存储库:
http://blog.blundellapps.co.uk/tut-android-things-temperature-sensor-i2c-on-the-rainbow-hat/
;-)
关于java - BMP280 服务特定异常 : I/O error (code 5),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47869657/