0:09
hello and welcome to controllers Tech
0:12
this is yet another video covering the
0:14
stone display and today we are going to
0:17
interface the stone HMI display with the
0:20
I have already explained how the display
0:23
communicates using the uart in the
0:25
previous video which you can check in
0:27
the top right corner today we will
0:30
continue where we left last time
0:33
here is the picture of the display and
0:35
you can see there are some pins
0:37
available to connect directly with the
0:39
controller but the spacing between the
0:42
pins is too wide and I don't have the
0:44
appropriate header pins for this
0:46
so I am going to use the uart to USB
0:49
board that comes along with the display
0:51
as it has some set of pins which can be
0:53
used as the TX and RX pins
0:56
after doing some continuity testing I
0:59
have found out that the txp is connected
1:01
to this particular pin right here and
1:03
the rxb is connected to this particular
1:07
we have already discussed that the stone
1:09
HMI outputs the data in the rs-232
1:12
format so in order to convert it to the
1:15
TTL I'm using this is-232 to TTL
1:20
this is the pin out for the TTL
1:22
converter and as you can see on the top
1:24
row the middle pin which is pin number
1:26
three is the RX pin and pin number two
1:31
there are other pins but we are only
1:34
interested in these two pins
1:37
here is the connection with the Arduino
1:41
the TX pin from the ball connects with
1:43
the RX pin of the converter and the RX
1:46
pin from the board connects with the TX
1:49
this converter is powered by 5 volts
1:52
which is provided by the external Supply
1:55
when I powered it with the 5 volts from
1:58
the Arduino it wasn't working well with
2:00
it so I used some external power supply
2:04
anyway the TX pin from the converter
2:07
connects with pin 1 of the Arduino and
2:09
the RX pin connects with pin 0.
2:12
one very important thing you have to
2:15
note is that on this side we have a
2:17
cross connection between t x and RX pins
2:19
but on the controller side there should
2:21
be a straight connection TX connecting
2:23
with the TX and RX connecting with RX
2:27
let's start with the Arduino IDE
2:31
in the meantime let's see the UI design
2:34
I am going to continue from the previous
2:38
this is the label we had in the previous
2:40
project along with the two more labels
2:43
that I added for this project
2:46
this particular label is going to act as
2:48
the indicator of the LED state so
2:51
whenever we press the button it's going
2:52
to print the current state of the LED
2:55
this Label 2 is going to display this
2:58
string and it will remain unchanged
3:01
we have one more label which is label
3:04
three that's where we will print the
3:06
numerical values of some variable
3:09
so there are not many changes I have
3:11
made here let's just save this project
3:13
and we will copy this into the display
3:17
all right let's continue with the
3:21
first we need to see if we are receiving
3:24
the data from the HMI module or not
3:28
so I am configuring the serial
3:30
peripheral at the board rate 11 5 200.
3:33
note here that I am using the hardware
3:35
serial so the right function will write
3:38
the data to the module as well as on the
3:42
here I am simply reading each byte from
3:45
the module and then writing it back
3:47
although this does not have any effect
3:49
on the HMI display it will print this
3:54
let's flash this and check the output on
4:02
here you can see we have received some
4:05
data on pressing the on button
4:07
if you note here this is the button name
4:10
for the on button there are two sets of
4:13
data because it's being sent when we
4:15
press the button and then again when we
4:21
here we have the name of the off button
4:24
this is all we need to control the LED
4:30
so here is the code for the same
4:35
after configuring the uart with the
4:37
board rate of 11 5 200 I have configured
4:40
the LED as output pin
4:42
inside the loop we will First Look for
4:47
I am using this fine function for the
4:50
if you check the Arduino reference you
4:53
can see this find function here
4:55
basically it will read the data until
4:58
the Target string is found
5:00
if it does find the string it returns
5:03
I am looking for the LED string because
5:05
both the button names contain the same
5:08
string in the beginning and only the
5:10
difference is either it ends 0 1 or 0 2.
5:14
to check for this criteria we will read
5:19
here I am using the function read bytes
5:28
this function basically reads the
5:30
characters from the serial buffer and
5:33
stores them in an array
5:35
basically there are three conditions
5:36
either the determined length has been
5:39
read or the timeout occurs or the
5:41
Terminator character has been detected
5:44
in either of these conditions this
5:46
function will exit and it Returns the
5:49
number of characters stored in the array
5:52
the timeout by default is one second and
5:55
you can modify it using this function
6:00
if we again take a look at the button
6:02
response here you can see that the
6:04
button name is followed by the value
6:06
which is followed by this character
6:11
I am using this as the terminating
6:14
character the data will be stored in the
6:16
RX data array and I am going to read two
6:19
bytes since we only need to know if it's
6:24
if the second byte of the received data
6:27
is 1 that means the on button has been
6:29
pressed and we will turn the LED on by
6:34
then we will send the LED State as the
6:42
if you check out the label section here
6:45
you can find the command for the same
6:48
we just need to edit the label ID along
6:51
with the text we need to send
6:56
here I have done the same the label is
6:59
label 1 and the text we will be sending
7:04
notice that the entire command needed to
7:06
be sent in the string format and that's
7:08
why we will put a backward slash before
7:10
every double quote inside the string I
7:14
am using the S printf function to copy
7:16
the entire string into the TX data
7:19
finally we will send the buffer using
7:22
the serial write function
7:24
similarly if the second byte of the
7:26
received data is 2 that means the on
7:29
button has been pressed and we will turn
7:31
the LED off by pulling the pin low
7:34
and then send the LED state to the label
7:40
remember that since I am using the pin 0
7:43
and 1 on the Arduino whatever data we
7:46
write to the serial it will be
7:47
transferred to the HMI display as well
7:50
as to the serial console
7:52
so basically we can see on the console
7:55
what command is being sent to the module
8:02
here I have pressed the on button you
8:04
can see the LED turned on
8:07
notice the command on the console it's
8:09
the command to print LED on to the label
8:19
when I press the off button the LED
8:21
turns off and the command LED off is
8:24
sent to the label one
8:34
so we were able to control the LED using
8:37
the buttons on the display and we also
8:39
successfully printed the string on the
8:50
now we will see how to print numerical
8:54
I am creating an integer variable here
8:58
if you remember I have created a label 3
9:03
so we will use the same format as we
9:06
used during the label 1.
9:08
here we will convert the numerical value
9:11
to string format using the S printf
9:13
function and then send this string to
9:18
each time this statement gets executed
9:21
the integral variable will increment its
9:39
let me reset this board
9:45
you can see the value is incrementing
9:49
well this is because the function we are
9:51
using inside the loop has the default
9:53
timeout set to 1 second
9:56
so they keep looking for the determined
9:58
strings for one second and if they can't
10:00
find it the function simply exits
10:03
and that's when our value statement gets
10:08
anyway you can see the LED is responding
10:11
well to the buttons as well as the value
10:13
is incrementing just fine
10:16
so we saw how to communicate with the
10:18
HMI module how to control the LED and
10:21
how to print the strings and values on
10:25
this is it for this video
10:27
I hope you understood the concept well
10:31
you can download the code from the link
10:35
keep watching and have a nice day ahead