In this video, I'm going to show you how
to use the Raspberry Pi with Windows 10
IoT Core to read Modbus and sensor data. Okay, so our what I have here is this Industrial
Controller from Opto22. So, I've got
this potentiometer mapped to a Modbus
address that we'll be reading using the
Raspberry Pi. And then here, I've got this
Dht11 sensor module that measures
temperature and humidity and
communicates using a 1 wire protocol. So, I will also be reading those values
using the Raspberry Pi. At the end of
this demo, we'll have an app that
graphically shows the value of
temperature and humidity from our Dht11
sensor and our Modbus TCP value from the Industrial Controller, as you can see on
the display. Ok, let's create a blank
Universal Windows project. Now, our
project has been created we'll begin by
connecting to our industrial controller
to read the potentiometer Modbus address using Modbus TCP. And to do that you must
first install a package for Modbus
communication particularly for Universal
Windows app.
Okay, so that's done. Now, let's go to our
MainPage c# file, which is the
code that first executes when our app
starts running. Now I want our app to
read sensor data every second, so I'll
create a timer. And then on
initialization, I'll specify the one
second time span for my timer, specify a
method for handling the timer and then
start the timer. And then, I'll put my
timer method here.
Now, for my Modbus communication I'll
I'll first include the necessary assembly
reference. And then I declare my
variables. I've got my input data my
controllers slave address, my TCP client
master and the modbus data for storing
the conversion from word to float, and
my variable for the result. And then here,
I'll put my method for connecting to the
Modbus client, so here I'm creating a
client with IP address of my controller
and a port, 502. And then here I'm creating
the Modbus master which is my Raspberry
Pi. And then, I'll call my connect method
here on initialization. And then, I'll put
my method for reading Modbus. And then, another one for converting the two bytes
of Modbus into a float. And then when
that is done, I'll call the read Modbus
method every second. Now, that's all for a our Modbus, we move on to our Dht11 sensor
module. First of all, we must include the
package that allows us to talk to the
sensor module via its one wire protocol.
Okay, so we've got our package installed.
Now, we go back to our c# file. And
then here, we add the assembly reference for our sensor module and the GPIO pins
of the Pi. And then, we go on to add the
variables for communicating with my
Dht11 sensor module. So here, I've got
that one wire connected to pin number
four, GPIO pin number four of the PI. And
then here, I'm instantiating a type of DHT
and then I'm also instantiating a GPIOpin type. And then, we also need to
initialize the Dht11 sensor, by opening
the pin number four, and then setting it
as an input pin. And then, we put the
method that does the actual reading of
the temperature and humidity data. And
then finally, we also call the sensor
method after every one second. Now we
have all the code required to read
Modbus and sensor data, but then we need to be able to visualize it graphically.
So, we go to ourXAML page. Now, our
project comes with standard controls
such as your buttons and stuff, but if we
need dashboard controls such as the
Radial Gauge we want to use, we must add a UI package. And then when that is
complete, we reference that package on
our XAML page. And then, I add this
code here, which is, basically I'm
creating a grid with three columns and
two rows. Then in the first row, I'm
putting my three radial gauges, and then
in the second row and putting the labels.
And then finally I go back to my c#
code to include the code for updating
these radial gauges.
And then from here, I make sure thatARM
processor is selected, and Remote Machine
is selected here. And then, confirm the IP
address of my Raspberry Pi. And then I
deploy. Okay, so as you can see our app is
running. So, I will turn the potentiometer
up and breathe into the sensor module.
Okay, so if you need the source code for
this demo please feel free to shoot me a
message, I'll send it to you. Otherwise,
thanks for watching. If you found it
useful, please share it with your
connections. And don't forget to
subscribe on YouTube.
