Bummer! This is just a preview. You need to be signed in with a Pro account to view the entire video.
Start a free Basic trial
to watch this video
Microcontrollers and the Internet of Things Survey
17:01 with Chris ContinanzaChris Continanza demystifies some of the decision making when choosing a piece of hardware to connect a device to the internet.
-
0:00
[MUSIC]
-
0:04
Hi I'm Chris Continanza, I'm here to talk to you
-
0:07
about the Internet of Things and keep you from lunch.
-
0:10
>> Woo.
-
0:12
>> So that's my honor.
-
0:14
So what I wanted to show you was a thing connected to the Internet.
-
0:18
So everyone on this side who cannot see, this is an LED matrix display board.
-
0:26
This is basically six pieces and you can buy each of these
-
0:30
as a three by two matrix and they are daisy chained together.
-
0:34
But the important part of this thing is that
-
0:39
it's connected to the Web and yeah, so things.
-
0:44
So things essentially when we talk about
-
0:45
Internet of Things we really mean computers.
-
0:48
And the change has been that the computers have obviously
-
0:51
shrunk in size and increased in processing power thanks to Moore's Law.
-
0:55
Because of that we're able to get logic in places we couldn't before.
-
0:59
And now we're, you know, able to I kind of
-
1:03
developed this whole new generation
-
1:04
of devices and basically real-world interactions.
-
1:08
That's kind of what I care about.
-
1:10
And so you have the real world interaction side.
-
1:14
And then you might say hey, you know, I have this device,
-
1:17
I've coded it up to do some cool stuff, but I'd really like
-
1:19
it to be infinitely dynamic or configurable
-
1:23
from where I am sitting at home.
-
1:25
And that's where the Internet is gonna kind of come
-
1:27
in or make something that's automatic or based off of data.
-
1:31
These slides are really here to kind of guide those stuff.
-
1:33
So I, actually I could use maybe this, this one to show the things.
-
1:40
So, as, as the things come up.
-
1:44
Basically there is two kinds of
-
1:46
computation platforms you are gonna deal with.
-
1:49
there's, there's the tiny, tiny microprocessors and
-
1:55
there's something that's big enough to run Linux.
-
1:57
And so, in the world of tiny, we have Arduino.
-
2:03
We have our Spark, we have an Electric Imp this is an Embed from Arm,
-
2:09
which is a small M3 processor.
-
2:12
And then for Linux, here's your Raspberry Pi.
-
2:15
And, you know there's kind of this notion that eventually Linux will
-
2:19
make it small enough, but I actually think there's always gonna be a
-
2:21
leading edge of devices that are always gonna be a little bit
-
2:24
smaller, a little bit more efficient than something that can fully run Linux.
-
2:29
That's gonna matter to us in about
-
2:30
three minutes when we start talking about protocols.
-
2:32
Because one of the big advantages of having Linux
-
2:34
on board is you get to take advantage of the whole TCP/IP stack that comes with
-
2:38
Linux that we've all been programming on for, you know, the last x amount of years.
-
2:44
Actually raises a good point for a raise of hands.
-
2:46
Who does develop server side web software here?
-
2:48
Here, there, all right we're all in the club.
-
2:51
So, you know I'm from the same boat.
-
2:54
I got started with Arduino a couple of years ago.
-
2:57
Just kind of having fun on the side.
-
3:00
And actually my odyssey with Arduino and the Internet
-
3:03
began with a project called the Heroku Outage Lights.
-
3:08
I was in the office one day and somebody came up
-
3:10
to me and was like, hey Chris, I don't care what
-
3:13
kind of Arduino crazy thing you need to do, but when
-
3:16
our status site is red, I want the office to be red.
-
3:21
And so, this is actually as simple as kind of an Internet
-
3:25
of things application can get, because all this has to do is trip a relay.
-
3:30
So this is no more confusing on the hardware side than blinking an LED.
-
3:36
What it does on the software side is it pegs status.heroku.com
-
3:40
has a JSON Endpoint, so it just pings that on a loop.
-
3:42
And then whenever it says, oh the status is red, turn the relay on.
-
3:48
Getting this connected to the Internet was easy, because I was able to use Ethernet.
-
3:55
So this is the Ethernet shield Arduino,
-
3:58
and that was my first Internet-connected Arduino project.
-
4:02
It actually went really easy because I had the wire
-
4:08
I could just plug in, and be on with my life.
-
4:12
As soon as we go wireless things get a little bit more complicated.
-
4:15
All right, so things.
-
4:18
So the reason I have these things listed, Ardurino, Raspberry Pi, and
-
4:22
Ardurino Yun is that Arduino is a perfect example of a microprocessor.
-
4:27
This handles your interactions
-
4:28
with the real world, but doesn't, say actually connect
-
4:34
to the Internet itself, which is why you need an Ethernet shield, or this Adafruit.
-
4:39
This is the CC3000 chip, which we'll actually see packaged
-
4:44
up again in a smart device, also the same chip.
-
4:48
And you can buy one in this format, which is the same format as the XB.
-
4:52
XB as the WiFly. The Raspberry Pi itself actually has
-
5:01
Linux on it, so you don't need or has an Ethernet, rather.
-
5:07
It has its own TCP/IP stack so you don't have to rethink a lot of the world
-
5:13
but to make this WiFi enabled we still have to add our own WiFi chip.
-
5:18
And then something like the Arduino Yun is I don't have one yet, because
-
5:22
I haven't been able to get my hands on it, but that's actually kind
-
5:25
of these hybrid solutions where you have a Linux system, essentially handling all the
-
5:30
Internet side of things, and then an
-
5:32
Arduino handling all of your inputs and outputs.
-
5:35
These things start to get complicated when you say, I have GPIO
-
5:39
here, but I really like being able to do shields with an Arduino.
-
5:42
So you
-
5:43
can take a Raspberry Pi and then connect it to an Arduino and control it with
-
5:47
something like Cylon or Johnny 5 but, that tends to involve too many parts for me.
-
5:55
So the different ways to connect to the Internet with
-
5:58
a thing Ethernet, fun, easy, simple, but requires a wire.
-
6:04
And part of my personal challenge is Ethernet
-
6:08
ports are getting rarer. So Heroku moved to a new office.
-
6:12
It turned out that there were no Ethernet ports.
-
6:16
So I had all these fun Ethernet based applications
-
6:20
and I had to convert them all to WiFi.
-
6:23
And that itself kind of informed some of this experience.
-
6:26
So I kind of want to get to that story.
-
6:29
When you have different ways of connect to the Internet now.
-
6:32
So there's the Ethernet shield itself
-
6:35
XP is this format.
-
6:37
It's not this chip, but it looks very similar.
-
6:40
XPs allows you to do a mesh network.
-
6:42
So, XPs don't connect you to directly to the Internet itself.
-
6:46
But an XP will usually be a first hop to connect
-
6:48
you to perhaps a Raspberry Pi, that's connected to the Internet.
-
6:53
That CC3000 chip is just a very popular chip that is directly doing WiFi.
-
6:59
I found it hard to work with,
-
7:00
so I'm very excited to try out the Spark chip.
-
7:04
There's a library for using that in Arduino that isn't completely polished.
-
7:09
This project actually uses an Electric Imp.
-
7:11
So if I don't break it well what I have here is an Electric Imp Breakout Board.
-
7:18
And that is handling the WiFi and I'll talk to
-
7:20
how the WiFi communicates with the Arduino in a second.
-
7:23
>> And then the Yun, like I said is
-
7:25
actually an Arduino with a small lineno with a small distribution on it.
-
7:30
And basically you have Linux handling the
-
7:32
Internet and Arduino handling inputs and outputs.
-
7:36
So, this specific example, which I feel bad, because it's blocked and I don't have
-
7:43
enough surge protector, but what this is, is
-
7:47
the rea-, reason I chose Arduino is that
-
7:50
Arduino comes with a library that easily
-
7:53
connects to these LED matrix display boards.
-
7:57
So that was kind of a necessary, and it
-
7:59
was very simple when it was hooked up with Ethernet.
-
8:02
So then I tried to use the CC3000 chip, but
-
8:06
I actually wound up with a pin conflict, in that
-
8:09
this needed one of the interrupt pins on the Arduino,
-
8:11
pins two or three, and my LED matrix board also
-
8:16
wanted both pins two and three.
-
8:20
so, it kind of looked cool because you would just
-
8:22
have this random splat of LEDs turned on and off.
-
8:28
But there is no app name that is, you know, like, something dash splat.
-
8:34
So I met one of the guys from Zivley, and he said,
-
8:37
hey, can you use an Electric Imp to connect to the Internet.
-
8:40
So this is an Electric Imp. And what the Electric Imp is,
-
8:45
is it's an SD card format, but it has WiFi
-
8:49
in it. So to connect an Electric Imp to the
-
8:52
Internet you actually do this interesting thing where, you flash,
-
8:59
and not in the streaking sense, but in the more of the epilepsy sense.
-
9:06
So this, if you have problems with blinking, turn away now.
-
9:10
So this is actually how you communicate
-
9:12
the WiFi credentials onto the Electric Imp.
-
9:16
So that's kind of a pretty cool way of not having
-
9:20
to recompile the same program just because you changed your WiFi credentials.
-
9:23
Which I really liked about it cuz it lets me kind of take
-
9:25
this with me, go into another room, set it up in my Internet device.
-
9:33
So, part of the Internet of Things and connecting stuff
-
9:37
to the Internet means you're gonna have to talk protocols.
-
9:40
TCP/IP matters again.
-
9:43
So we don't have the advantage of having Linux running
-
9:45
for us and just opening up the connection to the web.
-
9:49
For some of these devices shipping your own TCP/IP stack,
-
9:52
specifically even with the embed actually becomes part of the equation.
-
9:57
And that's why I think
-
9:58
that, that does matter and what platform you choose will make a big difference.
-
10:03
Things like Spark and Imp are a lot more Internet ready.
-
10:08
Things like the CC3000 shield for Arduino and the embed
-
10:13
specifically are a little bit more lower level, and they ship with a bunch of
-
10:18
C++ code that you actually have to compile your own TCP/IP stack.
-
10:24
Which, you know, is something that we may or may not be familiar with or having fun.
-
10:28
There's always UDP around, don't wanna leave anybody out.
-
10:33
And then for actually application-level protocols, once we have a WiFi connection
-
10:38
or an Ethernet connection, once we're talking TCP/IP, we can actually finally
-
10:43
get back to the land we're familiar with HTTP, Websockets and then
-
10:47
MQTT up, it's up here because it actually fills, fills a need.
-
10:54
It's very easy to talk HTTP from these devices.
-
10:57
I actually wrote my own
-
10:58
rest client for Arduino, which worked great on the Ethernet shield.
-
11:03
Not so much for the WiFi shield cuz
-
11:06
it's a totally different hardware stack or software stack.
-
11:09
It's a different interface and my C++ chops are not so good with polymorphism.
-
11:15
I was trying to pass a void pointer
-
11:16
around, and apparently you're not allowed to do that.
-
11:19
So yeah, so with HTTP it's, it's still
-
11:24
really easy.
-
11:25
With WebSockets it's, way less fun of a protocol.
-
11:28
I've gotten projects going with WebSockets on
-
11:32
the Raspberry Pi because you can actually
-
11:33
compile you can run Node and take
-
11:35
advantage of stuff, stuff somebody else wrote.
-
11:39
And that's kind of where MQTT comes in, because MQTT is a
-
11:42
simpler protocol than Websockets, but fits
-
11:44
that same niche of real-time communication.
-
11:50
I think that's a different slide.
-
11:51
So, sorry, what I wanted to talk about was how this works, because it's kind
-
11:56
of an example of both the trials
-
11:59
and tribulations of building an Internet connected thing.
-
12:03
I really wanted it to do something.
-
12:04
So, wanting it to work was a big part of it.
-
12:09
The way this works now is there's an Arduino,
-
12:12
and the Arduino is connected via the Electric Imp
-
12:15
breakout board.
-
12:17
Now if you're gonna want to get something online
-
12:18
you are gonna have to have something like this layer.
-
12:22
You can directly, you know, from the Raspberry Pi talk to the GPIO pins.
-
12:28
So you don't have to have an Arduino per se, but if you do want to connect in
-
12:33
Arduino you're gonna have to have to use either
-
12:35
the Imp shield, the WiFi shield, or the Ethernet shield.
-
12:40
and, the reason I went with the Imp is because it allowed me to do a software
-
12:44
serial connection. So, I have the Imp is actually talking,
-
12:50
and I'll show this code, is talking via software serial to the Arduino itself.
-
12:58
So the Arduino sits there and it waits on
-
13:01
a serial connection from, so its deployer's Imp Serial.
-
13:07
And without getting too much into it
-
13:12
right here we set up a software serial that
-
13:18
I call Imp serial on pins eight and nine.
-
13:21
So the long story short there is I was
-
13:22
able to get around the requirement that the matrix display
-
13:26
board needed two pins by using the Imp board and
-
13:29
letting that speak software serial over pins eight and nine.
-
13:33
And the lesson there isn't that everyone should run out and
-
13:35
use software serial, it's that there's gonna be an annoying hiccup
-
13:38
somewhere in your project, and getting around it may not be straightforward.
-
13:43
So what I learned there was there's this protocol called UART.
-
13:46
And UART is actually built into the Imp. So the Imp is running in the Cloud
-
13:54
right here, and down here are these strings.
-
13:59
So has anyone figured out what, what this is actually displaying yet?
-
14:05
>> [INAUDIBLE] >> Close.
-
14:06
>> [LAUGH] Heroku Deploys. Heroku Deploys, exactly.
-
14:09
So people that are deploying to Heroku
-
14:11
right now every deploy is scrolling across this.
-
14:15
And the reason I built that is because
-
14:17
the outage lights was kind of a downer project.
-
14:21
It's only working when something bad's happening, and it has to be
-
14:25
working all the time so I put in effort to monitor it.
-
14:28
And to make sure that, you know, it was still checking
-
14:31
the requests and did all this
-
14:33
productionization for something that essentially sits in
-
14:36
the corner gathers dust and is good if it stays off all day.
-
14:40
So the idea behind this was how to I take
-
14:43
something that's happening un-visualized and visualize it in the real word.
-
14:48
And some of the initial ideas that came around were, hey, why don't we
-
14:51
blink an LED every time someone deploys, which is cool, but I figured would
-
14:56
have been very hard. I mean, this is blinking, right?
-
15:00
Like it's not really that impressive and there's kind of that a lot of
-
15:03
explanation you have to do like what is this thing blinking on your desk, why?
-
15:08
You know no one is really going to associate that with app names.
-
15:11
So I figured well, if I can figure out the name of the app while it's
-
15:14
being deployed it would be really cool to
-
15:16
get a lot of LED's together and display that.
-
15:19
And so that's kind of what
-
15:21
informed this project.
-
15:24
And then some other things that I've worked on with Heroku has
-
15:27
been like a demo of Websockets talking to a back-end Heroku app.
-
15:32
but, you know, that was that's actually where we found out that Socket IO
-
15:38
doesn't really like to open lots and lots of connections and other, other issues.
-
15:45
But,
-
15:46
anyways the idea behind this is that there's a backing Heroku app, and so
-
15:50
there's also a whole server side component
-
15:52
where this is subscribed to an event stream.
-
15:55
And originally events were coming in the events stream
-
15:58
and this would pull itself over a GET request.
-
16:02
But the Electric Imp actually runs a server side thing, so
-
16:07
I had to change that to every three deploys it posts to
-
16:11
an endpoint in Imp land.
-
16:13
And then that like unique URL then sends the data down to the Imp.
-
16:19
Which writes it over UART software serial to the Arduino, which can then read
-
16:24
the characters and say, ha, I found a comma I will now print the name.
-
16:30
So, part of the Internet Side of Things is you
-
16:32
might have questions about should I use Ruby or JavaScript?
-
16:36
Should I use
-
16:36
Postgres or Redis? Should I post on Amazon or Heroku?
-
16:40
How am I gonna operate this thing? This is where I spend my whole day.
-
16:45
So, I'm happy to help people with questions like that, and how they want
-
16:48
to set up the server side, and the Internet connection for their app.
-
16:52
And, that's it, thank you. [SOUND]
You need to sign up for Treehouse in order to download course files.
Sign up