$30 off During Our Annual Pro Sale. View Details »

DIY: Home monitoring with Ruby & Pi

Helio Cola
February 04, 2017

DIY: Home monitoring with Ruby & Pi

Ruby and RaspberryPi are available to us for quite sometime and this talk is meant to discuss how to use Ruby to explore things on a RaspberryPi. From a practical point of view, we will go through installation, setup, and build a simple Motion Sensor application on a RaspberryPi.

In a world we teach ourselves a lot of things, why not do it Ruby & Pi way? Let’s get our hands on a piece of hardware, understand what it takes to setup one up, install a couple of libraries, Ruby, RVM, RBENV, a GUI. Let’s get a couple of sensors: motion, temperature, humidity, tsunami, ectoplasm and see if we detect a cool thing or two.

Helio Cola

February 04, 2017
Tweet

More Decks by Helio Cola

Other Decks in Programming

Transcript

  1. FOSDEM <3 Ruby 2017
    DIY: Home monitoring
    with Ruby & Pi
    Helio Cola
    @hacrods

    View Slide

  2. FOSDEM <3 Ruby 2017
    hac-rods.me
    Hi, I am Helio Cola!
    • ~16 years developing SW
    • 6/7 years since I found happiness
    • ~5 years full time happiness
    • I go by @hacrods on the internet…

    View Slide

  3. FOSDEM <3 Ruby 2017
    Agenda
    • Why RaspberryPi, Parallella, Micro PCs
    • What is available
    • Buy, Install, Setup
    • Development Environment
    • Motion (and others) Sensor App

    View Slide

  4. FOSDEM <3 Ruby 2017
    Why RaspberryPi, Parallella, Micro PCs

    View Slide

  5. FOSDEM <3 Ruby 2017
    Why RaspberryPi & Parallella
    • Because of Ray Hightower (http://rayhightower.com/)
    • Because I was curious
    • Because I was bored
    • And I’ve been doing some renovations at my house

    View Slide

  6. FOSDEM <3 Ruby 2017
    What is available

    View Slide

  7. FOSDEM <3 Ruby 2017
    What is available
    • RaspberryPi: https://www.raspberrypi.org/
    Raspberry Pi Zero
    Raspberry Pi 1 Model A+
    Raspberry Pi 2 Model B
    Raspberry Pi 3 Model B

    View Slide

  8. FOSDEM <3 Ruby 2017
    Pi Zero
    Pi 1 A+
    Pi 2 B Pi 3 B

    View Slide

  9. FOSDEM <3 Ruby 2017
    Pi Zero vs Quarter

    View Slide

  10. FOSDEM <3 Ruby 2017
    Pi 3 Case vs Quarter

    View Slide

  11. FOSDEM <3 Ruby 2017
    Differences between the Pi’
    CPU RAM Display USB Others
    Pi
    Zero
    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

    View Slide

  12. FOSDEM <3 Ruby 2017
    Differences between the Pi’
    Price Dimensions GPIO
    Pi Zero $5
    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

    View Slide

  13. FOSDEM <3 Ruby 2017
    What is available
    • Parallella: https://www.parallella.org/
    Parallella Microserver (P1600)
    Parallella Desktop (P1601)
    Parallella Embedded (P1602)

    View Slide

  14. FOSDEM <3 Ruby 2017
    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

    View Slide

  15. FOSDEM <3 Ruby 2017
    Microcontrolers & Motherboards
    ASUS Mini ITX Motherboards
    (processor bought separately)
    Intel GALILEO: Intel®
    Quark SoC X1000
    Application Processor

    View Slide

  16. FOSDEM <3 Ruby 2017
    Stick PCs
    ASUS VivoStick TS10-B017D
    Intel Atom Z8350
    Intel Compute Stick
    CS125: Windows 10

    View Slide

  17. FOSDEM <3 Ruby 2017
    Buy, Install, Setup

    View Slide

  18. FOSDEM <3 Ruby 2017
    Where to buy
    • If you are near Element14: buy it
    • If you are near Adafruit: buy it
    • If you are near Amazon: buy it
    • Otherwise: find micro center near you

    View Slide

  19. FOSDEM <3 Ruby 2017
    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

    View Slide

  20. FOSDEM <3 Ruby 2017
    Pi 3: Install, Setup
    • If your machine is Windows/Linux/Mac:
    https://developer.ubuntu.com/core/get-started/
    installation-medias
    • If your machine is Linux:
    https://ubuntu-mate.org/raspberry-pi/

    View Slide

  21. FOSDEM <3 Ruby 2017
    Pi3: Install, Setup
    • My one tip to all of you:
    don’t use ‘bs=32m’
    use ‘bs=1m’ instead

    View Slide

  22. FOSDEM <3 Ruby 2017
    Pi 3: OS Download
    • Ubuntu Core, Ubuntu Mate, Windows 10 IoT Core
    Core: https://developer.ubuntu.com/core/get-started/
    raspberry-pi-2-3
    Mate: https://ubuntu-mate.org/download/
    Windows (still on my TODO list): http://ms-
    iot.github.io/content/en-US/Downloads.htm

    View Slide

  23. FOSDEM <3 Ruby 2017
    Pi 3: Installation on Mac
    • More or less these were my steps:
    1. Download the image, un-archive, insert SD card
    2. Run:

    View Slide

  24. FOSDEM <3 Ruby 2017
    Pi 3: Setup
    • First boot: it will take longer
    • It may automatically extend the file system (Core)
    • Or you will have to do it manually (Mate)
    • Follow the instructions on the display
    • Configure your network
    • And an administrator account

    View Slide

  25. FOSDEM <3 Ruby 2017
    Pi 3: On a TV

    View Slide

  26. FOSDEM <3 Ruby 2017
    Pi 3: On a touch screen

    View Slide

  27. FOSDEM <3 Ruby 2017
    Pi 3: From your machine
    $ ssh @

    View Slide

  28. FOSDEM <3 Ruby 2017
    Development Environment

    View Slide

  29. FOSDEM <3 Ruby 2017
    (My) Development Environment
    • UbuntuMate OS: a GUI on top an Ubuntu distribution
    • RVM, RBENV
    • Postgres & PgAdmin
    • Text Editor: Atom or VIM
    • Chrome & Firefox: more than enough
    • A monitor or TV, keyboard and mouse

    View Slide

  30. FOSDEM <3 Ruby 2017
    7” Touch Screen display
    https://www.element14.com/community/docs/DOC-78156/l/raspberry-pi-7-
    touchscreen-display

    View Slide

  31. FOSDEM <3 Ruby 2017
    7” Touch Screen display

    View Slide

  32. FOSDEM <3 Ruby 2017
    7” Touch Screen display

    View Slide

  33. FOSDEM <3 Ruby 2017
    7” Touch Screen display

    View Slide

  34. FOSDEM <3 Ruby 2017
    Motion Sensor App

    View Slide

  35. FOSDEM <3 Ruby 2017
    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
    • Reporte event + video

    View Slide

  36. FOSDEM <3 Ruby 2017
    Motion Sensor App
    • Ruby as usual: rvm, ruby, rack, rails, rails-api,
    postgres, etc.
    Data model

    View Slide

  37. FOSDEM <3 Ruby 2017
    Motion Sensor App
    • CRUD admin app & api to allow events to come in

    View Slide

  38. FOSDEM <3 Ruby 2017
    PIR Motion Sensor

    View Slide

  39. FOSDEM <3 Ruby 2017
    PIR Motion Sensor
    • Reference: https://cdn-learn.adafruit.com/downloads/pdf/pir-passive-infrared-
    proximity-motion-sensor.pdf
    Passive infrared
    Pyroelectric
    IR motion

    View Slide

  40. FOSDEM <3 Ruby 2017
    Monitoring a PIR sensor
    Reference: https://github.com/jwhitehorn/pi_piper

    View Slide

  41. FOSDEM <3 Ruby 2017
    Sensor’ journey

    View Slide

  42. FOSDEM <3 Ruby 2017
    PIR Motion Sensor

    View Slide

  43. FOSDEM <3 Ruby 2017
    Smoke and
    Combustible
    Gas

    View Slide

  44. FOSDEM <3 Ruby 2017
    Buzzer

    View Slide

  45. FOSDEM <3 Ruby 2017
    Carbon
    Monoxide

    View Slide

  46. FOSDEM <3 Ruby 2017
    Digital
    touch

    View Slide

  47. FOSDEM <3 Ruby 2017
    Flame

    View Slide

  48. FOSDEM <3 Ruby 2017
    Vibration

    View Slide

  49. FOSDEM <3 Ruby 2017
    Temperature
    and Humidity

    View Slide

  50. FOSDEM <3 Ruby 2017
    Sound

    View Slide

  51. FOSDEM <3 Ruby 2017
    Water level

    View Slide

  52. FOSDEM <3 Ruby 2017
    (My) Home monitoring system

    View Slide

  53. FOSDEM <3 Ruby 2017
    (My) Home monitoring system
    experiment
    • We will go away for 2 months
    • Our contractor will come by regularly
    • And walk through the sensor
    • From November 1st to December 21st 2016
    • Let’s look at the logs

    View Slide

  54. FOSDEM <3 Ruby 2017
    (My) Home monitoring system
    experiment
    My theories:
    There is a ghost in my house
    There is IR noise near my sensor
    The sensor is broken
    Or can also be a bug in my code

    View Slide

  55. FOSDEM <3 Ruby 2017
    References
    http://rayhightower.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

    View Slide

  56. FOSDEM <3 Ruby 2017
    Thank you!
    http://bit.ly/k8s-rpi
    Helio Cola
    @hacrods

    View Slide