Slide 1

Slide 1 text

RailsConf 2017 - Phoenix, AZ Helio Cola @hacrods DIY: Home monitoring with Ruby & Pi

Slide 2

Slide 2 text

RailsConf 2017 - Phoenix, AZ hac-rods.me Hi, I am Helio Cola! • ~16 years developing SW • ~7 years since I found happiness • ~6 years full time happiness • I go by @hacrods on the internet…

Slide 3

Slide 3 text

RailsConf 2017 - Phoenix, AZ Agenda • OS installation • Why Raspberry Pi • What & Where to buy • Motion Sensor app • List of Sensors • Building Blocks • Exercises

Slide 4

Slide 4 text

RailsConf 2017 - Phoenix, AZ Exercises • OS installation: Raspbian • Capture images • Capture videos • Motion & Digital touch sensor • Buzzer Lite & Buzzer • Detect presence & record a video • Other sensors

Slide 5

Slide 5 text

RailsConf 2017 - Phoenix, AZ References • This presentation: https://speakerdeck.com/heliocola • Repo with building blocks: https://github.com/heliocola/rpi-bb

Slide 6

Slide 6 text

RailsConf 2017 - Phoenix, AZ OS installation

Slide 7

Slide 7 text

RailsConf 2017 - Phoenix, AZ OS installation Options • Raspbian • Ubuntu Core • Ubuntu Mate • Others: like Windows IOT

Slide 8

Slide 8 text

RailsConf 2017 - Phoenix, AZ OS installation Steps for Raspbian: • Format SDHC SD formatter tool: https://www.sdcard.org/downloads/formatter_4/ • Copy NOOBS to the SDHC Download link: https://downloads.raspberrypi.org/NOOBS_latest • Put SDHC in the PI, power up, and follow the instructions Instructions can be found: /INSTRUCTIONS-README.txt So, let’s do that!!! :)

Slide 9

Slide 9 text

RailsConf 2017 - Phoenix, AZ OS installation References for Ubuntu Core/Mate/Windows • Ubuntu Core: https://developer.ubuntu.com/core/get-started/raspberry-pi-2-3 • Ubuntu Mate: https://ubuntu-mate.org/download/ • Windows: http://ms-iot.github.io/content/en-US/Downloads.htm * If you are interested in one of these OSes, I have some more info I can share: @hacrods

Slide 10

Slide 10 text

RailsConf 2017 - Phoenix, AZ OS setup (raspbian) Setup steps: 1. Turn off bluetooth 2. Change keyboard to US 3. Enable SSH & Camera 4. Install MP4 Video format: $ sudo apt-get install -y gpac 5. Set static IP address: 5.1. sudo vi /etc/dhcpcd.conf 5.2. Paste at the end interface wlan0 static ip_address=192.168.1.205/24 static routers=192.168.1.1 static domain_name_servers=192.168.1.1

Slide 11

Slide 11 text

RailsConf 2017 - Phoenix, AZ Why Raspberry Pi

Slide 12

Slide 12 text

RailsConf 2017 - Phoenix, AZ Why RaspberryPi & Parallella • Because of Ray Hightower (@RayHightower), Julian Cheal (@juliancheal), and Chris (@crsexton) and Leah Sexton • Because they put a curiosity bug on my head • Because I was bored • And I’ve been doing some renovations at my house

Slide 13

Slide 13 text

RailsConf 2017 - Phoenix, AZ What & Where to buy

Slide 14

Slide 14 text

RailsConf 2017 - Phoenix, AZ What to buy • Depend of what you are trying to do • The basics: Starter kit (Pi 3, case, power supply, heatsink) and Micro SDHC • Extras: Camera, sensors, 7” Touch screen display Other gadgets

Slide 15

Slide 15 text

RailsConf 2017 - Phoenix, AZ What to buy: RaspberryPi RaspberryPi: https://www.raspberrypi.org/ • Raspberry Pi Zero W • Raspberry Pi 1 Model A+ • Raspberry Pi 2 Model B • Raspberry Pi 3 Model B

Slide 16

Slide 16 text

RailsConf 2017 - Phoenix, AZ Pi Zero Pi 1 A+ Pi 2 B Pi 3 B

Slide 17

Slide 17 text

RailsConf 2017 - Phoenix, AZ Pi Zero vs Quarter

Slide 18

Slide 18 text

RailsConf 2017 - Phoenix, AZ Pi 3 Case vs Quarter

Slide 19

Slide 19 text

RailsConf 2017 - Phoenix, AZ Differences between the Pi’ CPU RAM Display USB Others Pi Zero W 1Ghz, Single-core CPU 512MB RAM CSI (v1.2 only) and Mini HDMI USB On-The-Go ports Half the size of a Model A+, with twice the utility Pi 1 A+ 700Mhz ARM CPU 512MB RAM HDMI One USB 2.0 Port No Ethernet Low power 0.5W and 1W Pi 2 B A 900MHz quad- core ARM Cortex- A7 CPU 1GB RAM CSI, DSI, Full HDMI 4 USB 2.0 ports Ethernet Pi 3 B 1.2GHz 64-bit quad-core ARMv8 CPU 1GB RAM CSI, DSI, Full HDMI 4 USB ports Ethernet, 802.11n, Bluetooth & BLE

Slide 20

Slide 20 text

RailsConf 2017 - Phoenix, AZ Differences between the Pi’ Price Dimensions GPIO Pi Zero W $10 65mm long x 30mm wide x 5mm thick HAT-compatible 40-pin header Pi 1 A+ $24.95 65mm x 56mm 40 GPIO pins Pi 2 B $39.95 40 GPIO pins Pi 3 B $39.95 86.9mm x 58.5mm x 19.1mm 40 GPIO pins

Slide 21

Slide 21 text

RailsConf 2017 - Phoenix, AZ What to buy: Parallella • Parallella: https://www.parallella.org/ Parallella Microserver (P1600) Parallella Desktop (P1601) Parallella Embedded (P1602)

Slide 22

Slide 22 text

RailsConf 2017 - Phoenix, AZ The differences CPU Price RAM HDMI USB GPIO Microserver 18 cores Zynq Z7010 667 MHz (max 1 GHz) $99 1GB RAM No 1 port No Desktop 18 cores Zynq Z7010 667 MHz (max 1 GHz) $149 1GB RAM Yes 1 port 24 ports Embedded 18 cores Zynq Z7020 667 MHz (max 1 GHz) $264.94 1GB RAM Yes 1 port 48 ports

Slide 23

Slide 23 text

RailsConf 2017 - Phoenix, AZ Buy: where • Micro center near you • else if you are near Element14: buy it • else if you are near Adafruit: buy it • else (if) you are near Amazon: buy it

Slide 24

Slide 24 text

RailsConf 2017 - Phoenix, AZ Pi 3: On a TV

Slide 25

Slide 25 text

RailsConf 2017 - Phoenix, AZ Pi 3: On a touch screen

Slide 26

Slide 26 text

RailsConf 2017 - Phoenix, AZ Motion Sensor App

Slide 27

Slide 27 text

RailsConf 2017 - Phoenix, AZ Motion Sensor App • My Hello World for RaspberryPi • Detect “movement” • Do something: • Call an API • Sound an alarm • Turn on the lights and play a music • Turn on the Camera & record it until no more presence (or 5-10s) • Report event + video

Slide 28

Slide 28 text

RailsConf 2017 - Phoenix, AZ Motion Sensor App Pi 0 W: front door Pi 0 W: back door Pi 0 W: game room Or Heroku, AWS, Digital Ocean, etc Pi 3: local server

Slide 29

Slide 29 text

RailsConf 2017 - Phoenix, AZ Motion Sensor App • Ruby as usual: rvm, ruby, rack, rails, rails-api, postgres, etc. Data model

Slide 30

Slide 30 text

RailsConf 2017 - Phoenix, AZ PIR Motion Sensor

Slide 31

Slide 31 text

RailsConf 2017 - Phoenix, AZ PIR Motion Sensor • Reference: https://cdn-learn.adafruit.com/downloads/pdf/pir-passive-infrared-proximity-motion-sensor.pdf Passive infrared Pyroelectric IR motion

Slide 32

Slide 32 text

RailsConf 2017 - Phoenix, AZ Monitoring a PIR sensor Reference: https://github.com/jwhitehorn/pi_piper

Slide 33

Slide 33 text

RailsConf 2017 - Phoenix, AZ List of Sensors

Slide 34

Slide 34 text

RailsConf 2017 - Phoenix, AZ PIR Motion Sensor

Slide 35

Slide 35 text

RailsConf 2017 - Phoenix, AZ Smoke and Combustible Gas

Slide 36

Slide 36 text

RailsConf 2017 - Phoenix, AZ Buzzer

Slide 37

Slide 37 text

RailsConf 2017 - Phoenix, AZ Carbon Monoxide

Slide 38

Slide 38 text

RailsConf 2017 - Phoenix, AZ Digital touch

Slide 39

Slide 39 text

RailsConf 2017 - Phoenix, AZ Flame

Slide 40

Slide 40 text

RailsConf 2017 - Phoenix, AZ Vibration

Slide 41

Slide 41 text

RailsConf 2017 - Phoenix, AZ Temperature and Humidity

Slide 42

Slide 42 text

RailsConf 2017 - Phoenix, AZ Sound

Slide 43

Slide 43 text

RailsConf 2017 - Phoenix, AZ Water level

Slide 44

Slide 44 text

RailsConf 2017 - Phoenix, AZ Exercises

Slide 45

Slide 45 text

RailsConf 2017 - Phoenix, AZ Exercises: building blocks • General Purpose Input and Output pins: aka GPIO • (binary) raspistill: capture photos • (binary) raspivid: capture videos • (gem) pi_piper: read and write from/to GPIO Reference: https://github.com/heliocola/rpi-bb

Slide 46

Slide 46 text

RailsConf 2017 - Phoenix, AZ Building block: GPIO • It is a generic pin in the raspberry board that allows you to control and integrate with the outside world at run time. • Read something from the world • Or Write something to the world Reference: https://www.raspberrypi.org/documentation/usage/gpio-plus-and-raspi2/README.md

Slide 47

Slide 47 text

RailsConf 2017 - Phoenix, AZ Building block: GPIO • Reference: http://blog.mcmelectronics.com/ post/Raspberry-Pi-3-GPIO-Pin-Layout#.WP5- u1PyslU

Slide 48

Slide 48 text

RailsConf 2017 - Phoenix, AZ Building block: raspistill • Reference: https://www.raspberrypi.org/documentation/usage/camera/raspicam/raspistill.md

Slide 49

Slide 49 text

RailsConf 2017 - Phoenix, AZ Building block: raspivid • Reference: https://www.raspberrypi.org/documentation/usage/camera/raspicam/raspivid.md MP4Box: Install: $ sudo apt-get install -y gpac Run: $ MP4Box -add pivideo.h264 pivideo.mp4

Slide 50

Slide 50 text

RailsConf 2017 - Phoenix, AZ Building block: pi_piper • Reference: https://github.com/jwhitehorn/pi_piper Read from a GPIO

Slide 51

Slide 51 text

RailsConf 2017 - Phoenix, AZ Building block: pi_piper • Reference: https://github.com/jwhitehorn/pi_piper Write to a GPIO

Slide 52

Slide 52 text

RailsConf 2017 - Phoenix, AZ Army of Pi Zero W & a Pi3 • Pi Zero 1.3 (raspberry): ssh [email protected] • Pi 3 (raspberry): monitor/mouse/keyboard ssh [email protected] • List of Pi Zero's (W): raspberry ssh [email protected] ssh [email protected] ssh [email protected] ssh [email protected] ssh [email protected] ssh [email protected] (case)

Slide 53

Slide 53 text

RailsConf 2017 - Phoenix, AZ Rules for accessing the Pis • Create folder with your name • If there is already one, add _1, _2, etc • Do not delete folder that you haven’t created • The Pi’s don’t have access to the internet

Slide 54

Slide 54 text

RailsConf 2017 - Phoenix, AZ Army of Pi Zero W & a Pi3 Wifi to access the Raspberry Pi’s: SSID: RailsConf2017_Pi Security: WPA/WPA2 Personal Passphrase: raspberrypi2017

Slide 55

Slide 55 text

RailsConf 2017 - Phoenix, AZ Exercise: capture a photo Use raspistill utility to capture a photo from the camera • Building block: Raspistill • Reference: https://www.raspberrypi.org/documentation/usage/camera/raspicam/raspistill.md

Slide 56

Slide 56 text

RailsConf 2017 - Phoenix, AZ Exercise: capture a video Use raspivid utility to capture a video from the camera Limit the video to 5 seconds as the test Raspberry PI only have 32Gb micro disk • Building block: Raspivid • Reference: https://www.raspberrypi.org/documentation/usage/camera/raspicam/raspivid.md

Slide 57

Slide 57 text

RailsConf 2017 - Phoenix, AZ Exercise: Motion & Digital touch sensor Use the motion (PIR) or digital touch sensor to trigger a presence event • Building block: GPIO Use GPIO 4 to read input sensor • Reference: https://github.com/jwhitehorn/pi_piper

Slide 58

Slide 58 text

RailsConf 2017 - Phoenix, AZ Exercise: Lite Buzzer & Buzzer Lite Buzzer: turn on and off the buzzer by writing to a GPIO Buzzer: read value from motion (or digital touch) sensor and turn on/off the buzzer • Building block GPIO Use GPIO 4 to read from a sensor Use GPIO 17 to write to the buzzer • Reference: https://github.com/jwhitehorn/pi_piper

Slide 59

Slide 59 text

RailsConf 2017 - Phoenix, AZ Exercise: Detect Presence & record a video When you detect a presence (motion or digital touch) start recording a video for a small period of time • Building blocks: Raspivid GPIO Use GPIO 4 to read from a sensor Use GPIO 17 to write to the buzzer

Slide 60

Slide 60 text

RailsConf 2017 - Phoenix, AZ References https://github.com/heliocola/rpi-bb http://rayhightower.com/ http://juliancheal.co.uk http://www.codeography.com/ https://www.raspberrypi.org/ https://www.parallella.org/ https://developer.ubuntu.com/core/get-started/installation-medias https://ubuntu-mate.org/raspberry-pi/ https://developer.ubuntu.com/core/get-started/raspberry-pi-2-3 https://ubuntu-mate.org/download/ http://ms-iot.github.io/content/en-US/Downloads.htm https://www.element14.com/community/docs/DOC-78156/l/raspberry-pi-7-touchscreen-display https://cdn-learn.adafruit.com/downloads/pdf/pir-passive-infrared-proximity-motion-sensor.pdf https://github.com/jwhitehorn/pi_piper http://bit.ly/k8s-rpi

Slide 61

Slide 61 text

RailsConf 2017 - Phoenix, AZ http://bit.ly/k8s-rpi Helio Cola @hacrods Thank you! Any questions?