Code Monkey home page Code Monkey logo

sample-nativepio's Introduction

Native Peripheral I/O

This Android Things app runs basic code that exercises the Native PIO APIs from C++. Each sample is an Android module that can be run independently.

Note: The Android Things Console will be turned down for non-commercial use on January 5, 2022. For more details, see the FAQ page.

Screenshots

Blink

Blink sample demo

(Watch the demo on YouTube)

Button

Button sample demo

(Watch the demo on YouTube)

Speaker

Speaker sample demo

(Watch the demo on YouTube)

Pre-requisites

  • Android Things compatible board
  • Android Studio 2.2+
  • Android NDK bundle

For the Blink sample:

  • 1 LED
  • 1 resistor
  • 2 jumper wires
  • 1 breadboard

For the Button sample:

  • 1 push button
  • 1 resistor
  • 2 jumper wires
  • 1 breadboard

For the Speaker sample:

  • 1 piezo buzzer
  • 2 jumper wires
  • 1 breadboard

Build and install

Download the latest Android Things native library release and extract it in the project root directory. You will need to change the name of the extracted directory to libandroidthings.

The project root directory should contain the following native library directories:

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

On Android Studio, select the module in the select box by the "Run" button, and then click on the "Run" button.

If you prefer to run on the command line, type

./gradlew <module>:installDebug
adb shell am start com.example.androidthings.nativepio/.<ModuleActivity>

Sample Specifics

Blink

Schematics for Raspberry Pi 3

    ./gradlew blink:installDebug
    adb shell am start com.example.androidthings.nativepio/android.app.NativeActivity

Blinks an LED connected to a GPIO pin.

Button

Schematics for Raspberry Pi 3

    ./gradlew button:installDebug
    adb shell am start com.example.androidthings.nativepio/android.app.NativeActivity

Logs to logcat when a button connected to a GPIO pin is pressed. Make sure you use a pull-down or pull-up resistor to avoid fluctuation.

Speaker

Schematics for Raspberry Pi 3

    ./gradlew speaker:installDebug
    adb shell am start com.example.androidthings.nativepio/android.app.NativeActivity

Plays an annoying alarm sound on the PWM speaker. Stop it by turning off the Raspberry Pi.

Enable auto-launch behavior

This sample app is currently configured to launch only when deployed from your development machine. To enable the main activity to launch automatically on boot, add the following intent-filter to the app's manifest file:

<activity ...>

    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.HOME"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>

</activity>

License

Copyright 2016 The Android Open Source Project, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

sample-nativepio's People

Contributors

atn832 avatar daverim avatar irataxy avatar mangini avatar proppy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sample-nativepio's Issues

Latest version of `native-libandroidthings` makes the build fail

The latest version of native-libandroidthings (6900125a40e7ce4f76f094b67ba78a2defdb7709) is breaking the build of this project:

$ ./gradlew build

> Task :blink:generateJsonModelDebug
-- Check for working C compiler: /home/leinardi/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
-- Check for working C compiler: /home/leinardi/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /home/leinardi/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
-- Check for working CXX compiler: /home/leinardi/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found AndroidThings: /home/leinardi/Workspace/androidThings/sample-nativepio/libandroidthings/armeabi-v7a/lib/libandroidthings.so  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/leinardi/Workspace/androidThings/sample-nativepio/blink/.externalNativeBuild/cmake/debug/armeabi-v7a
-- Check for working C compiler: /home/leinardi/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
-- Check for working C compiler: /home/leinardi/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /home/leinardi/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
-- Check for working CXX compiler: /home/leinardi/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found AndroidThings: /home/leinardi/Workspace/androidThings/sample-nativepio/libandroidthings/x86/lib/libandroidthings.so  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/leinardi/Workspace/androidThings/sample-nativepio/blink/.externalNativeBuild/cmake/debug/x86

> Task :blink:externalNativeBuildDebug
Build blink x86
[1/6] Building C object CMakeFiles/native-app-glue.dir/home/leinardi/android-sdk/ndk-bundle/sources/android/native_app_glue/android_native_app_glue.c.o
[2/6] Building CXX object CMakeFiles/android-system-properties.dir/home/leinardi/Workspace/androidThings/sample-nativepio/android-system-properties/AndroidSystemProperties.cpp.o
[3/6] Linking C static library libnative-app-glue.a
[4/6] Linking CXX static library libandroid-system-properties.a
[5/6] Building CXX object CMakeFiles/blink.dir/blink.cpp.o
[6/6] Linking CXX shared library /home/leinardi/Workspace/androidThings/sample-nativepio/blink/build/intermediates/cmake/debug/obj/x86/libblink.so
FAILED: : && /home/leinardi/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=i686-none-linux-android --gcc-toolchain=/home/leinardi/android-sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/linux-x86_64 --sysroot=/home/leinardi/android-sdk/ndk-bundle/sysroot -fPIC -isystem /home/leinardi/android-sdk/ndk-bundle/sysroot/usr/include/i686-linux-android -D__ANDROID_API__=26 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11  -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot /home/leinardi/android-sdk/ndk-bundle/platforms/android-26/arch-x86 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -L/home/leinardi/android-sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now  -u ANativeActivity_onCreate -shared -Wl,-soname,libblink.so -o /home/leinardi/Workspace/androidThings/sample-nativepio/blink/build/intermediates/cmake/debug/obj/x86/libblink.so CMakeFiles/blink.dir/blink.cpp.o  -landroid -llog libnative-app-glue.a /home/leinardi/Workspace/androidThings/sample-nativepio/libandroidthings/x86/lib/libandroidthings.so libandroid-system-properties.a -latomic -lm "/home/leinardi/android-sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86/libc++_static.a" "/home/leinardi/android-sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86/libc++abi.a" && :
/home/leinardi/android-sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/linux-x86_64/lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: error: /home/leinardi/Workspace/androidThings/sample-nativepio/libandroidthings/x86/lib/libandroidthings.so: incompatible target
/home/leinardi/Workspace/androidThings/sample-nativepio/blink/src/main/cpp/blink.cpp:51: error: undefined reference to 'APeripheralManagerClient_new'
/home/leinardi/Workspace/androidThings/sample-nativepio/blink/src/m
ain/cpp/blink.cpp:54: error: undefined reference to 'APeripheralManagerClient_openGpio'
/home/leinardi/Workspace/androidThings/sample-nativepio/blink/src/main/cpp/blink.cpp:56: error: undefined reference to 'AGpio_setDirection'
/home/leinardi/Workspace/androidThings/sample-nativepio/blink/src/main/cpp/blink.cpp:61: error: undefined reference to 'AGpio_getValue'
/home/leinardi/Workspace/androidThings/sample-nativepio/blink/src/main/cpp/blink.cpp:65: error: undefined reference to 'AGpio_setValue'
/home/leinardi/Workspace/androidThings/sample-nativepio/blink/src/main/cpp/blink.cpp:82: error: undefined reference to 'AGpio_delete'
/home/leinardi/Workspace/androidThings/sample-nativepio/blink/src/main/cpp/blink.cpp:83: error: undefined reference to 'APeripheralManagerClient_delete'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':blink:externalNativeBuildDebug'.
> Build command failed.
  Error while executing process /media/Dati_ext4/android-sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /home/leinardi/Workspace/androidThings/sample-nativepio/blink/.externalNativeBuild/cmake/debug/x86 --target blink}
  [1/6] Building C object CMakeFiles/native-app-glue.dir/home/leinardi/android-sdk/ndk-bundle/sources/android/native_app_glue/android_native_app_glue.c.o
  [2/6] Building CXX object CMakeFiles/android-system-properties.dir/home/leinardi/Workspace/androidThings/sample-nativepio/android-system-properties/AndroidSystemProperties.cpp.o
  [3/6] Linking C static library libnative-app-glue.a
  [4/6] Linking CXX static library libandroid-system-properties.a
  [5/6] Building CXX object CMakeFiles/blink.dir/blink.cpp.o
  [6/6] Linking CXX shared library /home/leinardi/Workspace/androidThings/sample-nativepio/blink/build/intermediates/cmake/debug/obj/x86/libblink.so
  FAILED: : && /home/leinardi/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=i686-none-linux-android --gcc-toolchain=/home/leinardi/android-sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/linux-x86_64 --sysroot=/home/leinardi/android-sdk/ndk-bundle/sysroot -fPIC -isystem /home/leinardi/android-sdk/ndk-bundle/sysroot/usr/include/i686-linux-android -D__ANDROID_API__=26 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11  -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot /home/leinardi/android-sdk/ndk-bundle/platforms/android-26/arch-x86 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -L/home/leinardi/android-sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now  -u ANativeActivity_onCreate -shared -Wl,-soname,libblink.so -o /home/leinardi/Workspace/androidThings/sample-nativepio/blink/build/intermediates/cmake/debug/obj/x86/libblink.so CMakeFiles/blink.dir/blink.cpp.o  -landroid -llog libnative-app-glue.a /home/leinardi/Workspace/androidThings/sample-nativepio/libandroidthings/x86/lib/libandroidthings.so libandroid-system-properties.a -latomic -lm "/home/leinardi/android-sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86/libc++_static.a" "/home/leinardi/android-sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86/libc++abi.a" && :
  /home/leinardi/android-sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/linux-x86_64/lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: error: /home/leinardi/Workspace/androidThings/sample-nativepio/libandroidthings/x86/lib/libandroidthings.so: incompatible target
  /home/leinardi/Workspace/androidThings/sample-nativepio/blink/src/main/cpp/blink.cpp:51: error: undefined reference to 'APeripheralManagerClient_new'
  /home/leinardi/Workspace/androidThings/sample-nativepio/blink/src/main/cpp/blink.cpp:54: error: undefined reference to 'APeripheralManagerClient_openGpio'
  /home/leinardi/Workspace/androidThings/sample-nativepio/blink/src/main/cpp/blink.cpp:56: error: undefined reference to 'AGpio_setDirection'
  /home/leinardi/Workspace/androidThings/sample-nativepio/blink/src/main/cpp/blink.cpp:61: error: undefined reference to 'AGpio_getValue'
  /home/leinardi/Workspace/androidThings/sample-nativepio/blink/src/main/cpp/blink.cpp:65: error: undefined reference to 'AGpio_setValue'
  /home/leinardi/Workspace/androidThings/sample-nativepio/blink/src/main/cpp/blink.cpp:82: error: undefined reference to 'AGpio_delete'
  /home/leinardi/Workspace/androidThings/sample-nativepio/blink/src/main/cpp/blink.cpp:83: error: undefined reference to 'APeripheralManagerClient_delete'
  clang++: error: linker command failed with exit code 1 (use -v to see invocation)
  ninja: build stopped: subcommand failed.


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

Android Studio 3.2 can NOT parse project

Hello Folks,
just wanted to report that Android Studio 3.2 does NOT like this project. In the first step, it complains about MIPS support missing - this is fixed by manually updating the version of the Gradle plugin:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-beta05'

After that, allow Android Studio to perform missing updates to the project.

Next, add the missing repo to allprojects:
allprojects {
repositories {
jcenter()
google()

}

}

androidStudio build failed

I try to import project, but find this problem when gradle build.

Error:error: linker command failed with exit code 1 (use -v to see
Error:A problem occurred configuring project ':blink'.

executing external native build for cmake F:\AndroidStudioWorkSpace\AndroidThinds\sample-nativepio\blink\src\main\cpp\CMakeLists.txt

How can i solve it.

Runtime Issue on Raspberry PI

I've tried to test the Native PIO speaker example on a Raspberry PI and got the following runtime error:

java.lang.IllegalArgumentException: Unable to find native library speaker using classloader: dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/com.google.android.things.jar", zip file "/oem/app/speaker-debug.apk"],nativeLibraryDirectories=[/oem/lib/speaker-debug, /system/lib, /vendor/lib, /system/lib, /vendor/lib]]]

This is similar to errors we've seen compiling other armeabi-v7a libraries for the PI. Has anyone had success using those libraries on the PI, or is there an arm64-v8a version of the native libraries available?

Build fail

building the sample fails:
image

Looks like the project path (variable) uses incorrect slash in the path

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.