简体   繁体   English

Android Things I2C驱动程序PioException:I / O错误

[英]Android Things I2C Driver PioException: I/O error

Hello dear pioneers of Android things! 亲爱的Android事物先锋!

I am calling for your help as I have been triying for the last couple of months to build an android things driver for the Adafruit SI7021 Themperature and humidity sensor. 在过去的几个月中,我一直在努力为Adafruit SI7021温度和湿度传感器构建一个Android Things驱动程序,我在寻求您的帮助。 Here is the link to the github repository hosting the project. 这是托管项目的github存储库的链接 Connecting and Getting the chip id with readRegByte work fine. 使用readRegByte连接并获取芯片ID可以readRegByte工作。 But, I get a PioException: I/O error while trying to retrieve Temperature or humidity data using readRegBuffer . 但是,在尝试使用readRegBuffer检索温度或湿度数据时, PioException: I/O errorPioException: I/O error

int address = 0xE5; // from datasheet
byte[] buffer = new byte[3];

device.readRegBuffer(address, buffer, 3); // throws PioException

I don't know what other clue I can give you to get a clear idea of the problem so do not hesitate to ask any question. 我不知道我能给您什么其他线索以使您清楚地了解问题,因此请随时提出任何问题。

Please don't make me buy an arduino and start all over again ;) 请不要让我买一头arduino,然后重新开始;)

Thank you so mutch! 非常感谢!

PS: Use simple words I am a beginner in IoT and Android. PS:用简单的话来说,我是IoT和Android的初学者。

The readRegBuffer does not do what I believe you expect. readRegBuffer不能满足我的期望。 From [the API documentation]( https://developer.android.com/things/reference/com/google/android/things/pio/I2cDevice.html#readRegBuffer(int , byte[], int)): 从[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. 从给定的寄存器中读取多个字节。

This method would be used if the register you wanted to read was 3 bytes long (24 bits). 如果要读取的寄存器长3个字节(24位),则将使用此方法。 Looking at the part's datasheet (p21), register 0xE5 for relative humidity appears to be a 2-bit word. 查看该器件的数据手册 (p21),相对湿度寄存器0xE5似乎是一个2位字。

Expecting 3 bytes will create a problem as your device will be expecting 3 bytes to be returned. 预计3个字节会造成问题,因为您的设备预计会返回3个字节​​。 However, if only two bytes come back there will be an inconsistency in the actual result. 但是,如果仅返回两个字节,则实际结果将不一致。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM