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


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
  • Login to see the comments

  • Be the first to like this

Taking the hard out of hardware

  1. 1. Taking the "hard" out of hardware @RonaldMcCollam /
  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
  3. 3. Who am I? Linux geek from way back (when Slackware was the easy distro!) Terrified of hardware… at least until recently Email: or Twitter: @RonaldMcCollam Web:
  4. 4. Software is "safe"...
  5. 5. resin.ioPhoto: Tina Rataj-Berard
  6. 6. Hardware is scary!
  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.
  9. 9. How I learned hardware I learned Linux by doing, breaking, and redoing. Hardware would have to go the same way!
  10. 10. Single biggest tip Don't be afraid of "toy" projects!
  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!
  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
  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
  14. 14. "hello world" for hardware
  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)
  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
  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!)
  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: 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
  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!
  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)
  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
  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); }
  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!
  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)
  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>
  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 // 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); }
  28. 28.
  29. 29. resin.ioPhoto: Randall Bruder
  30. 30. Resources: where to get hardware Top recommendations: ● Adafruit - ○ The "Huzzah" board is a great way to get started with the ESP8266 -- lots of add-ons and libraries ● Sparkfun - ○ 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')
  31. 31. Resources: frameworks and tutorials ● Arduino: ● Johnny-Five: ● MicroPython: ● NodeMCU (Lua environment for ESP8266): ● ●
  32. 32. Resources: tools ● PlatformIO (makes installing/managing Arduino libraries easier): ● (makes building and deploying to Linux devices easier):
  33. 33. Thank you! @RonaldMcCollam /