gpt4 book ai didi

android - 如何启用Raspberry Pi3模块的I2C(将Android Things作为操作系统使用)

转载 作者:行者123 更新时间:2023-11-29 01:05:17 31 4
gpt4 key购买 nike

我正在尝试使用Raspberry Pi模块3开发一个示例Android-Things应用,该模块从BME280传感器获取温度读数并将其显示在应用上。我已经下载了示例项目,但是在打开带有地址的I2cDevice时遇到问题。

以下是代码详细信息:

私有静态最终int ADDRESS = 0x76;

private void printDeviceId() {
List<String> deviceList = managerService.getI2cBusList();
if (deviceList.isEmpty()) {
Log.i(TAG, "No I2C bus available on this device.");
} else {
Log.i(TAG, "List of available devices: " + deviceList);
}
I2cDevice device = null;
try {
device = managerService.openI2cDevice(deviceList.get(0), ADDRESS);
Log.d(TAG, "Device ID byte: 0x" + Integer.toHexString(device.readRegByte(0xD0)));
} catch (IOException|RuntimeException e) {
Log.e(TAG, e.getMessage(), e);
} finally {
try {
device.close();
} catch (Exception ex) {
Log.d(TAG, "Error closing device");
}
}
}


实际上,当deviceList只有一个设备(即deviceList.get(0)为“ I2C1”)时,它在openI2cDevice方法上崩溃

这是崩溃日志:
android.os.ServiceSpecificException:I / O错误(代码5)
                                                                        com.google.android.things.pio.PioException:android.os.ServiceSpecificException:I / O错误(代码5)
                                                                            在com.google.android.things.pio.I2cDeviceImpl.readRegByte(I2cDeviceImpl.java:81)
                                                                            在com.example.pitepmerature.MainActivity.printDeviceId(MainActivity.java:92)
                                                                            在com.example.pitepmerature.MainActivity.onCreate(MainActivity.java:34)
                                                                            在android.app.Activity.performCreate(Activity.java:7000)
                                                                            在android.app.Activity.performCreate(Activity.java:6991)
                                                                            在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
                                                                            在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
                                                                            在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
                                                                            在android.app.ActivityThread.-wrap11(未知来源:0)
                                                                            在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1589)
                                                                            在android.os.Handler.dispatchMessage(Handler.java:106)
                                                                            在android.os.Looper.loop(Looper.java:164)
                                                                            在android.app.ActivityThread.main(ActivityThread.java:6494)
                                                                            在java.lang.reflect.Method.invoke(本机方法)
                                                                            在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:438)
                                                                            在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
                                                                         引起原因:android.os.ServiceSpecificException:I / O错误(代码5)
                                                                            在android.os.Parcel.readException(Parcel.java:2018)
                                                                            在android.os.Parcel.readException(Parcel.java:1950)
                                                                            在com.google.android.things.pio.IPeripheralManagerClient $ Stub $ Proxy.I2cReadRegByte(IPeripheralManagerClient.java:1301)
                                                                            在com.google.android.things.pio.I2cDeviceImpl.readRegByte(I2cDeviceImpl.java:79)
                                                                            在com.example.pitepmerature.MainActivity.printDeviceId(MainActivity.java:92)
                                                                            在com.example.pitepmerature.MainActivity.onCreate(MainActivity.java:34)
                                                                            在android.app.Activity.performCreate(Activity.java:7000)
                                                                            在android.app.Activity.performCreate(Activity.java:6991)
                                                                            在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)

我也尝试将地址更改为0x77,但是没有用。还浏览了许多博客,但没有找到解决方法。

我更喜欢编写和设置所有内容的博客链接:

http://zenandroid.io/writing-a-driver-for-android-things-bme280-humidity-sensor/

请帮忙。

最佳答案

感谢大家的有用评论。我终于找到了解决方案,实际上问题出在我正在执行的示例上。另外,我想出了正确的引脚配置。
这是示例项目git链接:

https://github.com/androidthings/drivers-samples/tree/master/bmx280

另外,检查我遵循的引脚图enter image description here

关于android - 如何启用Raspberry Pi3模块的I2C(将Android Things作为操作系统使用),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47754702/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com