Now, in this lecture, I want to interface the TMB 36 with Adreno, but first let us go through the
steps that we need in order to read this value and convert it to some real temperature.
So this is my time.
It's connected to a voltage reference.
Could be five votes, could be three point three volts, depending on the microcontroller.
But we're using so the most famous to voltages that you will see in the market or microcontrollers that
are five volt based and microcontrollers that are three point three volt based.
So the voltage reference is very important in the calculation of the outcoming signal in order to calculate
the actual temperature.
So first of all, Audrina Onoe ADC, which we've talked about this before, or Timbits.
So it reads a value and this value can have a range of Timbits.
So Timbits, what does it give us?
What range does it give us when we have fembot?
So it's due to the power of ten, we have two thousand twenty four.
So what does this mean?
It means that we are reading a digital value between zero and one thousand twenty three.
OK, so whatever sensor you are connecting to this ADC, it's going to convert it to a value inside
this range.
Now there are bigger ATCs like 11 bits and pieces, Drillbit ATCs.
They can take larger values.
It means that they can be more accurate when reading a voltage value.
This is why there is a lot of ADC technologies, and this is why some of the microcontrollers are suitable
for certain ADC applications and some are not.
And the difference is the accuracy.
I mean, every time this range increases, you can get more accurate values from your sensor.
Right.
Let us continue.
Now, let's assume that the voltage reference is five volts.
Now five volts corresponds to 5000 volts.
Is that correct?
Now, why is this important?
Because sometimes you just want to know what is the conversion step?
It means that whenever you increase from zero to one or from one to two, you want to see what voltage
does occur response to.
So by dividing this 5000 volt by the ADC range, which is the 1024, you get four point eighty eight
to millivolts.
So zero zero volts, one is four point eighty eight to millivolts, two is four point eight.
Two times two.
Right.
So it's around nine point something.
So this is why every change, every step change is in this case.
One, two, three, four.
Every step change corresponds to a voltage change of four point eighty two, and this four point eighty
two could be corresponding to three degrees Celsius or four degrees Celsius.
But initially, we want to know what does it mean to change a millivolts?
Now, this information may be less relevant in this example, but I just want to show you the relationship
between an ADC, its range and the voltage signal that is coming to it.
OK, so these are very important relationships.
Now, what are the steps in order to calculate what's going on here, we need to read the voltage using
our Adreno.
We need to multiply it by the voltage reference.
I mean, if we are using five volts like our Adreno, so we're going to read the voltage multiplied
by five and by that we're going to get the voltage we are reading.
Now, this particular temperature sensor is going to give us a voltage value only between zero and one
point seventy five.
How do I know that if you go and Google TMP 56, you're going to find all the information in its own
data sheet?
So you open the data sheet and you're going to find all of this information.
Now, if you try to do that, we just have to 36 data sheet.
We open the analogue dot com website and we see the temperature sensor right here and we can see that
it reads values between minus 40 and one hundred twenty five Celsius.
Right.
That's amazing.
We can see that we can connect a voltage reference between two point seven and 5.5 volts.
All right.
So we read it and we multiply it by the voltage reference.
OK, next, we need to convert the facilities and the conversion program will offer.
This is just by taking the voltage.
We subtract this zero point four nine six nine nine and we multiply it by one hundred.
And by that we get our value in Celsius.
Now let us go and get to work.
No, first of all, we need to configure our analog input, so how do we do that?
We use the same pin mode and in this time we don't get to give it a number.
We will give it the name here, which is a zero, and we're going to configure it as input.
Now, we cannot configure this as outputs anyway, but we need to specify this in the set up as it is
an input.
There's no other option.
Still, we need to specify it.
Now, I want to begin as well because I want to send the reading information to my cereal.
So cereal begin 9600 Great Neck.
Now I want to read the voltage.
So let us define a variable called voltage.
And what we're going to do is we're going to say analog read a zero.
So we are reading the value from a zero.
What is my voltage reference?
It's five volts, so we will multiply it by the five volts.
OK.
Now remember, we're trying to convert this to the actual voltage by taking V out.
We multiply it by the voltage difference and by that we get the actual voltage and then we need to divide
it by our ADC resolution.
What is my ADC resolution here?
Timbits.
What does it corresponds to?
1024.
OK.
Now, if I take this reading, multiply it by the voltage difference and I divide by what's my ADC is
giving me here, there is a luciane, I'm going to get the actual voltage and let us see.
They said that this sensor takes a value between zero and one point seventy five as a maximum in this
case.
So let us try that out.
So if we say serial dot print, 11 voltage.
We should be seeing the voltage value, but I want to add something now if I just hit on start simulation.
Actually, we still have a very small error.
What is it?
Yes, what is the type of my voltage now since there was a division and the multiplication, if we we
cannot use an integer because we will have a value of a decimal point.
So we need to define the float now.
You would expect that you're going to get different values here, but that's not the case.
I'm going to show you what's going to happen when I hit on simulation.
I'm getting zero, even though I changed my value.
I'm getting a zero and one, why is that?
You need to learn that when you are using float and you're going when you are doing a float operation
since this is an integer.
Well, this whole operation will be an integer.
So what you need to do is instead of dividing by 2024, you need to divide by 2024 decimal zero.
Now, this will convert this whole operation to float as a result.
Now, this is giving us an integer, actually.
And remember, an integer, there's no decimal points.
This is why it's rounding down and up to zero and one.
Now, if I hit on simulation again.
You'll see that are starting to get a decimal value.
Now, if I go to zero, it will give me.
As you point one, and if I go all the way up to 125, I'm going to get one point seventy five, that's
a great.
Now let us convert this to Celestis.
I'm going to say float Celestials is going to equal to the voltage that I have now, opening up parenthesis,
say, the voltage minus zero point four nine six nine nine.
This is the conversion formula for the the six.
You can look it up online and we going to see what is the conversion formula.
Dimes one hundred.
This is how we convert to Solicitors' in this particular case.
Now let us try to print Celestials.
Start simulation.
And as you can see, we are already 25 and we are setting this already to 25, I set it to 70, almost
70, setting a 225, reading almost under 25, and that's it.
This is how we use our analog input.