Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Using Android Things
to Detect &
Exterminate
Reptilians
Android is
EVERYWHERE (01)
(01)
Reptilians too are everywhere, but they suck.
Using Android Things to Detect & Exterminate Reptilians
Android Things
"If you can build an
app, you can build a
device!"
8-bit Distributed Piano (02)
(02)
https://riggaroo.co.za/android-things-building-distributed-piano/
Play Music Like a Scientist
Beer Can Music Player (03)
(03)
http://nilhcem.com/android-things/discovering-the-I2C-api-creating-a-capacitive-sensor-driver
Notification Cat (04)
(04)
http://nilhcem.com/android-things/bluetooth-low-energy
Google Assistant powered Robot
(05)
(05)
http://nilhcem.com/android-things/create-your-google-assistant-robots
OK, BUT, WHY?
I mean... I can use an Arduino too
Perfect for
• Doing some computation locally
• Using Google Services
• A secure platform
• Prototype and production
Perfect for
• Doing some computation locally
• Using Google Services
• A secure platform
• Prototype and production
Perfect for
• Doing some computation locally
• Using Google Services
• A secure platform
• Prototype and production
Perfect for
• Doing some computation locally
• Using Google Services
• A secure platform
• Prototype and production
Compatible boards (06)
• Raspberry Pi 3
• NXP i.MX7D/i.MX6UL
• Intel Edison/Joule (discontinued)
(06)
https://developer.android.com/things/hardware/developer-kits.html
Raspberry Pi 3 - NXP i.MX7D
Using Android Things to Detect & Exterminate Reptilians
SOM (System on module)
SOM (System on module)
Edison Candle (07)
(07)
https://github.com/androidthings/edison-candle
SOMs are pre-certified for
regulator approvals
Perfect for
• Doing some computation locally
• Using Google Services
• A secure platform
• Prototype and production
Facts
• Humans don't use their brain to its full capacity
• Humans are distracted by media, entertainment, and
politics.
• Borders, country lines lead to endless wars and conflicts
Reason?
REPTILIANS
Reptilian conspiracy theory (08)
(08)
https://www.theatlantic.com/national/archive/2013/04/12-million-americans-believe-lizard-people-run-our-country/
316706/
Reptilian
• Altered our DNA so we don't fully use our brain
• Control humans with media / politics
• Have, through the generations, ruled the world
Using Android Things
to Detect &
Exterminate
Reptilians
Detect
TensorFlow (09)
(09)
http://nilhcem.com/android/custom-tensorflow-classifier
TensorFlow codelabs
• TensorFlow for Poets (10)
• TensorFlow for Poets 2: Optimize for Mobile (11)
• Android Things Image Classifier (12)
(12)
https://codelabs.developers.google.com/codelabs/androidthings-classifier/index.html
(11)
https://codelabs.developers.google.com/codelabs/tensorflow-for-poets-2/
(10)
https://codelabs.developers.google.com/codelabs/tensorflow-for-poets/
Inception v3
• Deep learning model for image recognition
• Transfer learning
Gather lots of images
Using Android Things to Detect & Exterminate Reptilians
Transfer learning
python tensorflow/examples/image_retraining/retrain.py 
--bottleneck_dir=~/tf_files/bottlenecks 
--how_many_training_steps 4000 
--model_dir=~/tf_files/inception 
--output_graph=~/tf_files/retrained_graph.pb 
--output_labels=~/tf_files/retrained_labels.txt 
--image_dir ~/tf_files/reptilians
Generated files
• retrained_graph.pb
• retrained_labels.txt
Generated files
$ cat retrained_labels.txt
human
reptile
reptilian
Mobile model optimizations
python tensorflow/python/tools/optimize_for_inference.py 
--input=~/tf_files/retrained_graph.pb 
--output=~/tf_files/optimized_graph.pb 
--input_names="Mul" 
--output_names="final_result"
TensorFlow Android Classify
sample (13)
(13)
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android
TensorFlow Inference
val inferenceInterface = TensorFlowInferenceInterface(getAssets(), MODEL_FILE)
val labels = loadLabels() // [ "reptilian", "reptile", "human" ]
fun doRecognize(image: Bitmap) {
val pixels = image.toPixelsArray()
inferenceInterface.feed(INPUT_NODE, pixels, NETWORK_STRUCTURE)
inferenceInterface.run(arrayOf(OUTPUT_NODE))
val outputs = FloatArray(labels.size)
inferenceInterface.fetch(OUTPUT_NODE, outputs)
}
TensorFlow Inference
labels = [ "reptilian", "reptile", "human" ]
outputs = [ 0.0098f , 0.0039f , 0.9863f ]
Test data
Using Android Things to Detect & Exterminate Reptilians
Using Android Things to Detect & Exterminate Reptilians
Using Android Things to Detect & Exterminate Reptilians
Using Android Things to Detect & Exterminate Reptilians
AndroidManifest.xml
<application>
<uses-library android:name="com.google.android.things" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.IOT_LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
MainActivity
class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
"Hi! I use RelativeLayouts, lol"
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:src="@drawable/background"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:src="@drawable/reptilian"
android:layout_width="280dp"
android:layout_height="224dp"
android:layout_gravity="bottom|center_horizontal" />
</FrameLayout>
Using Android Things to Detect & Exterminate Reptilians
"Layouts are dusty"
build.gradle
dependencies {
compileOnly 'com.google.android.things:androidthings:0.5.1-devpreview'
}
Peripheral I/O APIs
Arduino Starter Kit
Peripheral I/O APIs (14)
• GPIO
• PWM
• I²C
• I²S
• SPI
• UART
(14)
https://developer.android.com/things/sdk/pio/index.html
Using Android Things to Detect & Exterminate Reptilians
Blinking LEDs
Using Android Things to Detect & Exterminate Reptilians
val pioService = PeripheralManagerService()
val ledGpio = pioService.openGpio("BCM4")
Magic happens here
ledGpio.value = true
Thread.sleep(1000)
ledGpio.value = false
LEDs (15)
(15)
https://fullmoonwanderer.deviantart.com/art/Reptilian-LED-resin-eyes-552330846
PeripheralManagerService
fun openGpio(…): Gpio
fun openPwm(…): Pwm
fun openSpiDevice(…): SpiDevice
fun openUartDevice(…): UartDevice
fun openI2cDevice(…): I2cDevice
fun openI2sDevice(…): I2sDevice
fun writeBuffer(device: I2cDevice, data: ByteArray) {
device.write(data, data.size)
}
Drivers are standard
Android libraries (16)
(17)
(17)
https://github.com/amitshekhariitbhu/awesome-android-things
(16)
https://github.com/androidthings/contrib-drivers
Using Android Things to Detect & Exterminate Reptilians
Using Android Things to Detect & Exterminate Reptilians
Using Android Things to Detect & Exterminate Reptilians
build.gradle
compile 'com.google.android.things.contrib:driver-ssd1306:0.4'
MainActivity.kt
val display = Ssd1306("I2C1")
display.setPixel(x = 0, y = 0, on = true)
val display = Ssd1306("I2C1")
val bmp = BitmapFactory.decodeResource(resources, R.drawable.background)
BitmapHelper.setBmpData(display, 0, 0, bmp, false)
display.show()
Using Android Things to Detect & Exterminate Reptilians
Android Things
TensorFlow Sample
(18)
(18)
https://github.com/androidthings/sample-tensorflow-imageclassifier
Camera
Cucumbers (?!?) (19)
(19)
https://cloud.google.com/blog/big-data/2016/08/how-a-japanese-cucumber-farmer-is-using-deep-learning-and-
tensorflow
Detect when
someone is
approaching
Ultrasonic Sensor (HC-SR04)
Ultrasonic Sensor
(HC-SR04)
1. Trigger
2. Echo
No Android Things
compatible drivers
Arduino to the rescue
Arduino to the rescue
Arduino to the rescue
void loop() {
distance = getDistanceInCentimeters();
Serial.println(distance);
delay(1000);
}
Arduino to the rescue
Read data from USB (20)
Hcsr04LiveData(this)
.observe({lifecycle}) { distanceInCm ->
Log.i(TAG, "Distance (cm): $distanceInCm")
}
(20)
https://github.com/Nilhcem/usbfun-androidthings
Using Android Things to Detect & Exterminate Reptilians
HC-SR04
Hcsr04LiveData(this)
.observe({lifecycle}) { distanceInCm ->
if (distanceInCm < 25) {
takePicture()
}
}
git commit -m "Kill reptilian when detected"
if (detected.isReptilian()) {
exterminate()
}
Exterminate
Option #1: Gun
Servo motor
Servo motor
Servo motor
PWM servo
compile 'com.google.android.things.contrib:driver-pwmservo:0.3'
Moving the servo
val servo = Servo("PWM0")
servo.setAngleRange(0.0, 180.0)
servo.setPulseDurationRange(1.0, 2.0)
servo.enable = true
servo.angle = servo.minimumAngle
Moving the servo
servo.angle = 42.0
Using Android Things to Detect & Exterminate Reptilians
Option #2:
Flamethrower
Using Android Things to Detect & Exterminate Reptilians
Flamethrower (21)
(21)
https://www.youtube.com/watch?v=fh6oJZZ27Ro
Remote control
• Nearby Connections API
• Bluetooth LE
• Embedded http server
• Whatever you want
Option #3: Chainsaw
Relay module (22)
(22)
http://nilhcem.com/android-things/google-assistant-smart-home
Magic happens here
relay.value = true
Using Android Things to Detect & Exterminate Reptilians
Using Android Things to Detect & Exterminate Reptilians
Using Android Things to Detect & Exterminate Reptilians
val colorAnimator = ValueAnimator.ofFloat(0f, 360f).apply {
duration = 8000
repeatCount = ValueAnimator.INFINITE
repeatMode = ValueAnimator.REVERSE
addUpdateListener { animator ->
val leds = getLedsColors(animator.animatedValue)
ledstrip.write(leds)
}
start()
}
val path = Path().apply {
moveTo(0f, 0f)
lineTo(0.001f, 400f / 2000f) // 0 secs -> 2.5 fps
lineTo(3f / 23f, 400f / 2000f) // 3 secs -> 2.5 fps
lineTo(6f / 23f, 20f / 2000f) // 6 secs -> 50.0 fps
lineTo(18f / 23f, 20f / 2000f) // 18 secs -> 50.0 fps
lineTo(1f, 1f) // 23 secs -> 0.5 fps
}
val frameDelayAnimator = ValueAnimator.ofInt(0, 2000).apply {
duration = 23000
repeatCount = 0
interpolator = PathInterpolator(path)
start()
}
Using Android Things
to Detect &
Exterminate
Reptilians
Using Android Things to Detect & Exterminate Reptilians
Conclusion
Android Things is Fun
Easy to get started
Reptilians suck (23)
(23)
Unless Reptilians are just an analogy to tell you not to blindly trust media and get you think about reality in a different way
Be a maker
Try Android Things, really
Using Android Things to
Detect & Exterminate Reptilians
• Twitter:
@Nilhcem
• Slides:
bit.ly/reptilethings

More Related Content

Using Android Things to Detect & Exterminate Reptilians