![Page 1: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/1.jpg)
GOT PYTHON I/OIOT DEVELOPMENT IN PYTHON VIA GPIO
![Page 2: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/2.jpg)
HISTORICAL PERSPECTIVEHOW I CAME UP WITH THE HAIR-BRAINED IDEA TO USE PYTHON FOR IOT
![Page 3: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/3.jpg)
NODEBOTS DAYPut on by Suz Hinton and Pawel Szymczykowski
![Page 4: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/4.jpg)
THE LEXICUTIONERDesigned a built using SumoBot Jr. (Pawelbot) by Adam Englander and Lexi Glazer
![Page 5: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/5.jpg)
PHYSICAL ACCESS SYSTEMComprised of Raspberry Pi B, power converter, electronic door latch, inline switch. Software is Raspbian with Python 2.7 and Twisted.
![Page 6: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/6.jpg)
PYTHON IOT STARTER KITRASPBERRY PI FOR THE WIN
![Page 7: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/7.jpg)
STARTER KIT HARDWARE
• Raspberry Pi
• Micro USB with AC converter for power
• Cat 5 network cable
• USB Keyboard
• HDMI cable
• HDMI capable display – not shown
• 3.3V LED with (2) female to female connectors
![Page 8: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/8.jpg)
STARTER KIT SOFTWARE
• Raspbian• Pre-installed on SD card
• Download installer (requires SD card reader): https://www.raspberrypi.org/downloads/
• Python 2.7• Pre-installed on Raspbian
![Page 9: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/9.jpg)
ACCESSING GPIO FROM LINUX BASED SYSTEMSIT’S SO EASY YOU WON’T BELIEVE IT
![Page 10: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/10.jpg)
GENERAL PURPOSE INPUT/OUTPUT (GPIO)
• A generic pin on an integrated circuit (IC) whose behavior is controlled at runtime
• Use to control and transfer data to and from external devices to the IC
• Available on all general purpose IC boards
![Page 11: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/11.jpg)
IT’S ALL IN THE FILE SYSTEM
• Linux GPIO Sysfs Interface for Userspace
• Root directory is at /sys/class/gpio
• Control Interfaces
• Pin Interfaces
![Page 12: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/12.jpg)
CONTROL INTERFACE
• “export” creates a node to expose a GPIO port to the user space
• “echo 18 > /sys/class/gpio/export” will create a gpio18 node at “/sys/class/gpio/gpio18”
• “unexport” removes the node for a GPIO port from the user space• “echo 18 > /sys/class/gpio/unexport” removes
the gpio18 node
![Page 13: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/13.jpg)
GPIO SIGNALS
• “direction” determines the direction of a pin. Valid values are “in” and “out”. “in” is used for interrupts
• “echo out > /sys/class/gpio/gpio18/direction” will set GPIO pin 18 ’s direction as out
• “value” is the value of a pin. It reads a “0” or “1”. Any on-zero value written will be interpreted as “1”. When reading the value ”high” evaluates to ”1” and “low” evaluates to “0” unless overridden by “active_low”
• “echo 1 > /sys/class/gpio/gpio18/value” sets the value of GPIO 18 to “1” and closes the circuit
• “cat /sys/class/gpio/gpio18/value” would return “1” after the statement above
![Page 14: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/14.jpg)
GPIO SIGNALS CONTINUED
• “edge” is used to tell the GPIO when to write to ”value” when “direction” is “in”. Valid values are “none”, “rising”, ”falling”, and “both”.
• “echo both > sys/class/gpio/gpio18/edge” will trigger an interrupt when voltage increases or decreases
• “active_low” is used to invert the effect of “edge” of “value”. Valid values are “1`” and “0”. “1” inverts and “0” sets standard.• “echo 1> sys/class/gpio/gpio18/active_low” will
invert the values of high and low
![Page 15: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/15.jpg)
PYTHON ACCESS TO GPIOCAT SKINNING 101
![Page 16: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/16.jpg)
USE FILE SYSTEM ACCESS
• ”open”
• “read”
• “write”
![Page 17: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/17.jpg)
TWISTED
• Event loop
• Single thread
• Asynchronous I/O
• HTTP server
• Websocket server
• File system I/O
• Real IoT
![Page 18: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/18.jpg)
DEMO TIME
![Page 19: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/19.jpg)
PLATFORM COMPARISONHOW TO PICK THROUGH THE MYRIAD OF OPTIONS
![Page 20: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/20.jpg)
RASPBERRY PI
Pros• Moderately Inexpensive (~35 USD)
• Flexible platform
• Lots of guides and tutorials
• GUI interface for beginners
• Aptitude package manager
• Great starter platform
Cons• Requires special cable to do away with keyboard
and monitor
• Under powered
• No built in Analog to Digital Converter (ADC)
• A bit on the large side
• ARM processor
![Page 21: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/21.jpg)
INTEL EDISON
Pros• X86 based Atom processor
• Ample power, RAM, and storage
• Multiple form factors
• Arduino developer board can use standard Arduino backplanes
• Easy to setup Wi-Fi
• Arduino board has Analog to Digital Converter and Python library
Cons• Can be a bit pricy (~110 USD)
• Not as many guides and tutorials
• Documentation is a bit confusing at times
• Evolving platform
• Sysfs GPIO is flakey
![Page 22: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/22.jpg)
DRONESMITH LUCI
Pros• Easy to build unmanned vehicles
• No real electrical understanding needed
• Just uses some simple scripting
• Based on Intel Edison
Cons• Expensive
• Still in early development phase
• No real direct development – just scripting routes.
![Page 23: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/23.jpg)
CHIP
Pros• Super inexpensive (~10 USD)
• Wi-Fi
• Bluetooth
Cons• Low power
• Pre-order only
![Page 24: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/24.jpg)
BEAGLEBONE BLACK
Pros• Inexpensive (~50 USD)
• Can be a full computer
• Has add-on ecosystem
• Lots of connectivity
• On-board Analog to Digital Converter (ADC)
Cons• Low power
• ARM chipset
![Page 25: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/25.jpg)
FURTHER READING• Raspberry Pi: https://www.raspberrypi.org/
• Linux Kernel GPIO Sysfs: https://www.kernel.org/doc/Documentation/gpio/sysfs.txt
• Examples for GPIO in Bash and PHP: https://github.com/aenglander/iot-examples
• Twisted: http://twistedmatrix.com/
• Intel Edison: http://www.intel.com/content/www/us/en/do-it-yourself/edison.html
• CHIP: https://getchip.com/pages/chip
• Luci: http://www.dronesmith.io/luci/
![Page 26: Got Python I/O: IoT Develoment in Python via GPIO](https://reader033.vdocuments.net/reader033/viewer/2022042517/5883fae11a28ab884b8b4ae9/html5/thumbnails/26.jpg)
CONTACT INFO
• @adam_englander on Twitter
• aenglander on Freenode
• aenglander on GitHub
• adamenglander on Linkedn