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!
1. Taking the "hard" out of hardware
@RonaldMcCollam
mccollam@gmail.com / ronald@resin.io
www.ronaldmccollam.com
resin.io
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. 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
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. How I learned hardware
I learned Linux by doing, breaking, and redoing.
Hardware would have to go the same way!
resin.io
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. 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. 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
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. 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. 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. 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
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. 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. 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
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. 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
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