3. What You Will Learn Today
1. Internet of Things and Data Stream
2. How to send & receive data with PubNub using Python
3. How to wire a LED & resistor to Pi using breadboard
4. How to program Pi to blink the LED
5. Making it IoT : Remote-controlled LED from web interface
4. Era of Internet of Things
Source: PLATFORM, data based on Cisco IBSG
Estimate 50B by 2020
non-human/human = 6.58
2003:
non-human/human = 0.08
2015:
non-human/human = 3.47
2008:
non-human/human >= 1
5. Withings: Smart Body Analyzer
GE Link
Cinder
Sensing Cooker
Nest: Learning
Thermostat
Whistle: Connected pet collar
Amazon
Dash Button
Smart Devices
8. Internet of Things with
Data Stream
Send & Receive Data to/from Data
Center via Internet
9. PubNub Data Stream
Two-way communication to/from every device in the world.
https://pubnub.com
Realtime Reliable Secure
PubNub is globally distributed realtime data stream
network (DNS)
15. SSH into your Rasp Pi
1. Get your Raspberry Pi’s IP address
pi@raspberrypi ~$ hostname -I
16. 2. SSH to Pi from your laptop
(Terminal on Mac/Linux, PuTTY on Windows):
me@MyMac ~$ ssh pi@10.96.70.1
SSH into your Rasp Pi
Use your Pi’s IP!
Your Pi’s username
If SSH-ing fails, try:
$ sudo raspi-config
on your Pi
18. Get Started w/ Python
Update your system first
~$ sudo apt-get update
~$ sudo apt-get upgrade
Install python and pip
~$ sudo apt-get install python-dev
~$ sudo apt-get install python-pip
19. Wut, you want Node.js?
~$ wget
http://node-arm.herokuapp.com/node_latest_
armhf.deb
...but we’re using python today!
Don’t worry, I’m a JS dev too :-)
28. 1. Raspberry Pi 2 (w/ a WiFi Adapter for later exercise)
2. 1 Breadboard
3. 2 Male/Female jumper wires, 2 colors
4. 1 Resistor (200Ω)
5. 1 LED (1.9 - 3.2V)
What you need
31. OMG Physics!
R =
V - Vs f
I
source voltage (V) forward voltage (V)
(LED voltage drop)
current thru
the LED (A)
resistance (Ω)
32. OMG Physics!
R =
3.3v - 1.9v
0.02 A
source voltage (V)
forward voltage (V)
(Red LED voltage drop)
current thru
the LED (A)
resistance (Ω)
= 70 Ω
33. 4-band Resistor Color Code
47 x 100 =
4.7 k Ohms
4 7 102 +/- 5%
multiplier
tolerance
Learn more at: https://learn.adafruit.com/multimeters/resistance
34. 5-band Resistor Color Code
200 x 1 =
200 Ohms
2 0 100 +/- 1%
multiplier
tolerance
Learn more at: https://learn.adafruit.com/multimeters/resistance
0
35. Breadboard
400-pinMini
We are using this kind today!
You may find this
type of breadboard
when googling
circuits. They have
power rails that
goes vertical!
not connected !
An electronics breadboard is a fundamental tool to build circuits. It is solderless, and great tool for
prototyping.
conductive metal
strips goes
horizontally
Connected!
40. Programming LED
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
LED = 4
GPIO.setup(LED,GPIO.OUT)
for i in range(6):
GPIO.output(LED,True)
time.sleep(0.5)
GPIO.output(LED,False)
time.sleep(0.5)
import RPi.GPIO libs
set pin type. use BCM, not pin number
GPIO 4 pin (Pin 7)
set LED pin as output
toggle light pin signal to low/high to
make it blink.
7 times.
43. Publishing data from a web client
var pubnub = PUBNUB.init({
subscribe_key: 'demo',
publish_key: 'demo'
});
button.addEventListener('click',
function(){
pubnub.publish(
{channel: 'disco',
message: {led: 1}}
);
});
Making it IoT:
Remote-Controlled LED
When the button is
clicked on browser, it
publishes data, {‘led’: 1}
44. Subscribing data to Raspberry Pi
pubnub = Pubnub(publish_key='demo', subscribe_key='demo')
channel = 'disco'
def _callback(m, channel):
if m['led'] == 1:
for i in range(6):
GPIO.output(LED_PIN,True)
time.sleep(0.5)
GPIO.output(LED_PIN,False)
time.sleep(0.5)
pubnub.subscribe(channels=channel, callback=_callback, error=_error)
Making it IoT:
Remote-Controlled LED
button.addEventListener
('click', publish);
As soon as a message is
published from a browser,
the message is subscribed
to Pi
47. Data Visualization with
Temperature Sensor
It uses a capacitive humidity sensor and a thermistor to
measure the surrounding air, and spits out a digital signal on
the data pin.
https://github.com/pubnub/workshop
-raspberrypi/tree/master/projects-pyt
hon/dht22
http://pubnub.github.io/workshop
-raspberrypi/web/temperature.ht
ml
51. Creative Commons Attributions
◼ LED circuit: Wikimedia
◼ GPIO Pins: RaspberryPi-Spy.co.uk
Also, great public domain images from Pixabay, and an
open-source software, Fritzing for circuit diagrams!