1
00:00:00,720 --> 00:00:04,570
Hi, welcome to the last lecture in this section, in this lecture.

2
00:00:04,590 --> 00:00:10,100
I'll show you how to read a value from a potential error and then use it to drive.

3
00:00:10,170 --> 00:00:16,490
And using GWM this potential race, regular 10 kiloton potential murder.

4
00:00:16,490 --> 00:00:21,270
I have connected to your 34 right here.

5
00:00:21,510 --> 00:00:28,560
And I've got one pin going to the three point three volt power rail and the other one to ground.

6
00:00:29,460 --> 00:00:31,410
Let's have a look at the sketch.

7
00:00:31,560 --> 00:00:33,740
There's a couple of interesting things happening here.

8
00:00:34,590 --> 00:00:40,950
First of all, as you can see here in my notes, we will be using the ADC, the analog to digital converter,

9
00:00:41,220 --> 00:00:47,070
to take readings from the potential mirror, and then we'll convert those readings to an appropriate

10
00:00:47,070 --> 00:00:48,870
peak in value.

11
00:00:49,290 --> 00:00:57,480
Now, the thing to remember is that by default, ATC producer values 12 bits, which means that the

12
00:00:57,480 --> 00:01:03,450
range of an ATC value goes from zero to four thousand and ninety five.

13
00:01:03,900 --> 00:01:08,220
And as you've seen in the previous election, the Section PITIABLY and Values Pettifor have 10 bits

14
00:01:08,640 --> 00:01:14,160
in width, so values ranging from zero to one thousand point twenty three.

15
00:01:14,520 --> 00:01:20,360
And therefore we need to do a little calculation to scale the ADC value into a P value.

16
00:01:20,760 --> 00:01:28,050
And this calculation is simply divide the range of the M by the range of the ADC and that will give

17
00:01:28,050 --> 00:01:35,040
us the scaling factor, which happens to be three point twenty four, probably closer to zero point

18
00:01:35,040 --> 00:01:35,760
twenty five.

19
00:01:35,760 --> 00:01:36,470
But OK.

20
00:01:36,990 --> 00:01:38,610
And we'll see what values come out later.

21
00:01:39,060 --> 00:01:45,900
And that means that you just multiply whatever comes out of the ADC by zero point twenty four and that

22
00:01:45,900 --> 00:01:50,880
will give you a new value that is within the range.

23
00:01:52,080 --> 00:01:55,230
I also have the documentation for the ATC here.

24
00:01:55,710 --> 00:01:58,050
I'm going to refer to this in a moment.

25
00:01:58,050 --> 00:02:05,070
And there's also documentation for a built in python function called E.A. Integer that converts floating

26
00:02:05,070 --> 00:02:06,900
point in this into integers.

27
00:02:06,900 --> 00:02:13,740
Again, we need to make this conversion from floating point to integer in sketchiest.

28
00:02:13,740 --> 00:02:14,570
You'll see in a moment.

29
00:02:15,510 --> 00:02:16,550
Let's have a look at the script.

30
00:02:16,770 --> 00:02:27,090
So we need to first import ADC pain and P m from the machine module and sleep from the time module.

31
00:02:27,330 --> 00:02:32,580
Here I'm using sleep, which allows me to define a sleep time in seconds instead of milliseconds of

32
00:02:32,580 --> 00:02:32,820
time.

33
00:02:32,820 --> 00:02:42,900
In some of the previous scripts in line thirty nine, I create the M object ytterbium twenty one.

34
00:02:43,110 --> 00:02:50,910
Just to make it easy for me to remember that this is connected to Shapir twenty one and for the ADC

35
00:02:51,300 --> 00:02:57,360
I'm using pin thirty four as I said earlier and using ADC constructor in the object.

36
00:02:57,930 --> 00:03:04,350
Now here's one interesting way to configure the attenuation of your ADC.

37
00:03:04,350 --> 00:03:08,580
The analog to digital converter is to use the atin function.

38
00:03:09,150 --> 00:03:18,480
You can find out what the available attenuation levels by having a look at the documentation but hyperlink

39
00:03:18,480 --> 00:03:20,100
to right here.

40
00:03:21,330 --> 00:03:22,980
Let's check it out.

41
00:03:22,980 --> 00:03:31,620
It is this section of the document and there is the attend function and these are the available attenuation.

42
00:03:32,160 --> 00:03:36,900
So zero degrees with those two and a half decibel, six and eleven.

43
00:03:37,110 --> 00:03:44,400
And I've gone for the eleven decibel attenuation which gives me maximum input voltage up to three point

44
00:03:44,400 --> 00:03:45,480
six volts.

45
00:03:46,380 --> 00:03:51,420
So depending on what it is that you are connecting, you can choose the appropriate attenuation.

46
00:03:52,440 --> 00:03:56,730
You can also control the width of your analog to digital converter.

47
00:03:56,730 --> 00:03:57,870
I'm not doing that here.

48
00:03:57,870 --> 00:03:59,820
I'm just leaving it to its default.

49
00:03:59,820 --> 00:04:00,780
Twelve page.

50
00:04:01,380 --> 00:04:06,270
You can see you can go for nine, ten, eleven, twelve bits for the width.

51
00:04:07,420 --> 00:04:16,390
OK, and moving on now, I've got a infinite loop here, while true, start by taking reading of the

52
00:04:16,390 --> 00:04:23,560
potential murder, using the read function, then I multiplied by the scaling factor, your point twenty

53
00:04:23,560 --> 00:04:25,290
four that I calculated up here.

54
00:04:25,990 --> 00:04:33,430
And that gives me a floating point that I need to convert it to an integer using the anti function.

55
00:04:33,790 --> 00:04:41,050
And I stole the result in PWI and then in line 47 or print out those two numbers so I can see the original

56
00:04:41,050 --> 00:04:47,920
and the scaled number, then use that to set the short cycle for the entity.

57
00:04:48,910 --> 00:04:53,200
And then take a little nap for zero point one seconds, OK?

58
00:04:54,190 --> 00:05:02,320
Let's try this out, I'm going to get a copy of the script on the device log.

59
00:05:04,440 --> 00:05:10,680
Great report, which is connected to Perio 34 Togepi y.

60
00:05:12,510 --> 00:05:19,530
Yes, but an earlier version of this earlier this script to double click on it, you open it up, can

61
00:05:19,530 --> 00:05:20,580
you get rid of the other two?

62
00:05:20,580 --> 00:05:25,780
So that does confuse me as to which script I'm uploading to my hospitality.

63
00:05:26,190 --> 00:05:28,230
And this is the one that I want to upload.

64
00:05:28,290 --> 00:05:28,860
So let's do it.

65
00:05:30,690 --> 00:05:34,510
You go right, you can see the current values for the potential.

66
00:05:36,160 --> 00:05:38,170
Let's move at One Direction.

67
00:05:40,650 --> 00:05:47,670
Then you saw moving the early days, becoming fainter to goes off, let's go to the other extreme.

68
00:05:50,430 --> 00:05:58,800
Trying to do this in a nangle, simple, all right, going up in this chaos, and that's the maximum,

69
00:06:00,090 --> 00:06:06,150
you can see that the potential murder is at four thousand ninety five is nine hundred and eighty two,

70
00:06:06,690 --> 00:06:18,660
which means maybe I can increase this factor by maybe as much and that they allow me to go for the full

71
00:06:19,350 --> 00:06:22,970
MGD cycle extent without going over it.

72
00:06:22,980 --> 00:06:35,640
So save and play soldier one thousand twenty three point twenty five Scaling factor, which works out

73
00:06:35,640 --> 00:06:36,150
perfectly.

74
00:06:38,430 --> 00:06:38,850
Right.

75
00:06:42,780 --> 00:06:48,240
So that's how you can use the ATC and your is pathetic to using micro python.
