====== Having a great fun with GPIO on Android ====== ** You must install the C2 Android Marshmallow Ver2.8 image or higher to access the 40pin GPIO properly.** This WiKi explains how to make an Android app which can access GPIO ports.\\ You need to install [[https://developer.android.com/studio/index.html|Google Android Studio]] on your host PC.\\ And add [[https://developer.android.com/ndk/guides/index.html|NDK and tools]] first before starting below steps.\\ We tested following steps on Android Studio 2.3 and NDK R14. ===== Ubuntu/Linux ===== ==== Configure NDK path for Android Studio ==== Add this line in your ~/.bashrc file after installing Android NDK. export NDK_PATH=[YOUR ANDROID SDK LOCATION]/ndk-bundle For example export NDK_PATH=/home/codewalker/projects/android-sdks/ndk-bundle You can find the Android SDK location on this menu (File -> Settings -> Appearance & Behavior -> System Settings -> Android SDK)\\ {{:en:screenshot_from_2017-05-18_11_15_43.png?nolink&800|}} After editing the bashrc file, you have to login again or type "**source ~/.bashrc**" on the command line. ==== Download example code ==== Download C2-WiringPi NDK library and App source code Project from [[https://github.com/codewalkerster/example-wiringPi| github]]. $ sudo apt install git $ git clone https://github.com/codewalkerster/example-wiringPi -b mater ==== Run Android Studio and open the downloaded project. ==== {{:en:screenshot_2017-05-18_10-33-55.png?nolink|}} ==== Build the project to make an apk package ==== Select **Build -> Make Project** menu.\\ You will see a couple of error messages and click following texts to complete the build process.\\ //**Install missing platform(s) and sync project**\\ **Install Build Tools 25.0.2 and sync project**// \\ And you will have an apk file to run it on your ODROID. ===== Windows ===== ==== Set environment PATH to point NDK folder path ==== {{:en:advanced_system_setting.png?nolink|}} {{:en:environment.png?nolink|}} {{:en:ndk_path.png?nolink|}} Reboot Windows. ==== Install git client program ==== [[https://git-for-windows.github.io/]] ==== Clone project ==== {{:en:git.png?nolink&700|}} https://github.com/codewalkerster/example-wiringPi Select origin/master. {{:en:branch.png?nolink|}} ==== Install NDK ==== Toos -> Android -> SDK Manager {{:en:android_sdk.png?nolink$500|}} {{:en:ndk_install.png?nolink&500|}} ===== Features of example project ===== ==== ADC and GPIO output ==== Read ADC value and show the voltage level with 19 LEDs on GPIO output.\\ {{http://dn.odroid.com/homebackup/android_wiringPi_ADC.png?600|}} {{youtube>zyfULOkj0Vw?medium}} ==== PWM ==== Basic PWM control example. You can choose the number of PWM outputs 1 or 2.\\ And control the frequency and duty ratio.\\ {{http://dn.odroid.com/homebackup/android_wiringPi_PWM.png?600|}} === Gmail Notifier example === This is fun and useful project using the PWM port. \\ When you watch video or play games, you might lose a notification of the important email or message. \\ The flag is moving by servo motor which is connected to a PWM pin on 40pin GPIO port. \\ https://github.com/codewalkerster/GMailNotifier {{youtube>Vvq77w87RWQ?medium}} ==== I2C ==== An example code to access our [[http://www.hardkernel.com/main/products/prdt_info.php?g_code=G144533067183|Weather Board]] to measure the temperature, humidity, atmospheric pressure, altitude and visible/invisible light intensities via I2C interface.\\ {{:en:img_20170526_153143.jpg?600}} {{:en:screenshot_2016-04-25-02-38-54.png?600|}} ==== UART ==== A demo software for Sending and Receiving characters via UART interface. \\ {{http://dn.odroid.com/homebackup/android_wiringPi_UART.png?600|}} ==== 1 Wire ==== A demo software to access 1-wire protocol interfaced DS18S20 temperature sensor.\\ {{http://dn.odroid.com/homebackup/android_wiringPi_1wire.png?600|}} ===== Kernel for i2c ===== Open File Manager app. Edit /storage/internal/boot.ini like this. (near end of file). Before edit. movi read dtb 0 ${dtbaddr} # load kernel from vat or boot partition. movi read boot 0 ${loadaddr} #fatload mmc 0:1 ${loadaddr} Image booti ${loadaddr} - ${dtbaddr} After edit. movi read dtb 0 ${dtbaddr} # load kernel from vat or boot partition. #movi read boot 0 ${loadaddr} fatload mmc 0:1 ${loadaddr} Image booti ${loadaddr} - ${dtbaddr} Load kernel image from vfat partition built i2c. If you could not find 'fatload' command, remove /storage/internal/boot.ini file and reboot system.