# Gpio

Summary:[Constants](https://developer.android.com/reference/com/google/android/things/pio/Gpio#constants)\|[Methods](https://developer.android.com/reference/com/google/android/things/pio/Gpio#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/com/google/android/things/pio/Gpio#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/com/google/android/things/pio/Gpio#)  

# Gpio

`
public


interface
Gpio
`  
`


implements

`[Closeable](https://developer.android.com/reference/java/io/Closeable)`


`

|------------------------------------|
| com.google.android.things.pio.Gpio |

|---|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/com/google/android/things/pio/Gpio#)Known Indirect Subclasses [GpioDriver](https://developer.android.com/reference/com/google/android/things/userdriver/pio/GpioDriver) |-----------------------------------------------------------------------------------------------------------|-------------------| | [GpioDriver](https://developer.android.com/reference/com/google/android/things/userdriver/pio/GpioDriver) | GPIO user driver. | ||

<br />

*** ** * ** ***

Controls a GPIO pin.

General-purpose input/output (GPIO) pins are physical pins on an integrated circuit that can be controlled via software. A GPIO pin can be configured as input to read the voltage value or as output to change the voltage value. It only understands logic values (`true`/`false`) which maps physically to a low value (the pin has the same voltage as Ground) or high value (the pin has the same voltage as IOREF). GPIOs are frequently used to communicate with simple peripherals like sensors and actuators.

Opening a GPIO pin takes ownership of it for the whole system, preventing anyone else from opening/accessing the GPIO until you call[close()](https://developer.android.com/reference/com/google/android/things/pio/Gpio#close()). Forgetting to call[close()](https://developer.android.com/reference/com/google/android/things/pio/Gpio#close())will prevent anyone (including the same process/app) from using the GPIO.

## Summary

|                                                                                                                                                                                                                                   ### Constants                                                                                                                                                                                                                                    ||
|-------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | [ACTIVE_HIGH](https://developer.android.com/reference/com/google/android/things/pio/Gpio#ACTIVE_HIGH) [ActiveType](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setActiveType(int))constant to select active high, which means that logical`true`corresponds with high voltage.                                                                                                                                                               |
| `int` | [ACTIVE_LOW](https://developer.android.com/reference/com/google/android/things/pio/Gpio#ACTIVE_LOW) [ActiveType](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setActiveType(int))constant to select active low, which means that logical`true`corresponds with low voltage.                                                                                                                                                                   |
| `int` | [DIRECTION_IN](https://developer.android.com/reference/com/google/android/things/pio/Gpio#DIRECTION_IN) [Direction](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setDirection(int))constant used to configure a GPIO pin as an input.                                                                                                                                                                                                         |
| `int` | [DIRECTION_OUT_INITIALLY_HIGH](https://developer.android.com/reference/com/google/android/things/pio/Gpio#DIRECTION_OUT_INITIALLY_HIGH) [Direction](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setDirection(int))constant used to configure a GPIO pin as an output and initialize its state to`true`(equivalent of calling[setValue(true)](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setValue(boolean))). |
| `int` | [DIRECTION_OUT_INITIALLY_LOW](https://developer.android.com/reference/com/google/android/things/pio/Gpio#DIRECTION_OUT_INITIALLY_LOW) [Direction](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setDirection(int))constant used to configure a GPIO pin as an output and initialize its state to`false`(equivalent of calling[setValue(false)](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setValue(boolean))). |
| `int` | [EDGE_BOTH](https://developer.android.com/reference/com/google/android/things/pio/Gpio#EDGE_BOTH) [EdgeType](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setEdgeTriggerType(int))constant used to configure the GPIO interrupt to trigger on any edge (when[getValue()](https://developer.android.com/reference/com/google/android/things/pio/Gpio#getValue())changes state in either direction).                                            |
| `int` | [EDGE_FALLING](https://developer.android.com/reference/com/google/android/things/pio/Gpio#EDGE_FALLING) [EdgeType](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setEdgeTriggerType(int))constant used to configure the GPIO interrupt to trigger on falling edge (when[getValue()](https://developer.android.com/reference/com/google/android/things/pio/Gpio#getValue())goes from`true`to`false`).                                           |
| `int` | [EDGE_NONE](https://developer.android.com/reference/com/google/android/things/pio/Gpio#EDGE_NONE) [EdgeType](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setEdgeTriggerType(int))constant used to configure the GPIO interrupt to never trigger.                                                                                                                                                                                             |
| `int` | [EDGE_RISING](https://developer.android.com/reference/com/google/android/things/pio/Gpio#EDGE_RISING) [EdgeType](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setEdgeTriggerType(int))constant used to configure the GPIO interrupt to trigger on rising edge (when[getValue()](https://developer.android.com/reference/com/google/android/things/pio/Gpio#getValue())goes from`false`to`true`).                                              |

|                                                                                                                                                                                                                                                        ### Public methods                                                                                                                                                                                                                                                        ||
|-------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` abstract void`                                                              | ` `[close](https://developer.android.com/reference/com/google/android/things/pio/Gpio#close())`() ` Releases the GPIO pin.                                                                                                                                                                                                                                                                                                                        |
| ` default `[String](https://developer.android.com/reference/java/lang/String) | ` `[getName](https://developer.android.com/reference/com/google/android/things/pio/Gpio#getName())`() ` Returns the I/O name.                                                                                                                                                                                                                                                                                                                     |
| ` abstract boolean`                                                           | ` `[getValue](https://developer.android.com/reference/com/google/android/things/pio/Gpio#getValue())`() ` Gets the current value of the GPIO pin (for GPIO pins configured as input only).                                                                                                                                                                                                                                                        |
| ` default void`                                                               | ` `[registerGpioCallback](https://developer.android.com/reference/com/google/android/things/pio/Gpio#registerGpioCallback(com.google.android.things.pio.GpioCallback))`(`[GpioCallback](https://developer.android.com/reference/com/google/android/things/pio/GpioCallback)` callback) ` Registers a callback for GPIO edge interrupts.                                                                                                           |
| ` abstract void`                                                              | ` `[registerGpioCallback](https://developer.android.com/reference/com/google/android/things/pio/Gpio#registerGpioCallback(android.os.Handler, com.google.android.things.pio.GpioCallback))`(`[Handler](https://developer.android.com/reference/android/os/Handler.html)` handler, `[GpioCallback](https://developer.android.com/reference/com/google/android/things/pio/GpioCallback)` callback) ` Registers a callback for GPIO edge interrupts. |
| ` abstract void`                                                              | ` `[setActiveType](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setActiveType(int))`(int activeType) ` Sets the active level.                                                                                                                                                                                                                                                                                       |
| ` abstract void`                                                              | ` `[setDirection](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setDirection(int))`(int direction) ` Sets the direction of the GPIO pin.                                                                                                                                                                                                                                                                             |
| ` abstract void`                                                              | ` `[setEdgeTriggerType](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setEdgeTriggerType(int))`(int edgeTriggerType) ` Sets the interrupt trigger type.                                                                                                                                                                                                                                                              |
| ` abstract void`                                                              | ` `[setValue](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setValue(boolean))`(boolean value) ` Sets the value of the GPIO pin (for GPIO pins configured as output only).                                                                                                                                                                                                                                           |
| ` abstract void`                                                              | ` `[unregisterGpioCallback](https://developer.android.com/reference/com/google/android/things/pio/Gpio#unregisterGpioCallback(com.google.android.things.pio.GpioCallback))`(`[GpioCallback](https://developer.android.com/reference/com/google/android/things/pio/GpioCallback)` callback) ` Unregisters an interrupt callback.                                                                                                                   |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/com/google/android/things/pio/Gpio#)From interface` `[java.io.Closeable](https://developer.android.com/reference/java/io/Closeable)` ` |------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[close](https://developer.android.com/reference/java/io/Closeable#close())`() ` Closes this stream and releases any system resources associated with it. | ||
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/com/google/android/things/pio/Gpio#)From interface` `[java.lang.AutoCloseable](https://developer.android.com/reference/java/lang/AutoCloseable)` ` |------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[close](https://developer.android.com/reference/java/lang/AutoCloseable#close())`() ` Closes this resource, relinquishing any underlying resources. | ||

## Constants

### ACTIVE_HIGH

```
int ACTIVE_HIGH
```

[ActiveType](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setActiveType(int))constant to select active high, which means that logical`true`corresponds with high voltage.

<br />

Constant Value: 1 (0x00000001)  

### ACTIVE_LOW

```
int ACTIVE_LOW
```

[ActiveType](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setActiveType(int))constant to select active low, which means that logical`true`corresponds with low voltage.

<br />

Constant Value: 0 (0x00000000)  

### DIRECTION_IN

```
int DIRECTION_IN
```

[Direction](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setDirection(int))constant used to configure a GPIO pin as an input.

<br />

Constant Value: 0 (0x00000000)  

### DIRECTION_OUT_INITIALLY_HIGH

```
int DIRECTION_OUT_INITIALLY_HIGH
```

[Direction](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setDirection(int))constant used to configure a GPIO pin as an output and initialize its state to`true`(equivalent of calling[setValue(true)](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setValue(boolean))).

<br />

Constant Value: 1 (0x00000001)  

### DIRECTION_OUT_INITIALLY_LOW

```
int DIRECTION_OUT_INITIALLY_LOW
```

[Direction](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setDirection(int))constant used to configure a GPIO pin as an output and initialize its state to`false`(equivalent of calling[setValue(false)](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setValue(boolean))).

<br />

Constant Value: 2 (0x00000002)  

### EDGE_BOTH

```
int EDGE_BOTH
```

[EdgeType](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setEdgeTriggerType(int))constant used to configure the GPIO interrupt to trigger on any edge (when[getValue()](https://developer.android.com/reference/com/google/android/things/pio/Gpio#getValue())changes state in either direction).

<br />

Constant Value: 3 (0x00000003)  

### EDGE_FALLING

```
int EDGE_FALLING
```

[EdgeType](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setEdgeTriggerType(int))constant used to configure the GPIO interrupt to trigger on falling edge (when[getValue()](https://developer.android.com/reference/com/google/android/things/pio/Gpio#getValue())goes from`true`to`false`).

<br />

Constant Value: 2 (0x00000002)  

### EDGE_NONE

```
int EDGE_NONE
```

[EdgeType](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setEdgeTriggerType(int))constant used to configure the GPIO interrupt to never trigger.

<br />

Constant Value: 0 (0x00000000)  

### EDGE_RISING

```
int EDGE_RISING
```

[EdgeType](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setEdgeTriggerType(int))constant used to configure the GPIO interrupt to trigger on rising edge (when[getValue()](https://developer.android.com/reference/com/google/android/things/pio/Gpio#getValue())goes from`false`to`true`).

<br />

Constant Value: 1 (0x00000001)

## Public methods

### close

```
void close ()
```

Releases the GPIO pin.

This must be called in order for the GPIO pin to be released and be available to other users. Closing a GPIO does not change its state, for example if it closed while outputting a high signal, it will continue to output high until another user opens it and changes its state.

<br />

|                                                   Throws                                                   ||
|----------------------------------------------------------------------------|--------------------------------|
| [IOException](https://developer.android.com/reference/java/io/IOException) | if the GPIO is already closed. |

### getName

```
String getName ()
```

Returns the I/O name.

<br />

|                                  Returns                                   ||
|--------------------------------------------------------------------|--------|
| [String](https://developer.android.com/reference/java/lang/String) | <br /> |

### getValue

```
boolean getValue ()
```

Gets the current value of the GPIO pin (for GPIO pins configured as input only).

<br />

|                                                    Returns                                                     ||
|-----------|-----------------------------------------------------------------------------------------------------|
| `boolean` | the state of the GPIO pin. Return value is undefined if the GPIO is configured as an output. <br /> |

|                                    Throws                                     ||
|----------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException) |   |

### registerGpioCallback

```
void registerGpioCallback (GpioCallback callback)
```

Registers a callback for GPIO edge interrupts.

Equivalent to[registerGpioCallback(callback, null)](https://developer.android.com/reference/com/google/android/things/pio/Gpio#registerGpioCallback(android.os.Handler, com.google.android.things.pio.GpioCallback)).

<br />

|                          Parameters                          ||
|------------|--------------------------------------------------|
| `callback` | `GpioCallback`: GpioCallback to register. <br /> |

|                                         Throws                                          ||
|----------------------------------------------------------------------------|-------------|
|                                                                            | IOException |
| [IOException](https://developer.android.com/reference/java/io/IOException) |             |

**See also:**

- [registerGpioCallback(Handler, GpioCallback)](https://developer.android.com/reference/com/google/android/things/pio/Gpio#registerGpioCallback(android.os.Handler, com.google.android.things.pio.GpioCallback))
- [unregisterGpioCallback(GpioCallback)](https://developer.android.com/reference/com/google/android/things/pio/Gpio#unregisterGpioCallback(com.google.android.things.pio.GpioCallback))  

### registerGpioCallback

```
void registerGpioCallback (Handler handler, 
                GpioCallback callback)
```

Registers a callback for GPIO edge interrupts.

The type of edges to watch for must be first set with[setEdgeTriggerType(int)](https://developer.android.com/reference/com/google/android/things/pio/Gpio#setEdgeTriggerType(int)).

<br />

|                                          Parameters                                           ||
|------------|-----------------------------------------------------------------------------------|
| `handler`  | `Handler`: Handler to run callbacks on, or`null`to use the current thread. <br /> |
| `callback` | `GpioCallback`: GpioCallback to register. <br />                                  |

|                                         Throws                                          ||
|----------------------------------------------------------------------------|-------------|
|                                                                            | IOException |
| [IOException](https://developer.android.com/reference/java/io/IOException) |             |

**See also:**

- [registerGpioCallback(GpioCallback)](https://developer.android.com/reference/com/google/android/things/pio/Gpio#registerGpioCallback(com.google.android.things.pio.GpioCallback))
- [unregisterGpioCallback(GpioCallback)](https://developer.android.com/reference/com/google/android/things/pio/Gpio#unregisterGpioCallback(com.google.android.things.pio.GpioCallback))  

### setActiveType

```
void setActiveType (int activeType)
```

Sets the active level.

<br />

|                                                                                                                  Parameters                                                                                                                   ||
|--------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `activeType` | `int`: One of[ACTIVE_LOW](https://developer.android.com/reference/com/google/android/things/pio/Gpio#ACTIVE_LOW)or[ACTIVE_HIGH](https://developer.android.com/reference/com/google/android/things/pio/Gpio#ACTIVE_HIGH). <br /> |

|                                                       Throws                                                        ||
|--------------------------------------------------------------------------------------------------------|-------------|
|                                                                                                        | IOException |
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) |             |
| [IOException](https://developer.android.com/reference/java/io/IOException)                             |             |

### setDirection

```
void setDirection (int direction)
```

Sets the direction of the GPIO pin.

<br />

|                                                                                                                                                                                                                Parameters                                                                                                                                                                                                                 ||
|-------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `direction` | `int`: Direction to set. One of[DIRECTION_IN](https://developer.android.com/reference/com/google/android/things/pio/Gpio#DIRECTION_IN),[DIRECTION_OUT_INITIALLY_HIGH](https://developer.android.com/reference/com/google/android/things/pio/Gpio#DIRECTION_OUT_INITIALLY_HIGH),[DIRECTION_OUT_INITIALLY_LOW](https://developer.android.com/reference/com/google/android/things/pio/Gpio#DIRECTION_OUT_INITIALLY_LOW). <br /> |

|                                                       Throws                                                        ||
|--------------------------------------------------------------------------------------------------------|-------------|
|                                                                                                        | IOException |
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) |             |
| [IOException](https://developer.android.com/reference/java/io/IOException)                             |             |

### setEdgeTriggerType

```
void setEdgeTriggerType (int edgeTriggerType)
```

Sets the interrupt trigger type.

The trigger type is based on the logical pin value, not the physical voltage. For example,[EDGE_RISING](https://developer.android.com/reference/com/google/android/things/pio/Gpio#EDGE_RISING)will always trigger on a`false`-to-`true`transition, but if the GPIO is configured as[ACTIVE_LOW](https://developer.android.com/reference/com/google/android/things/pio/Gpio#ACTIVE_LOW)this will actually be caused by a drop from high to low voltage.

<br />

|                                                                                                                                                                                                                                           Parameters                                                                                                                                                                                                                                            ||
|-------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `edgeTriggerType` | `int`: Type of trigger to use for interrupt. One of[EDGE_NONE](https://developer.android.com/reference/com/google/android/things/pio/Gpio#EDGE_NONE),[EDGE_RISING](https://developer.android.com/reference/com/google/android/things/pio/Gpio#EDGE_RISING),[EDGE_FALLING](https://developer.android.com/reference/com/google/android/things/pio/Gpio#EDGE_FALLING),[EDGE_BOTH](https://developer.android.com/reference/com/google/android/things/pio/Gpio#EDGE_BOTH). <br /> |

|                                                       Throws                                                        ||
|--------------------------------------------------------------------------------------------------------|-------------|
|                                                                                                        | IOException |
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) |             |
| [IOException](https://developer.android.com/reference/java/io/IOException)                             |             |

### setValue

```
void setValue (boolean value)
```

Sets the value of the GPIO pin (for GPIO pins configured as output only).

<br />

|                Parameters                ||
|---------|---------------------------------|
| `value` | `boolean`: Value to set. <br /> |

|                                    Throws                                     ||
|----------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException) |   |

### unregisterGpioCallback

```
void unregisterGpioCallback (GpioCallback callback)
```

Unregisters an interrupt callback.

<br />

|                           Parameters                           ||
|------------|----------------------------------------------------|
| `callback` | `GpioCallback`: GpioCallback to unregister. <br /> |

**See also:**

- [registerGpioCallback(Handler, GpioCallback)](https://developer.android.com/reference/com/google/android/things/pio/Gpio#registerGpioCallback(android.os.Handler, com.google.android.things.pio.GpioCallback))  
-

  ## Interfaces

  - [Gpio](https://developer.android.com/reference/com/google/android/things/pio/Gpio)
  - [GpioCallback](https://developer.android.com/reference/com/google/android/things/pio/GpioCallback)
  - [I2cDevice](https://developer.android.com/reference/com/google/android/things/pio/I2cDevice)
  - [Pwm](https://developer.android.com/reference/com/google/android/things/pio/Pwm)
  - [SpiDevice](https://developer.android.com/reference/com/google/android/things/pio/SpiDevice)
  - [UartDevice](https://developer.android.com/reference/com/google/android/things/pio/UartDevice)
  - [UartDeviceCallback](https://developer.android.com/reference/com/google/android/things/pio/UartDeviceCallback)
-

  ## Classes

  - [PeripheralManager](https://developer.android.com/reference/com/google/android/things/pio/PeripheralManager)