0:09
hello and welcome to controllers Tech
0:12
this is the fourth video in the lvgl
0:15
series and today we will see how to send
0:17
and retrieve data from the display I am
0:20
going to use the U to send the data from
0:23
the computer to the MCU which will then
0:25
display on the UI I will also use the
0:28
ADC to read the potentiometer and modify
0:31
the arc on the display according to it
0:34
to send the information from display to
0:36
the MCU we will use three buttons on the
0:39
display which will be used to control
0:41
the LEDs on the MCU let's continue with
0:45
the previous project on the
0:47
lvgl here I have imported the project to
0:50
the IDE we need to include art ADC and
0:55
LEDs to our project so let's open the
0:58
cube MX the nucleo and Discovery boards
1:02
support the virtual comp port for the
1:04
uart so I am going to use the same here
1:08
is the schematics of the nucleo L
1:11
496 you can see the pins pg7 and pg8 are
1:15
connected to the SD link RX and TX pins
1:19
these pins are actually connected to the
1:21
U peripheral of the SD link and hence we
1:24
can use the SD link USB as the virtual
1:27
comp Port you can also use an external
1:30
USB to TTL module to communicate to the
1:33
computer using the uart let's enable the
1:36
low power uart in the asynchronous mode
1:39
the default pins assigned are the pins
1:43
pc1 let's configure the pin pg7 and pg8
1:48
as the RX and TX pins for the uart now
1:52
we need to configure the
1:54
parameters I am setting the board rate
1:58
115200 the word length should be 8 Bits
2:02
let's also enable the global interrupt
2:04
for the uart now we will configure the
2:07
ADC let's enable the adc1 channel one in
2:11
the single-ended mode the pin pc0 has
2:15
been selected as the channel one pin the
2:18
resolution is set to 12 bits I am
2:21
leaving everything to default as I will
2:24
use the blocking mode to read the ADC
2:26
value now let's set the LEDs as output
2:31
here you can see in the schematics we
2:33
have the red LED connected to the pin
2:36
pb14 we have a blue LED connected to the
2:40
pb7 we have one more green LED connected
2:46
pc7 let's set these three pins as output
2:49
in the cube MX I am also renaming the
2:53
pins so that it will be easier for us to
3:04
that is all we need to do here click
3:06
save to generate the project I have
3:09
already created a project in square line
3:11
Studio I will explain it there is a text
3:15
area where we will display the data
3:17
received from the uart I am also using
3:20
an arc to display the ADC value here the
3:24
range for Arc is set between 0 to 100 so
3:27
we will also map our ADC value within
3:30
this range then we have three switches
3:34
which will be used to control the three
3:36
LEDs on the board I have also created
3:39
events for these switches which will
3:41
trigger when the switches are clicked
3:44
here we will call these functions which
3:47
we will Define later in the
3:50
code let's export the UI files let me
3:54
delete the previous UI folder from the
3:56
project and we will copy our newly
3:58
generated UI folder inside
4:04
it here in the UIC screen source file
4:08
you can see all the components we added
4:10
to the UI all right let's start by
4:13
writing the event file include the main
4:16
header file once the first switch is
4:19
clicked the LED one clicked function
4:22
will be called here we will first check
4:25
the current state of the switch you can
4:28
see all the available States but we are
4:31
interested in the checked State this
4:33
means that the switch has been enabled
4:37
if this happens we will turn the LED 1
4:40
on otherwise if the state is not checked
4:43
which means that the switch is disabled
4:45
turn the LED off repeat the same for the
4:50
functions that is all we need to do in
4:52
the event file let's go to the main file
4:56
now here after the UI has been
4:59
initialized I ized we will receive the
5:01
data from the uart in the interrupt mode
5:04
I am setting the 32 bytes limit here as
5:07
this is enough to test the UI let's
5:10
define the RX data array where the
5:12
received data will be stored once all
5:16
the 32 bytes have been received or there
5:18
is an idle line before that the uart
5:21
interrupt will trigger and the RX event
5:25
called here we will set the received
5:27
data to the text area
5:30
now clear the RX buffer so that there is
5:33
no residue from the previous
5:35
reception call the receive to idle
5:38
function again as Hall disables the
5:42
call now we will write one more function
5:45
for the ADC read and write to the
5:48
UI let's also Define the map function to
5:51
map the ADC values within a certain
5:54
range inside the ADC read function we
5:57
will first start the ADC
6:00
then PLL for conversion to
6:02
complete then read the ADC value and
6:07
ADC Now map the ADC value which can
6:13
4,095 to the range 0 to
6:16
100 and finally we will set the value to
6:19
the arc defined in the
6:21
UI let's call this ADC function in the
6:26
loop that is all let's build the code
6:29
now we don't have any errors so let's
6:35
board let's see the connection before we
6:38
proceed with the output I have already
6:41
shown the LCD Connection in the previous
6:43
videos so let's skip that here is how
6:47
the potentiometer is connected to the
6:49
board it is powered with 3.3 volts from
6:53
the board and the ADC pin is connected
6:57
pc0 I am using the virtual come for the
7:00
uart so there is no need to connect any
7:02
external hardware for the same but if
7:05
you do want to use a TTL module the
7:08
connection should be as shown here the
7:10
RX pin from the board connects to the TX
7:13
pin of the module and the vice versa all
7:17
right let's see the working now here you
7:20
can see the UI has been loaded to the
7:23
display we will first test the buttons
7:26
and ADC and later the uart you can see
7:30
the LEDs on board are responding to the
7:33
switches each LED is separately
7:35
controlled by a switch the ADC is also
7:39
responding well the arc denotes the
7:42
position of the potentiometer and is
7:51
now I am using this wch serial Port
7:55
application on my Mac let's open the
7:58
comp port at 115200 board and eight data
8:03
parity send the string hello world you
8:07
can see it is displayed on the text area
8:13
it everything is working fine I have
8:16
defined the array of 32 bytes in the
8:19
code so it can receive up to that limit
8:21
pretty well so we were able to send the
8:24
data to the display receive the input
8:27
from it and also display the a C value
8:29
on it I hope you understood the
8:32
procedure well in the next video I will
8:36
cover the keyboard and how we can
8:38
receive and store the data entered on
8:40
the display this is it for today you can
8:44
download the code from the link in the
8:46
description leave comments in case of
8:49
any doubt keep watching and have a nice