Skip to content

Most visited

Recently visited

navigation

Native PIO

The native PIO APIs let you write C/C++ code to control GPIO, PWM, I2C, SPI and UART peripherals that access the same underlying peripheral service as the standard PIO APIs. This lets you write an Android Things app purely in C/C++ or extend a Java-based Android Things app with C or C++ code that uses the native PIO APIs (for example, porting existing drivers written for other embedded platforms).

Getting started with the NDK

If you've never used the NDK, see the Android NDK Getting Started guide to download and install the NDK. The documentation also has detailed information on how to use the NDK.

Get the Android Things native library

The native PIO APIs are available in the Android Things native library. You copy the entire directory into the root directory of your Android Studio project. The directory structure looks like this:

libandroidthings/
  ${ABI}/
    include/
      pio/
        *.h
    lib/
      libandroidthings.so

You'll include the header files in the include/pio directory to compile your app and link the libandroidthings.so shared object for the appropriate ABI when you package your app. The FindAndroidThings.cmake CMake module file is also available to help you configure new NDK projects to use the Android Things native library.

See the header files for the library in the Github repository for more information and documentation.

Native PIO sample

The native PIO sample (see Github repository) shows you how to blink an LED, get input from a button, and actuate a PWM speaker by calling the native PIO APIs inside a NativeActivity, which lets you create an activity using only C/C++.

To run the sample:

  1. Clone or download the sample from Github.
  2. See the README.md file for prerequisites to running the sample.
  3. Extract or copy the native PIO libraries into the project's root directory.
  4. Connect your device to the development machine and run one of the sample's modules: blink, button, or speaker.

    • In Android Studio, select the module in the drop-down menu by the Run button, then click Run button.
    • On the command line, run the following commands from your project root directory:

      ./gradlew [blink|button|speaker]:installDebug
      adb shell am start com.example.androidthings.nativepio/android.app.NativeActivity
      
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.