0:08
hello everyone welcome to controllers
0:11
tech today in this video we are going to
0:15
interface joystick with stm32 I am using
0:19
stm32 f-100 and three micro controller
0:23
joystick can be used for the purpose of
0:26
controlling the robot or a camera or
0:28
anything else the output from the
0:31
joystick is in the form of an analog
0:33
signal and so we have to use the ADC to
0:37
read this data here i am using channels
0:41
1 & 2 of ADC 1 the pins used are a 1 and
0:46
a 2 there is a little bit of setup needs
0:49
to be done in the ADC first select the
0:54
continuous conversion mode and enable it
0:56
this is because we want the conversion
0:59
to be taking place continuously next
1:02
select the number of conversions as 2
1:05
because we have two channels to do the
1:08
conversion for ranked one is for channel
1:11
1 and I have changed the sampling time
1:14
to two hundred and thirty nine point
1:17
five cycles to make the conversion
1:19
fastest possible rank two is for channel
1:22
two with same settings next thing we
1:26
need to do is enable the DMA in circular
1:29
mode this is important since in order to
1:33
use multi channel we have to use DMA
1:36
next I am going to connect four pins to
1:39
the four LEDs to demonstrate the working
1:42
of the joystick and so I am selecting
1:45
these four pins as output the rest is
3:09
Here I am creating an array of two
3:12
variables to store the ADC result it
3:15
must be a 32-bit unsigned integer
3:18
because that's the argument of the ADC
3:20
DMA function next we need to start a DC
3:25
in DMA mode and the argument will be the
3:28
array that we created above please note
3:31
that do not write this inside the while
3:34
loop write it before the while loop
3:36
begins now let's compile it and flash in
4:09
let me just quickly fix this one
4:26
okay so the flashing is done now I will
4:30
show you the result in the STM studio
4:41
first go to the project folder in the
4:44
debug folder open the dot e.l.f file
4:56
now send both of these variables to the
4:59
variable viewer and change it to the bar
5:02
graph now notice the bar graph as I move
5:11
the stick around note these values
5:14
carefully especially the extreme values
5:17
this is varying between 0 to 4095
5:21
because the ADC and stm32 have 12 bit of
5:25
resolution we will write our rest of the
5:28
program based on these values
6:15
in my case vr0 is connected to the VXR
6:22
this is the case if the stick is in the
6:24
middle then all the LEDs will be off
7:08
rest we can write individual cases for
7:11
each position turning on individual LEDs
8:17
this is it guys I hope you enjoyed the
8:21
video you can download the code from the
8:24
link in the description keep watching