亲爱的 Android 先驱者们,您好!
我请求您的帮助,因为过去几个月我一直在尝试为 Adafruit SI7021 温度和湿度传感器构建 Android Things 驱动程序。
Here is the link to the github repository主持该项目。
使用 readRegByte 连接并获取芯片 ID 工作正常。
但是,我在尝试使用 readRegBuffer
检索温度或湿度数据时收到 PioException: I/O error
。
int address = 0xE5; // from datasheet
byte[] buffer = new byte[3];
device.readRegBuffer(address, buffer, 3); // throws PioException
我不知道我还能为您提供什么其他线索来清楚地了解问题,因此请随时提出任何问题。
请不要让我买一个arduino并重新开始;)
非常感谢!
PS:用简单的话来说,我是物联网和 Android 的初学者。
最佳答案
readRegBuffer
没有达到我相信您所期望的效果。来自 [API 文档]( https://developer.android.com/things/reference/com/google/android/things/pio/I2cDevice.html#readRegBuffer(int , byte[], int)):
Read multiple bytes from a given register.
如果您要读取的寄存器长度为 3 个字节(24 位),则将使用此方法。正在查看the part's datasheet (p21),相对湿度寄存器 0xE5
似乎是一个 2 位字。
期望 3 个字节会产生问题,因为您的设备将期望返回 3 个字节。但是,如果只返回两个字节,则实际结果会不一致。
关于java - Android Things I2C 驱动程序 PioException : I/O error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47675786/