GPIO - Digital Input/Output

Now that we have seen all the hardware working with the Rainbow HAT in the previous chapter, we are going to learn about the first communication protocol: GPIO (General-Purpose Input/Output). We have used it already for LEDs as output and for buttons as input, and we will extend that to other outputs and inputs. Finally, we will look at a few components that use GPIO in a more generic way (DC motor controller, stepper motor, distance sensor, and LCD display)

GPIO is the simplest protocol to control devices; it just uses digital signals that can be on or off. In digital circuits, there are two possible values for what is considered a logic 1: 3.3v and 5v. The current Android Things developer kits use 3.3v. Note that the developer kits have some 5v Vcc pins, but that is used exclusively to power external circuits and has nothing to do with the value of GPIO.

GPIO in Android Things developer kits is 3.3v.

Note that the ports do not have predetermined usage, hence the general part of the name, and some components use them in a very particular way. We can configure a GPIO pin to be used for input or output at runtime, and even change that dynamically. 

A very important aspect of GPIO is that it is used for signaling and it is not intended to be used for power. Making an LED blink is about as much power as you should drain from GPIO. Do not use GPIO to power anything!

Never use a GPIO pin to power an external circuit; it may damage your developer kit.

One last important note is that the Rainbow HAT does not expose any GPIO pins, so we will have to take it out to connect the extra hardware.

And remember that, when using any peripherals, you need to request the permission USE_PERIPHERAL_IO in the manifest.

<uses-permission android:name="com.google.android.things.permission.USE_PERIPHERAL_IO" />

This chapter covers the following topics:

  • Making the code work on any developer kit
  • Using GPIO for output
  • Using GPIO for input
  • Other usages of GPIO

Let's get started with the generic way to address pins in a way that supports different boards.

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

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