I am trying to develop a sample Android-Things app using Raspberry Pi module 3 which takes temperature reading from BME280 sensor and display it on app. I have downloaded the sample project but facing an issue while opening I2cDevice with an address.
Below are the code details:
private static final 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");
}
}
}
Actually its crashing on openI2cDevice method while deviceList have only one device i.e. deviceList.get(0) is "I2C1"
Here is the crash log: android.os.ServiceSpecificException: I/O error (code 5) 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.example.pitepmerature.MainActivity.printDeviceId(MainActivity.java:92) at com.example.pitepmerature.MainActivity.onCreate(MainActivity.java:34) at android.app.Activity.performCreate(Activity.java:7000) at android.app.Activity.performCreate(Activity.java:6991) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) Caused by: android.os.ServiceSpecificException: I/O error (code 5) at android.os.Parcel.readException(Parcel.java:2018) at android.os.Parcel.readException(Parcel.java:1950) at com.google.android.things.pio.IPeripheralManagerClient$Stub$Proxy.I2cReadRegByte(IPeripheralManagerClient.java:1301) at com.google.android.things.pio.I2cDeviceImpl.readRegByte(I2cDeviceImpl.java:79) at com.example.pitepmerature.MainActivity.printDeviceId(MainActivity.java:92) at com.example.pitepmerature.MainActivity.onCreate(MainActivity.java:34) at android.app.Activity.performCreate(Activity.java:7000) at android.app.Activity.performCreate(Activity.java:6991) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
I tried changing address to 0x77 as well but didn't work. Also gone through many blogs but didn't find the fix.
Blog link which i preferred to code and setup everything:
http://zenandroid.io/writing-a-driver-for-android-things-bme280-humidity-sensor/
Please help.
pio i2c I2C1 0x12 read-reg-byte 0x76
. May be issue is in circuit. – Andrii Omelchenkorpi3:/ $ pio i2c I2C1 0x12 read-reg-byte 0x76 [WARNING:client_errors.cc(35)] error 5: I/O error
– Siddharth YadavI2C1
a valid name? What is$pio list i2c
response? – Andrii Omelchenko