Temperature and pressure sensor (Bmx280)

In a similar way, for the temperature and pressure sensor we just need to include the sensor driver into the build.gradle:

dependencies {
[...]
implementation 'com.google.android.things.contrib:driver-bmx280:+'
}

And then build an object of type Bmx280, passing the bus name:

val bmx280 = Bmx280(i2cBusName)
bmx280.setTemperatureOversampling(Bmx280.OVERSAMPLING_1X)
bmx280.setMode(Bmx280.MODE_NORMAL)
[...]

Also very simple. When using custom drivers most of the complexity is understanding the driver itself.

Note that both of the components are connected to the same bus and we can interact with both within the same activity, as we did when we displayed the temperature on the display. That is why the I2C protocol is very interesting. Instead of holding the pins for a particular circuit, it allows us to connect multiple devices to the same shared bus.

Let's look at some other drivers for components that we can use to extend the functionality of the developer kits.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.174.168