0:09
hello and welcome to controllers tech
0:12
this is yet another video covering the
0:14
stone display and as we discussed in the
0:16
previous video today we are going to
0:19
interface the stone hmi display with
0:24
i have already explained how the display
0:26
communicates using the uart in the
0:28
previous video and today we will
0:30
continue where we left last time
0:33
here is the picture of the display here
0:36
you can see there are some pins
0:37
available to connect directly with the
0:41
but the spacing between the pins is too
0:43
wide and i don't have the appropriate
0:47
so i am going to use the uart to usb
0:50
board that comes along with the display
0:52
as it has some set of pins which can be
0:54
used as the tx and rx pins
0:58
after doing some continuity testing i
1:00
have found out that the tx-b is
1:01
connected to this particular pin right
1:03
here and the rxb is connected to this
1:08
we have already discussed that the stone
1:10
hmi outputs the data in the rs 232
1:16
so in order to convert it to the ttl i
1:18
am using this rs 232 to ttl converter
1:23
this is the pin out for the ttl
1:25
converter and as you can see on the top
1:27
row the middle pin which is pin number
1:30
three is the rx pin and pin number two
1:35
there are other pins but we are only
1:37
interested in these two pins
1:40
the esp32 vroom board has gpio 16 and 17
1:45
as the rx and tx pins for the uart and
1:48
we will use these pins in order to
1:50
communicate with the display
1:53
here is the connection diagram
1:56
the t-x pin from the board connects with
1:58
the r-x pin of the converter and the r-x
2:01
pin from the board connects the t-x pin
2:04
this converter is powered by 5 volts
2:07
which is provided by the external supply
2:10
i tried using the 3.3 volts but it was
2:16
anyway the t-x pin from the converter
2:18
connects with the t-x pin of the esb 32
2:21
and the rx pin connects with the rx pin
2:25
one very important thing you have to
2:26
note is on this side we have a cross
2:29
connection between tx and rx pins but on
2:32
the controller side there should be a
2:33
straight connection connecting the t-x
2:35
with t-x and r-x connecting with r-x
2:39
let's start the expressive i-d-e
2:46
in the meantime let's see the u-i
2:48
design i am going to continue from the
2:54
this is the label we had in the previous
2:56
project along with the two more labels
2:58
that i added for this project
3:01
this particular label is going to act as
3:03
the indicator of the led state so
3:06
whenever we press the button it's going
3:07
to show the current state of the led
3:10
this label 2 is going to display this
3:13
string and it will remain unchanged
3:16
we have one more label which is label 3
3:19
that's where we will print the numerical
3:21
values of some variable
3:24
so there are not many changes i have
3:26
made here let's just save this project
3:28
and we will copy this into the display
3:32
all right let's create a new expressive
3:37
give some name to it and check using the
3:41
navigate to the peripherals and here
3:44
under the uart section select this one
3:47
we have already covered this in the
3:49
previous esp32 video and we will utilize
3:52
the same method to communicate with the
3:58
we have the project here before going
4:00
any further let's build it once
4:06
the build is successful so we will start
4:09
with the modifications
4:11
first we need to see if we are receiving
4:13
the data from the hmi module or not
4:17
so block this t-x task as we don't need
4:21
as i mentioned earlier we will be using
4:24
the pins 16 and 17 as the tx and r-x
4:27
pins which are the uart2 pins
4:30
we need to define them in the code here
4:34
also change the uart number to uart2
4:36
everywhere in the code
4:47
make sure the baud rate is set to 11 5
4:52
in the receiver task the hex dump
4:54
function is predefined and it is
4:56
important for us to identify the
5:00
build the code again and make sure the
5:03
target is configured correctly
5:09
download the code into the device
5:21
open the terminal and make sure the
5:23
project and port are correct
5:26
all right let's press the button now
5:33
here you can see the log function
5:35
outputs this data whereas the hex dump
5:38
function outputs a better version of it
5:41
the received data contains the button
5:45
and that's all we need to control the
5:48
if i press the off button the button
5:51
name received is led02
5:54
so we are receiving the data from the
5:56
module and now we will proceed with the
6:00
i am removing this additional function
6:02
send data as i will directly send it in
6:05
the task function itself
6:07
i am going to use the led on board so i
6:12
i am also defining an integer variable
6:15
and a character pointer to tx data
6:18
now in the rx task we receive the data
6:21
using the uart read bytes function
6:24
let's change the timeout to 200
6:26
milliseconds so that we don't have to
6:28
wait for long for the button data to
6:31
after we receive the data we will add
6:33
the terminating character at the end of
6:37
and here is our code to handle the
6:41
first we will compare the incoming data
6:43
from the 7th position with the string
6:46
led 0 1. this is basically the button
6:49
name for the on button
6:51
let's understand this with the
6:53
instruction set manual
7:00
here is the response of a button when
7:03
the first seven bytes of this response
7:05
remain fixed irrespective of what the
7:09
the button name starts from the seventh
7:11
position and this is why we are looking
7:13
for the button string starting at the
7:18
if the string led 0 1 is found in the
7:21
data the string compare function will
7:25
this means the on button has been
7:27
pressed and inside this loop we will
7:29
first turn the led on
7:31
then we will allocate the memory for the
7:35
i am assigning 100 bytes for the same
7:39
now we need to send the led state to the
7:42
label we created to understand this we
7:45
will look into the label section
7:50
this is the format we need to send to
7:52
the module to display some string on it
7:55
let's copy this into our s printf
7:59
the command needs to be inside the quote
8:01
indicating it as a string
8:03
and we need to put a forward slash
8:05
before every double quote in this string
8:14
the led state indicator widget has the
8:19
the text field contains the string that
8:21
is going to be displayed on the label
8:24
since the l-e-d is turning on here we
8:26
will set the string as l-e-d on
8:34
then we will send this data stored in
8:36
the t-x data buffer to the uart using
8:39
the function you outright bytes
8:42
in the end we will free the memory
8:44
allocated for the tx data buffer
8:46
similarly we will look for the string
8:48
led 0 2 which is sent by the display
8:52
when we press the off button if the
8:54
string is found we will turn the led off
8:57
and we will send the led state that is
9:00
led off to the label 1.
9:03
we don't need to log the data but i am
9:05
just keeping these for now
9:12
let me comment out this entire thing for
9:14
now since we are not sending any data
9:22
we also need to set the direction of the
9:32
all right the code builds just fine so
9:34
let's upload it to the board
9:37
let's check the buttons now
9:54
the led is responding fine with the
9:58
the button state is indicating correctly
10:01
so the command we sent to the display
10:03
has been received by it as well
10:11
now we will send the value of a variable
10:13
to the third label we created
10:19
i am going to use this t-x task for the
10:32
here we will first allocate the memory
10:34
for the t-x data buffer
10:38
then we will store the command into the
10:42
its same as the previous command we
10:44
discussed except the label is label 3
10:47
and the text is the format specifier for
10:50
the integer where we are going to store
10:52
the incremented value of the integer
10:58
then we will send the t-x data buffer to
11:02
in the end we will clear the memory
11:04
allocated for the t-x data buffer
11:07
i am setting this loop to run every 500
11:12
let's build and download this code to
11:22
you can see the value is incrementing
11:26
the led is responding to the on and off
11:38
so we saw how to use uart to receive the
11:40
data from the display
11:42
and how to print any string on it
11:45
you can extend this technique to more
11:47
elements available on this hmi module
11:51
i hope you understood the video
11:53
the link to download the code is in the
11:56
description of the video
11:58
leave comments in case of any doubt
12:01
keep watching and have a nice day ahead