Getting an Lidar product (using Lidar Lite v3) to interface with a Raspberry Pi 3 running Android things (using the 0.6.1 preview). At the moment; I'm just trying to scan the I2C1 bus for the active device (looking at 0x62). I have a very simple Android things project but I'm getting a permissions issue. I can't see anything in the documentation about specific permissions needed.

This line in my code:

    for (int address = 0x60; address < 0x70; address++) {
        //auto-close the devices
        try (final I2cDevice device = service.openI2cDevice("I2C1", address)) {

fails with the following exception:

com.google.android.things.pio.PioException: android.os.ServiceSpecificException: Caller does not own I2C1(0x60) (code 13)

Am I missing something?

  • Is this running in the main UI thread? Do you have any other apps installed which may concurrently claim I2C? Dec 18 '17 at 7:12
  • Nick, This is a "clean" RasPi with fresh Android Things installed. I didn't install anything using I2C; but unsure if the kernel has. Full Source is on GitHub at: github.com/Zitt/RGB_Walkway Dec 19 '17 at 9:13
  • Can you not do the try with resources and just do a regular try? It may be that this format is handling the I/O in an unusual way outside of the normal application context. Dec 19 '17 at 18:48

My issue was a misunderstanding of "try-with-resources" which automatically closes the device when the scope is exited. My in scope device.close() was closing and then the "try-with-resources" scope tried to close it a second time which was generating the error.

https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html is a bit dense but has all the information you should need about the try-with-resources block.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.