0:19
welcome to controllers tech this is
0:22
another video covering the raspberry pi
0:25
and today we will see how to use analog
0:27
to digital conversion in pi pico
0:30
i will first cover the adc part where we
0:33
will read the voltage from a
0:36
and later we will see the internal
0:37
temperature sensor which also relies on
0:42
here is the pin out of the picot
0:45
this is a-d-c-0 a-d-c-1
0:48
and a-d-c-2 this pin is the reference
0:52
voltage for the a-d-c
0:55
you can connect the reference voltage
0:58
if not connected then the reference will
1:02
considering the input to pico is greater
1:07
here i will use the potentiometer first
1:11
this is how the connection looks like
1:14
the v-c-c is connected to 3.3 volts from
1:19
ground to ground and the output from the
1:24
is connected to the pin 26 of the pico
1:26
which is basically the a-d-c-0
1:33
let's see the r-p 20-40 data sheet once
1:42
go to the a-d-c section
1:49
here it's mentioned that this chip of 5
1:54
out of them 4 are the regular ones
1:58
you can see them they are available on
2:05
but the 5th one is connected to the
2:12
also the adc have the resolution of 12
2:29
now if we look into the pico python sdk
2:32
it's mentioned here that although the
2:34
resolution is 12 bits
2:36
but in micro python this will be handled
2:41
so this a-d-c behaves as a 16-bit adc in
2:49
that's all for the basic details about
2:53
let's start the thunni ide now
2:57
the device is not connected so i will
3:02
and press stop and you can see the
3:06
let's write our program
3:10
first of all we will import the adc from
3:15
also import the time for delay purposes
3:19
now let's initialize the adc0 which is
3:32
start an infinite loop here first of all
3:35
we will read the adc value and convert
3:38
it to the respective voltage
3:41
this idea is very simple the adc reading
3:44
of 0 corresponds to zero volts
3:47
and the reading of 65 535 corresponds to
3:55
so based on this we can convert our
3:57
reading to the voltage
4:00
now we will print this voltage to the
4:03
and sleep for 10 milliseconds
4:07
now let's save this inside our picot
4:16
it saved successfully so run it now
4:20
you can see the voltage values are being
4:22
printed on the console
4:24
let's rotate the potentiometer now
4:31
this is the maximum i can rotate the
4:34
and it reads 3 point 3 volts here
4:38
now i am rotating in another direction
4:40
and the voltage is decreasing
4:50
its almost zero at the minimum point
4:53
you can see how the voltage is changing
4:56
based on the rotation
4:58
this is because the potentiometer is
5:00
like a variable resistor
5:02
whose resistance varies when rotated
5:05
that's why the voltage output from the
5:08
also varies we can also bring the
5:12
concept of angle of rotation here
5:15
this particular potentiometer can rotate
5:20
that means when the voltage is 3.3 volts
5:23
the angle is 300 degrees
5:27
and when the voltage is zero the angle
5:32
again we will use the ratio logic and
5:34
write one formula to convert the voltage
6:00
you can see how the angle is changing
6:07
this is it for the potentiometer now we
6:10
will see the internal temperature sensor
6:14
let's delete this code first we will
6:17
initialize the a-d-c-4 for the
6:20
because that's the one connected to it
6:24
again write an infinite loop let's see
6:28
20-40 data sheet again
6:32
here go to the temperature sensor
6:37
as you can see here is the formula to
6:40
convert the adc voltage to the
6:44
let's copy it and paste directly in our
6:49
as the formula require the adc voltage
6:53
let's calculate the adc voltage first
7:03
i am going to call it temp
7:08
print the temperature now and add a
7:14
let's save it and run
7:22
you can see the temperature on the
7:29
note that this is in degrees celsius and
7:32
you can use the conversion formula to
7:34
convert it to the fahrenheit
7:40
you can see here if i touch the core the
7:53
it will take some time to go back to
8:00
this is it for this video i hope
8:03
things were clear i will try to bring
8:07
and interrupt videos for the adc in the
8:11
you can download the code from the
8:13
github the link is in the description
8:16
keep watching and have a nice day ahead