0

I can't get data by I2C bus in Android Things on Raspberry Pi 3.

I connect Android Things on RPi and DS18B20(Temperature Sensor). Connect to RPi

and run the I2C address scan App (https://github.com/dennisg/i2c-address-scanner), but can't find available address.

    for (int address = 0; address < 256; address++) {

        //auto-close the devices
        try (final I2cDevice device = peripheralManagerService.openI2cDevice(BoardDefaults.getI2cBus(), address)) {

            try {
                device.readRegByte(TEST_REGISTER);
                Log.i(TAG, String.format(Locale.US, "Trying: 0x%02X - SUCCESS", address));
            } catch (final IOException e) {
                Log.i(TAG, String.format(Locale.US, "Trying: 0x%02X - FAIL", address));
            }

        } catch (final IOException e) {
            //in case the openI2cDevice(name, address) fails
        }
    }

How do I get data by I2C?

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79

2 Answers2

2

The linked test project appears to use the I2C protocol poorly in several ways.

First, it makes the assumption that there is only a single I2C bus on a particular board. Although that is true now, it may not scale to additional SOMs that support Android Things in the future.

Second, it assumes the register address to read from (0x00). This may have worked for whatever device the developer started with, but a large number of I2C peripherals may not respond to that address.

You should take a look at the datasheet for this device. After a cursory examination, it seems that there is no register corresponding to 0x00. Additionally, it has a custom read flow that would make it difficult to use the snippet above. The microcontroller getting these values on your sensor probably throws them away and returns no signal.

It may be useful to read through the datasheet again. It seems like the sensor is "one-wire" instead of I2C. While the two protocols may be similar, using the built in readByte method may make some assumptions in the data transmission that may not match the peripheral protocol exactly.

Nick Felker
  • 11,536
  • 1
  • 21
  • 35
0

As Nick Felker wrote in his answer DS18B20 has 1-Wire interface and you can't connect it to Raspberry Pi with Android Things directly. You should use industrial (e.g DS2482-100) or custom MCU-based (like in that project) 1-Wire <-> I2C converter, or other (e.g. USB <-> 1-Wire, UART<-> 1-Wire) converters.

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79