This lesson is going to show you how to create a peripheral driver library in AndroidThings. We’ll discuss just what is a driver library and the benefits of using one. Then we will take an AndroidThings gesture sensor and convert it to a driver library.
A driver library is a reusable piece of code that you can run to control a peripheral sensor or actuator at a higher level of abstraction without having to worry about how the peripheral works or its low level communication details. You can write them yourself or alternatively use driver libraries other people have written and published online.
When complete, you will understand how to create and when driver libraries are useful in your Android Things applications. You will be able to modularise your IoT application and separate driver libraries for cleaner code and potential reuse on your other projects.
This lesson references the code already written for the ZX Sensor in this UART lesson you maybe want to check that out first, although it is not necessary at all.
For this lesson, no actual hardware is needed. However if you want to test out the completed demo application. You will need:
- A Raspberry Pi 3 flashed with Android Things
- A ZX Gesture Sensor
If you need to buy the Raspberry Pi to start with Android Things I would recommend this kit. It contains:
- Raspberry Pi 3
- Rainbow HAT
- Pibow Coupé for Android Things
- 2.5A official Raspberry Pi worldwide power supply
- 8GB microSD card