Okay, welcome to another episode of the On.NET show.
Today we're gonna be talking with my colleague Peter and
we're gonna be talking about Raspberry Pi, IoT, ARM 32 and
all that good stuff.
So what are we talking about?
What is this ARM 32, IoT, Raspberry Pi?
What are those things?
>> All right, so yeah, ARM 32, Raspberry Pi, IoT are things
that we talk about generally in this IoT space.
Which are a bunch of devices,
Internet of Things, things that you can do with a bunch of these
really small devices like Raspberry Pi's,
that can do amazing things for $35.
And really unlocks a lot of possibilities.
People are doing smart homes and general compute in the cloud
using large arrays of these things and
it's really a cool space.
So it's something we've been exploring for
a little while now.
>> Okay, so this device that we see here,
we might need to kind of lift it up a tiny bit.
Yeah okay, there we go.
So this is a Raspberry Pi, right?
>> Yeah, this is a Raspberry Pi.
>> And I sometimes hear this different terms like
Raspberry Pi 2, Raspberry Pi 3, I guess there was a 1, and
then there's also a Zero.
>> Yes.
>> Which one is this? >> So this Raspberry Pi 3.
Raspberry Pi 3 and Raspberry Pi 2 are very similar, Raspberry Pi
3 is just an updated version that has more memory and
a greater CPU power.
But a lot of the pins and
everything on there is the same between 2 and 3.
>> Okay. >> Then you mentioned
the Pi Zero, which is actually a different processor
that has a reduced set of instructions.
I think it's ARMv6 instruction set, as opposed to ARMv7.
And ARMv7 is what .NET depends on, so as of right now,
in some of the demos we show you,
we're literally talking about ARMv7 instruction sets.
So Raspberry Pi 2, Raspberry Pi 3 is what we're looking at.
>> Okay, so when I go on YouTube sometimes I see people and
I search on Raspberry Pi, I sometimes see people using
the Raspberry Pi, I guess what I would call, as a computer.
And then I sometimes see them using it as an IoT device
that takes advantage of the sensors and that kind of thing.
So can you talk about,
is it the same device they use in both cases?
Can you talk to that?
>> Yeah, people use Raspberry Pi's in both cases.
In my office I have a Raspberry Pi hooked up doing 4k monitor
as a full desktop, it's got LibreOffice and
all kinds of things running on it.
So it's a full-fledged client.
It's slow, it's not the processor you'd normally have on
a desktop workstation.
>> It's not an Intel i7 or i9.
[LAUGH] >> No, it's not.
But it is functional and it does what it needs to do for
small things.
>> Yeah, I actually know my neighbor has one hooked up as
with I think it's Kudu or Kudo media server?
>> Yeah, yeah people are using it all over the place for media
center type things, recording streams off the Internet and
putting them one their NAS.
>> Right, okay, so how about you walk us through what's
actually on this board, cuz it's super, super cool.
What are we seeing here? >> Yeah, so
I'll just stick at a high level, but
basically this board has four USB ports, so
you can connect all kinds of devices to it.
Ethernet, it has this array of GPIO ports, which we'll talk
a little bit more about in the demo we're gonna show.
You can hook it up to a camera, you can hook it up to a display.
It has HDMI port, it has the mini HDMI for power and
then it has the ability to plug in on like wall wart to be
able to power it as well.
It's got the processor and
it's got the SD card kind of on the back here.
>> And that's where our OS is.
>> That's where the OS is,
that's where everything is running off of.
I think it's got a 16 gig card in there right now.
But most of the distros and
everything you need to run on it can happen in about eight gigs.
>> Okay, and tell us which operating systems you can
install on that.
>> So I've done various things.
Windows IoT obviously runs on this Raspberry Pi.
Raspberry has a distro called Raspbian that runs on here.
Ubuntu MATE is something that you can run on here.
Those are the three that I've done.
>> Okay, or isn't it MATE?
>> MATE.
>> Yeah.
>> So I've run those on this Pi.
And it's really nice because I can leave the whole hardware
configuration the same.
And I can just swap out the SD card and
it all works kind of the same.
>> Yeah, the one I normally run is Raspbian, because with
the other Linux work that you and I actually do together.
>> Yep. >> For .NET Core, there we use,
mostly focus on Debian.
So Raspbian, which is basically the Raspberry Pi version of
Debian, as you know.
>> Right, right.
>> It's why it's called that.
That's the one I usually use, and
it sticks with the same version.
So there's a Raspbian version for Jessie,
which is what we kind of used to focus on.
And there's another one called Stretch,
which is what we kind of use now, so that's what I installed.
>> And today I have Raspbian on here, so
that's what we'll be looking at.
>> Okay, and are you using Stretch or Jessie?
>> I believe it's Stretch.
>> Okay. >> But
I don't remember [CROSSTALK] >> So
let's look at this fancy here, cuz this looks crazy.
>> Yeah, so let me walk through the rest of the hardware,
is that what you're- >> Yeah.
>> So we'll demo something very simple, but we have samples, and
I can show you where they are, of controlling a lot of
different sensors that are available in the ecosystem.
And very common ones are things like light sensors,
potentiometers, this is a barometric pressure sensor with
temperature and all kinds of goodies on it.
LEDs, obviously, there's a digital-analog converter.
I think that's what I've got on here today.
But basically, all of these things interact with
the Raspberry Pi through GPIO, and
usually use common protocols like SPI or I2C.
So it's really about just hooking them up,
getting the right libraries to connect to them, and
then interacting with them.
>> Right, so I would imagine to use one of those, you probably
need super low-level C++ code, or like crazy PInvokes.
>> [LAUGH] You do and you don't.
It turns out there's a great ecosystem around this stuff.
And there's C++ libraries and
libraries in a bunch of languages that are available to
interact with all of these things.
So in a lot of these demos that I'm giving,
there's a very popular library called WiringPi.
That's a C++ library that has language bindings from
a bunch of different languages.
So I'm using a .NET library that has language bindings to
WiringPi.
So all the protocols and the all the GPIO interhop happens in
that library, and then we just write nice subtractions for
the hardware on top of that library.
>> Okay, so what are you gonna show us first?
This device actually doing something or show us the code.
>> Let's look at the project real quick.
>> Okay. >> Let's look at the code that
controls the Raspberry Pi.
So we might wanna just make that a tinny bit bigger.
>> Okay.
So I have a set of projects here, but a very simple project,
a very simple project here is .NET Core 2.0 application.
>> So, if you do, okay.
>> And this is just the boilerplate code that you would
use to blink an LED.
You can see you kinda initiate the GPIO driver,
chose which pin you're gonna use to control the LED.
And then just do a simple loop to toggle the LED from true to
false, where the important thing here is you're writing the LED
state, the high or low on the pin.
>> Okay, so we never actually defined what GPIO means,
cuz it's an acronym, right?
>> Yeah, GPIO is general purpose I/O.
So it's just the general way that you interact with
the external devices from a Raspberry Pi.
>> Right, input/output.
>> Yes, input/output.
>> So whenever I see these while loops here,
cuz I've seen this type of code before, I have always have this
idea that the device is gonna burn up or something like that.
>> [LAUGH] >> That doesn't happen.
>> No, it doesn't.
It's actually using a thread and lubing through with a sleep.
So no, it's not an infinite, I mean it's an infinite loop, but
it's not running out of control.
>> Yeah, exactly.
>> So yeah, so this is the project.
And as I said it's a .NET Core 2.0 application.
And where did that terminal go?
>> Here?
Yeah, there it is.
>> Okay, so you can see here, this is that project that I was
just in, and in order to build it you do your normal
interactions with it, so .netbuild, .netrun,
except .netrunning it Isn't really useful,
cuz you're on a Mac here, or you could be on a Windows.
And running this code, it doesn't have GPIO,
it doesn't have all the drivers,
it doesn't have everything ready, so
dotnet run isn't that interesting.
What's really important is that you kinda create
a self-contained application, or an application that can
run on the framework that's on the device.
So what we do is effectively do a dotnet publish,
-r to say to a specific runtime, and then we do linux arm,
because that's the target architecture and
the OS of the device.
So once we do that, it'll create in this folder here,
in the /linux-arm/publish folder, an application.
Now, I won't do it here today,
but all we do is copy that folder over the Raspberry Pi.
And it just, you just start to run it,
so the next thing we can do is pop over to the Pi.
So let's see, do we have that up here, there we go,
perfect [CROSSTALK].
So here, let me get focus, right.
>> Not quite there, there we go.
>> Okay, so here, there's our application, it was copied into
this blink LED folder, and I can do a, sudo blink led,
now, you have to run as sudo because access to the GPIO is
an admin operation, so running in sudo is critical here.
>> Okay, so now we started it, now I assume it's just gonna sit
there cuz I didn't see the console.
>> [CROSSTALK] running our code,
now we can jump over here to the [CROSSTALK], there we go.
So the LED's blinking, and that's what we've got running.
>> Okay, yeah, we can see that on the screen.
>> Yeah, I think I can see it over here, so-
>> Okay, it can help.
>> There we go. >> Yeah,
so that will just keep on blinking forever.
Now, if we had another, let's just kind of conceptually
make this a little more interesting.
If we'd had a temperature sensor, maybe we could
cause the blinking to start above 70 degrees Celsius.
>> Right, so if we go back to the Mac here-
>> Some temperature.
>> I've got another sample,
which I don't have all the wires hooked up, so I can't demo it.
But this is effectively exercising all of those
different sensors that are on the board today.
So, you can see how it sets up
all these different serial interfaces and protocols.
It does the same thing,
except the thing that's controlling the LED in this case
is actually down here, it's the state of the motion sensor.
So when the motion sensor has been activated,
the LED turns on.
And when it hasn't been active for a period of time,
I forgot what it was set to, it turns back off.
Right, so you can also see in here,
we're reading stuff for the temperature, we're outputting
the pressure and the temperature that's currently there, reading
the potentiometers to say where we are on the analog values.
So all the sensors right here on the board are being controlled
in, this is, what, 60, 70 lines of code?
So we're getting a lot of data flowing in,
all this data could be uploaded to the cloud, processed there,
doing different things.
>> Now, I see some console.write lines there,
I assume, from a pure runtime scenario,
those console.write lines wouldn't be super interesting.
>> Yeah, those aren't interesting,
but in a demo, you'd be able to see these pressure gauges and
everything outputting.
So I could cover up the light sensor, and you'd see the stream
of data change in the value of light that's coming.
It's just a way for them to make it easy to see, and
not have to go through a whole end to end.
>> Right, or you could be pushing that data to the cloud.
>> Right, but you can replace those console.write lines with
push data to wherever you wanna push it.
>> Makes sense, do you see people adopting
this kind of model, at all?
>> Yeah, actually, I first put up instructions on how to do
this Raspberry Pi stuff probably about six months ago now.
And immediately I started getting people telling me
that it worked or it didn't work, and
what they were trying to do with it.
And we've had people take what I've done here, and
go to conferences and demo them, and create really cool devices.
And connecting them to Azure,
connecting them to different services, and
creating whole end to ends.
It's been really fun watching people come out of the woodwork
and wanting to play with this.
I know Scott Hanselman, right now,
is playing with creating a whole cluster of Raspberry Pis,
running code like this, using the libraries that I sent him.
>> So can you tell me two things,
one is, what is the thing that you found most challenging?
And what was the thing that you found most surprisingly easy?
>> Okay, well, so assuming you've already gotten over
the hurdle of working with hardware,
working with electronics.
So knowing how to read voltages, knowing how to kind
of debug the signals that are coming to these things.
Once you've gotten over that hurdle,
which is probably the hardest hurdle for
someone that's just lived in software for a long time.
Once you get past that, the hurdles, actually,
were more of the trying to integrate it
with different protocols and different control boards.
So for example, reading the specification for
the barometric pressure sensor to understand when I get a value
of high, it means this.
And kind of mapping that to something that makes sense, so
it's still the hardware to software translation there.
Now, the nice thing is, there's a lot of libraries out there for
a lot of popular boards,
that have already done that abstraction for you.
So for example, I have a whole base set of libraries here that
I'm using, that came from the mono community,
that really helped with getting the whole thing bootstrapped.
So it's really when you stray from what a lot of people have
done, and you start getting into your own custom boards or
your own custom configurations,
that's probably the hardest part.
>> Okay, makes sense, one of the questions that I was talking to
you about earlier was,
though we actually don't have an answer for yet.
>> [LAUGH] >> Is Scott Hanselman is
creating this kind of array of Raspberry Pis.
And I've seen pictures of people having these towers with
the plastic and everything.
To use all of them, you need to find out what their IP address
is, and we were speculating on how he might be doing that.
Yeah, and we don't really know the answer, but yeah,
it is one of the other challenges you do hit,
is you wire this whole thing up.
And in order to connect to it through any type of development
environment, to just do Putty or SCP or any of the different
things to connect to it, you need to know the IP address.
So you've gotta find a way to figure out what IP address
it got.
So usually, you end up hooking up a monitor, hooking up
a keyboard, running some commands to get the IP address.
And using that and hoping it never changes, or going and
possibly setting a static IP on it.
>> Right, because I think that's what one of
the interesting things is.
These are still fundamentally real computers,
running a modern operating system.
And so they mostly rely on this DHCP for getting an IP address.
>> That's right, we're just talking, you know what would be
super cool, if there was a little LED on here that would
tell you the current IP address of the boards.
You didn't have to go wandering around trying to find it.
I would never have to connect a bunch of hardware to these
things, I literally would just plug them in, and
let them connect to Wi-Fi, and get an IP address.
Except that I have to find the IP address, and getting started,
that's one of the more painful parts of it.
>> Cool, well, I think we've learned a bunch today.
I really like that device, it's the bread board, right,
that's what that thing is called?
>> Yeah, the bread board.
>> Yeah, I don't think you ever said that word.
>> Yep, that's just used for prototyping, proto board.
>> Yeah, exactly, so if people want to learn more about this
and kind of do this at home, where would you suggest they go?
>> So we have a getting started, let's see,
it's at .NET Core, think it's under samples.
Nope.
>> Go to Core, cuz you're missing the master thing,
links don't work that way.
>> And then we have Raspberry Pi instructions.
>> Cool. >> So there's this whole thing
here, and then like I said,
there's a bunch of libraries up on NuGet.
If you just search for Pi, you're probably likely to find
the ones that might work for your scenarios.
And go ahead and link them or reference them in, and
start playing around.
>> Right, I guess I should also point out,
there's this announcement that we created, that tells you about
ARM32 builds being available generally.
And this link from samples is there,
so that's at .net/announcements, and
this one happens to be issue 29 on GitHub.
So I recommend people look at that,
we'll include the link at the end of the video.
>> Okay, well, this is great, thanks for
telling us about Raspberry Pi, and how to do IOT, and
I'm sure all the folks are gonna do that at home.
So thanks for watching another episode of On.NET, and
I hope you learned something today, thanks.
[MUSIC]