Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Taking the hard out of hardware

206 views

Published on

Software geeks fear hardware. It's a fact of life: code is easy to write and easy to change, but hardware catches on fire if you put it together wrong. But this is changing! Hardware is becoming cheaper and easier to work with every day and can often be managed with the same tools you use to deploy code to the cloud. Join self-described software guy and hardware-phobe Ronald McCollam for a guided trip from the safe world of web development to the scary lands of hardware and back again. We'll see how easy it can be to make the leap from managed code to microprocessors!

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Taking the hard out of hardware

  1. 1. Taking the "hard" out of hardware @RonaldMcCollam mccollam@gmail.com / ronald@resin.io www.ronaldmccollam.com resin.io
  2. 2. int main() { About me and how I learned hardware Hardware for Linux geeks Going smaller: microcontrollers Building a project Where to go from here resin.io
  3. 3. Who am I? Linux geek from way back (when Slackware was the easy distro!) Terrified of hardware… at least until recently Email: mccollam@gmail.com or ronald@resin.io Twitter: @RonaldMcCollam Web: www.ronaldmccollam.com resin.io
  4. 4. Software is "safe"... resin.io
  5. 5. resin.ioPhoto: Tina Rataj-Berard
  6. 6. Hardware is scary! resin.io
  7. 7. resin.ioPhoto: João Alves
  8. 8. How I learned hardware I kept hearing about this "Internet of Things"... because it was constantly broken! Weirdly, seeing other people fail made me feel better about making mistakes. resin.io
  9. 9. How I learned hardware I learned Linux by doing, breaking, and redoing. Hardware would have to go the same way! resin.io
  10. 10. Single biggest tip Don't be afraid of "toy" projects! resin.io
  11. 11. How I learned hardware Start "big" and go small If you know software, do what you can in software! Let someone else worry about the hardware, at least at first Lots to choose from! Raspberry Pi Beaglebone Samsung ARTIK NextThing C.H.I.P. Onion Omega … so many more! resin.io
  12. 12. Hardware for Linux geeks: Raspberry Pi Very common Cheap: $5 - $35 Lots of connectivity and expansion ● USB ● Ethernet ● HDMI ● WiFi / Bluetooth (on some models) ● HATs: Hardware Attached on Top ● GPIO resin.io
  13. 13. Hardware for Linux geeks: GPIO GPIO: General Purpose Input/Output Can be read or write, digital or analog Lots of ways to access in Linux sysfs exposure: /sys/class/gpio resin.io
  14. 14. "hello world" for hardware resin.io
  15. 15. Using GPIO in Python #!/usr/bin/env python import RPi.GPIO as GPIO # What pin the LED is connected to: led = 11 # Set up that pin to be used for output: GPIO.setup(led, GPIO.OUT) # Set the pin value to 'high', turning it on: GPIO.output(led, GPIO.HIGH) resin.io
  16. 16. Using GPIO in bash(!) #!/bin/bash # What pin the LED is connected to: LED=11 # Mark the pin as 'exported' and that it's used for output: echo "$LED" > /sys/class/gpio/export echo "out" > /sys/class/gpio/gpio$LED/direction # Set the pin value to 'high' (1) turning it on: echo "1" > /sys/class/gpio/gpio$LED/value resin.io
  17. 17. Adding more functionality Most devices support some sort of add-ons via the GPIO pins E.g. Raspberry Pi Sense HAT Accelerometer, gyroscope, magnetometer, thermometer, barometer, hygrometer Cool LED matrix Common protocols for other add-ons: I2 C - Inter-Integrated Circuit SPI - Serial Peripheral Interface USB - Universal Serial Bus (you know this!) resin.io
  18. 18. The Raspberry Pi and similar devices are Linux computers! You can use python, gcc/gdb, node.js, bash right on the device Build packages, use git (Shameless plug: resin.io lets you git push your code and have it run on these devices directly in a Docker container! Really useful for production code...) Tools, tools, tools resin.io
  19. 19. resin.ioPhoto: Click and Boo
  20. 20. Going smaller: microcontrollers Non-Linux devices - simple OS (or none at all!) Usually very limited if you come from a desktop/web background Many frameworks exist to work with these microPython (Python) Johnny-Five (javascript) eLua/nodeMCU (Lua) Arduino (C++) … many others! resin.io
  21. 21. Embedded hardware: ESP8266 Great hardware support: I2 C, SPI, UART (serial), GPIO, WiFi Reasonable power use (including deep sleep modes) Widely used (so there are a lot of add-ons and tutorials available) Small and CHEAP! ($16.95 for a full breakout board from Adafruit, can be less than $3 in small quantities from Chinese sources) resin.io
  22. 22. C++ on embedded devices: Arduino Probably the most common embedded framework C/C++ based LOTS of existing libraries Open source Expanded to support a vast array of hardware resin.io
  23. 23. LEDs with Arduino #define LED_PIN 5 void setup() { pinMode(LED_PIN, OUTPUT); } void loop() { digitalWrite(LED_PIN, HIGH); delay(1000); digitalWrite(LED_PIN, LOW); delay(1000); } resin.io
  24. 24. Adding on Remember I2 C and SPI? They work in microcontrollers too! Every type of sensor you can think of Output too Displays, speakers Even GPS and networking! resin.io
  25. 25. A real project Dryer is in the basement People 3 floors up want to know when it's finished ● ESP8266 with Arduino framework ($3) ● I2 C LCD module ($4) ● 4x4 matrix keypad ($1) ● I2 C I/O module for keypad ($1.50) ● MPU 6050 accelerometer ($1) Total: $10.50 (Plus paper for keypad, wood for case, screws, USB cable for power -- stuff I had already) resin.io
  26. 26. Lots of libraries // ESP8266 WiFi support: #include <ESP8266WiFi.h> // I2C support: #include <Wire.h> // LCD support: #include <hd44780.h> #include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header // Matrix keypad support: #include <Keypad_I2C/Keypad_I2C.h> #include <Keypad.h> // MQTT support: #include <PubSubClient.h> // Accelerometer support: #include <MPU6050.h> resin.io
  27. 27. Simple C code void set_status_lcd() { lcd.setCursor(0, 0); lcd.print(dryerRunning ? "running" : "stopped"); lcd.print(" "); // Calculation for real temperature from // https://www.i2cdevlib.com/forums/topic/53-mpu-6050-temperature-compensation/ String temp = String(round((mpu.getTemperature()/340. + 36.53) * 10) / 10.0).substring(0, 4); lcd.print(temp + (char)223 + "C"); // 223 == degree sign ⁰ } void set_notify_mqtt() { // Publish MQTT message mqtt.publish(mqttTopicPerson, notifyPerson, true); mqtt.publish(mqttTopicMethod, notifyMethod, true); } resin.io
  28. 28. resin.io
  29. 29. resin.ioPhoto: Randall Bruder
  30. 30. Resources: where to get hardware Top recommendations: ● Adafruit - https://www.adafruit.com ○ The "Huzzah" board is a great way to get started with the ESP8266 -- lots of add-ons and libraries ● Sparkfun - https://www.sparkfun.com ○ The "ESP8266 Thing Dev Board" looks similar to the "Huzzah" from Adafruit (but I haven't used it) More esoteric: ● AliExpress (look in 'electronic components and supplies') https://www.aliexpress.com/category/502/electronic-components-supplies.html resin.io
  31. 31. Resources: frameworks and tutorials ● Arduino: https://www.arduino.cc ● Johnny-Five: http://johnny-five.io ● MicroPython: https://micropython.org ● NodeMCU (Lua environment for ESP8266): http://nodemcu.com ● https://learn.adafruit.com ● https://learn.sparkfun.com resin.io
  32. 32. Resources: tools ● PlatformIO (makes installing/managing Arduino libraries easier): http://platformio.org ● resin.io (makes building and deploying to Linux devices easier): https://resin.io resin.io
  33. 33. Thank you! @RonaldMcCollam mccollam@gmail.com / ronald@resin.io www.ronaldmccollam.com resin.io

×