Tip:
Highlight text to annotate it
X
In this video we will take a look at the TMP102 temperature sensor
There are links to resources below including a link to the buildr.org article on the
tmp102
and to a great resource on I2C.
you'll also find a link below to the code so don't worry about trying to copy it
from the video
there are of these sensors on an NanoSatisfi's ArduSat.
the tmp102 is not only tiny but it's also accurate they can detect point zero
sixty two five celsius fluctuations between eighty five c in negative twenty five c
The tmp102 is an I2C device so it's a little more difficult
to read in a typical analog sensor but you get more accurate readings this way
just for review was taking another look at i2c
i2c uses two wire serial connection
one wire is sda
and the other is scl
a basic arduino the sda on the analog pin 4 and scl this on the analog pin 5
confined arduino mega yes sda is digital 20 and scl is digital twenty one
We will communicate with the tmp102 using the library we use for most of
I2C devices
the wire library
most the time ice i2c addresses are seven bits
that means you can have up to one hundred twenty eight devices
since the seven bit number can be from zero to one twenty seven value
we still send 8 bits and the last bit is used to inform the slaves if the masters
is writing or reading from it
the seven bit address is placed in the upper seven bits of the byte
in the redirect their is the LSB
least significant bit
for now let's assume we have one of these sensors connected to an arduino.
this sensor has an address pan
we'll ground that pin so the address will be seventy two
zero X forty-eight in HEX
let's look at the code courtesy of buildr.org
we include wire.h - we set the address to our tmp102
as an integer
in set up we set our baud rate to ninety six hundred for serial connection
we initiate the wire library
and join the i2c bus
now is take a look at our loop
We're going to call a function called gettemperature()
and store the return from that function as a float called celsius that's going to
be our temperature
and we'll print out our result over the serial connection
we'll do the same below and convert it to fahrenheit
let's take a look at our get temperature function without it nothing with work
We use our wire library get two readings from our tmp102
we pass it the address and the quantity
you may have noticed that we didn't do anything with the request
that's because we have to read back what we requested
we'll do that sequentially
the first byte, we get the most significant
gets stored in MSB
the second byte we get, the last significant byte, gets stores in LSB
we need to do some bitmath
ameyer from builder.org provided a great explanation in the forums so I'll quote it.
The code receives the temperature information from the sensor in two bytes
if the first part AKA the most significant byte
in a variable named MSB
and i get a second byte called least significant (LSB)
so we have two bytes, right? and we need to combine them
so we move the MSB over to the left eight bytes doing this
then we or that value with the LSB by doing this- the temp values only twelve
bit's long but we have sixteen bits so we need to get rid of the first for bits we
do this by moving the value to the right for bits like this
so that has the twelve bits to make up the temperature value
let's hop back to our code
we do our bit math
and then we convert the temperature to celsius and return that be printed
so that's the gist of using the tmp102 sensor
there are links to resources below including a link to the buildr.org article
on the tmp102
and to a great resource on i2c
also find the link below to the codes so don't worry about trying to copy out of
the video