0:17
hello and welcome to controllers Tech
0:21
this is the fourth video in the stm32
0:24
touch gfx series and as I mentioned in
0:27
the previous video this video will also
0:30
replace the old video in this playlist
0:33
in the previous video we saw how to
0:35
sample the data from the GUI task and
0:38
send the data to the UI via the
0:41
as I mentioned in the previous video
0:43
this video is going to cover the
0:46
sampling from another task
0:48
I am going to use the same button and
0:50
potentiometer which I used in the last
0:52
video but this time I will use a gauge
0:55
and the animation instead of text area
0:57
and images that I used in the previous
1:01
here the same PDF explains how we can
1:04
sample from another task
1:07
we can set the priority of the task
1:09
higher or lower than the GUI task
1:10
depending on how time critical the task
1:14
if the task has higher priority than the
1:17
GUI task it might impact the frame rate
1:21
regardless of what method we use for
1:23
sampling The Tick function is the place
1:25
where the GUI task becomes aware of the
1:28
new data to be shown in the UI
1:30
we have already seen this in the
1:32
previous video and here also we will use
1:35
the tick function to receive the data
1:39
if other tasks are being used SD
1:42
recommends the use of inter-task
1:44
messaging system to send the data to the
1:47
this includes mailbox message queues Etc
1:52
we will do the same in this video
1:55
let's start the touch gfx and create a
2:02
stm32f750 discovery board
2:06
give some name to the project and click
2:11
let's add the background image to this
2:19
I am going to use the gauge to display
2:26
you can choose from the different
2:28
presets available here I am leaving it
2:32
the range of the values is from 0 to
2:37
let's set the initial value to zero
2:40
that's it for the gauge setup
2:43
I am configuring the animated image now
2:49
I have here the set of images extracted
2:53
let's add all of them to our project
2:58
now choose the first and the last image
3:07
I don't want it to automatically start
3:11
basically this GIF will be controlled by
3:14
the button and as long as the button is
3:16
pressed the animation will keep running
3:19
so the button will control the animation
3:22
and the ADC values will update the gauge
3:25
here is the name of this image animated
3:30
that's it for the touch gfx part let's
3:33
generate the code now
3:36
go to files now go to Project folder
3:39
stm32 Cube ID and open the project in
3:45
let's set up few things in the cube MX
3:49
the button is connected to the pin Pi 11
3:52
so let's set it as the input
3:55
I am pulling this pin low so when the
3:58
button is clicked it will be pulled High
4:01
let's configure the ADC
4:04
I am using ADC 3 Channel 0.
4:09
the resolution is 12 bit so the values
4:12
will vary between 0 to
4:15
4095. I want the conversion rate to be
4:18
slower so I am setting the maximum
4:20
sampling time available here
4:23
let's also add the dma for the ADC
4:27
we will see both the methods where we
4:30
will sample from another task and send
4:32
the data to the UI and also where we use
4:34
the interrupt and send the data
4:37
configure the dma in circular mode
4:41
the ADC resolution is 12 bit so an
4:44
unsigned 16-bit width is required
4:47
let's enable The Continuous conversion
4:50
and also enable The dma Continuous
4:54
here the dma interrupt is enabled so we
4:59
let's add the tasks in free rtos
5:03
here you can see the touch gfx task as
5:08
so now if your task is very time
5:10
critical keep the task priority higher
5:14
but I don't have such requirements so I
5:17
will keep the priority lower than normal
5:20
so I am adding a button task with low
5:24
and an ADC task again with a low
5:31
now the task has been created let's
5:34
create the cues for inter-task
5:37
first I am creating the button queue
5:41
there is not much data needed from the
5:43
button so the queue size of 2 is enough
5:46
I will be storing a 1 and 0 to this Q so
5:50
unsigned int is enough
5:52
the second queue is for the ADC
5:55
our ADC data is 16 bit in size so make
5:59
sure the queue also has the same or
6:04
five items are enough for this as the
6:06
conversion rate is anyway slower and
6:09
even if the data is lost it's not a big
6:12
so this is it for the cube MX
6:14
configuration click save to generate the
6:18
the pins and the connection are the same
6:21
as what I used in the previous video
6:24
the potentiometer is connected via the
6:26
ADC and the button is connected to the
6:31
let's start writing the main file first
6:35
I am creating variables to store the
6:37
button State and the ADC value
6:40
I am also going to use the same map
6:43
function from the Arduino source which I
6:46
used in the previous video
6:48
by the way I have added the touch gfx
6:51
series to the website
6:53
more tutorials will be updated here soon
6:56
as I will make more videos on this topic
7:03
let's write the button task first
7:09
here we will read the pin Pi 11 and
7:12
store its value in the button State
7:19
this value is either going to be a 1 or
7:23
I want this task to run every 5
7:28
now after retrieving the button State we
7:30
will send the value to the message queue
7:33
the ID is the button queue handle the
7:36
address of the variable the priority is
7:40
since I am keeping the timeout zero the
7:42
message will be put to the queue only if
7:44
there is some space available it will
7:46
not wait for the space to become
7:52
this is going to be the same code we
7:55
used in the previous video
8:13
I want this task to run every 10
8:18
after the ADC data has been converted we
8:21
will send the data to the ADC queue
8:24
again I am sending the data with zero
8:27
priority and zero timeout
8:30
let's build the code once to see if
8:36
everything seems fine so let's go ahead
8:40
we will first start with the model
8:42
source file let's include the cmsys os2
8:46
header file and Main header file
8:51
we will be using the ADC and button
8:54
queue here so we need to First Define
9:03
now we will fetch the data from the
9:05
queue in the tick function
9:11
the OS message Q get count Returns the
9:14
number of messages in the queue and if
9:17
there is some message in this ADC queue
9:19
we will read the message and store it in
9:22
the ADC value variable
9:24
we will Define this variable in a while
9:28
the message priority and timeout are
9:30
both zero again so if the message is not
9:33
available this function will not wait
9:35
for it to become available
9:37
we will perform the sending operation
9:39
later first let's fetch the button data
9:45
we will save the queue data to this
9:52
now if the button is equal to 1 the
9:54
button State variable will be set to
9:56
True else it will be set to false
10:05
let's create these variables first
10:09
in the model header file Define an
10:12
integer variable ADC value and a Boolean
10:15
variable button state
10:17
now initialize the variables in the
10:21
now we have the data from the queue so
10:24
we will send it to the UI
10:27
I have already explained this part in
10:31
we will call the function using the
10:33
model listener which is a pointer to the
10:35
presenter and send the ADC value as the
10:40
similarly we will send the button state
10:42
to the presenter using the function set
10:52
now we will Define the functions in the
10:55
model listener header file and the
10:57
presenter header file
11:05
in the source file the presenter will
11:08
call the same function in The View
11:20
Define the same function in the view
11:24
now in the view source file we will
11:27
write these functions to display the
11:29
respective data on The View
11:31
the set ADC function will display the
11:34
ADC value on the gauge
11:37
set the ADC value to gauge 1.
11:40
and invalidate the gauge so that the
11:43
gauge can be updated
11:45
let's write the set animation function
11:48
the name of the image is animated image
11:52
we will first check if the animation is
11:56
if it is not running and the button is
11:58
clicked we will start the animation
12:02
the parameters are as follows
12:04
if you want to reverse the animation
12:07
I don't want to reverse it so I am
12:12
the second parameter is if you want to
12:16
I am setting it to false again
12:19
and the final parameter is if you want
12:26
now if the animation is already running
12:28
and if the button is released the
12:31
animation will be paused
12:33
so that's it for the IDE let's build and
12:36
Flash the code to the board
12:57
here you can see the gauge is rotating
13:00
as I am rotating the potentiometer the
13:03
minimum value is zero and the maximum is
13:06
100. whenever the button is pressed the
13:10
animation starts and when it is released
13:13
the animation is also paused
13:21
so everything is working as expected
13:24
here we use two different tasks and
13:27
their data was sent using the message
13:29
queue to the GUI task
13:31
now we will quickly see how we can also
13:34
use the interrupt to do the same
13:37
I will leave the button task as it is
13:39
the ADC will be read using the dma and
13:42
the data will be sent from the interrupt
13:45
start the ADC in dma mode but make sure
13:49
you do this inside one of the tasks
13:51
this is because we will send the data
13:54
from the interrupt Handler using the
13:56
queue and the kernel must be initialized
13:58
before we send the data or else we could
14:02
the ADC start dma function takes three
14:05
parameters the ADC instance the pointer
14:08
to the data storage variable and the
14:11
number of conversions
14:13
I am using adc3 we will store the data
14:16
in ADC Val and there is only one
14:19
conversion happening
14:21
once this conversion is complete ADC
14:24
conversion completed callback will be
14:39
I am using this code from my ADC
14:43
so here we will get the ADC value
14:46
then the map function will convert this
14:51
and now we will send this to the adcq
14:55
first we will check if there is any
14:57
space available in the queue and if
14:59
there is put the message in the queue
15:18
let's build and Flash this to the board
15:29
here you can see the gauge and the
15:31
button both are working all right
15:34
so you saw how we can use another task
15:37
to sample the data and then use the
15:39
inter task messaging to send this data
15:43
I have completed both methods to send
15:46
data to the UI as explained in the touch
15:50
in the next video we will see how to
15:53
send bigger data like strings or the
15:56
structure to the GUI task and then
15:58
display it on the UI
16:00
this is it for this video
16:02
you can download the code from the link
16:07
leave comments in case of any doubt
16:10
keep watching and have a nice day ahead