tmp102


27 posts   Page 1 of 2   1, 2
by sharix » Sun Jul 15, 2012 10:02 pm
has anyone managed to read temperature with the tmp102 I2C sensor?
If yes, could I get a tutorial on how to do it?
I have Chris Boot's custom kernel with I2C support and it has the tmp102.ko module included.
Posts: 170
Joined: Thu Feb 16, 2012 11:29 am
Location: Slovenia
by sharix » Mon Jul 16, 2012 10:06 am
Ok I got it to work with this script:

Code: Select all
#!/bin/bash

hexraw=$(sudo i2cget -y 0 0x49 0x00 w)
while [ "$hexraw" == "" ]; do
    hexraw=$(sudo i2cget -y 0 0x49 0x00 w)
done

msb=$(echo ${hexraw:4:2})
lsb=$(echo ${hexraw:2:1})
dec=$(printf "%d\n" "0x$msb$lsb")

echo "scale=4; $dec*0.0625" | bc


But it sometimes (not always) fails with a read error. How to fix this?
example outputs:
$ ./tmp102.sh
26.6250
$ ./tmp102.sh
26.6250
$ ./tmp102.sh
Error: Read failed
Error: Read failed
Error: Read failed
26.6250
$ ./tmp102.sh
Error: Read failed
Error: Read failed
Error: Read failed
26.6250
$ ./tmp102.sh
Error: Read failed
26.6250
$ ./tmp102.sh
Error: Read failed
Error: Read failed
Error: Read failed
Error: Read failed
Error: Read failed
Error: Read failed
26.6250
$ ./tmp102.sh
Error: Read failed
Error: Read failed
26.6250
$ ./tmp102.sh
26.6250
Posts: 170
Joined: Thu Feb 16, 2012 11:29 am
Location: Slovenia
by sharix » Mon Jul 16, 2012 10:35 am
Alright, I fixed it by connecting ADD0 to GND (previously unconnected).
Posts: 170
Joined: Thu Feb 16, 2012 11:29 am
Location: Slovenia
by NewPi » Sat Aug 18, 2012 2:57 pm
Hi,

I am a programmer but have only basic knowledge of electronics, Now I have my RPi and would like to get things started with hardware.

For getting things started I am looking for a cheap solution to have RPi read temperature and make it updated on my website, now the problem is I have no clue how to get started with temperature sensing.
Could you pls. tell how you made things working with this sensor ?

Thanks
Raspberry Pi Howto, Tips, Tricks and Tools -> http://bit.ly/RPiTricks
Posts: 66
Joined: Sat Aug 18, 2012 2:52 pm
by donster2k » Thu Sep 20, 2012 8:19 pm
I have created a detailed tutorial on using the TMP102 with the Raspberry Pi here:
http://donalmorrissey.blogspot.co.uk/2012/09/raspberry-pi-i2c-tutorial.html
Any comments on how to improve it would be great.
Cheers,
Donal
Posts: 5
Joined: Fri Dec 23, 2011 2:18 pm
by NewPi » Fri Sep 21, 2012 2:31 am
donster2k wrote:I have created a detailed tutorial on using the TMP102 with the Raspberry Pi here:
http://donalmorrissey.blogspot.co.uk/2012/09/raspberry-pi-i2c-tutorial.html
Any comments on how to improve it would be great.
Cheers,
Donal



Awesome, thanks for sharing :)
Raspberry Pi Howto, Tips, Tricks and Tools -> http://bit.ly/RPiTricks
Posts: 66
Joined: Sat Aug 18, 2012 2:52 pm
by Steven Boelens » Fri Sep 21, 2012 7:39 am
In the datasheet (page 10) the serial bus address is specified. And there they have four different addresses. Anyone have experience with this? Most information I see about the tmp102 mentions that two devices can live on the same bus and not four.

Thanks for the tutorial.
Steven
Posts: 41
Joined: Sat Sep 08, 2012 12:16 pm
by chorlton2080 » Sun Dec 23, 2012 9:53 pm
Hi Folks

I've attempted the TMP102 tutorial in MagPi issue 5, and with some reference to the excellent RaspberyPiIVBeginners video, I am encountering problems at the "i2cget -y 0 0x48 0x00 w" stage (testing the module prior to running the script). The command returns with "Error: Read failed". I've queried the bus with "i2cdetect -y 0" and no device appears on the map.

Now, fearing for my soldering skills I immediately tried the module with my Arduino: it works wonderfully. Returning back to the RPi it fails again. I've checked with a multimeter and there is power going to the TMP102; I've since installed an LED off the PWR and GND to verify the supply is fine on the breadboard.

Can anyone offer advice on this?

Thanks

Stu
Posts: 110
Joined: Sun Dec 23, 2012 9:44 pm
by Peter247 » Sun Dec 23, 2012 10:19 pm
it all depends on if you have a rev 2 broad , which you need to change i2cdetect -y 0 for i2cdetect -y 1
http://www.peter224722.blogspot.co.uk/
Posts: 55
Joined: Wed Nov 21, 2012 12:29 am
by Steven Boelens » Sun Dec 23, 2012 10:27 pm
Have you tried bus 1 as well?

i2cdetect -y 1

Between revision 1 and 2 (512MB) RPi's the buses were switched in the hardware. So it could very well be that the tmp102 now lives on bus number 1?

Steven.
Posts: 41
Joined: Sat Sep 08, 2012 12:16 pm
by chorlton2080 » Sun Dec 23, 2012 10:35 pm
Steven, Peter

You were both completely correct! It now works. I hadn't appreciated the significance of the Rev 1 and 2 boards. Thank you very much and a Merry Christmas: this RPi is a refreshing challenging
Posts: 110
Joined: Sun Dec 23, 2012 9:44 pm
by Peter247 » Sun Dec 23, 2012 10:44 pm
I`ve been using the a tmp102 for so long I`ve forgot that it support 4 address.

I`m using python2 & 3 with both quick2wire and smbus libraries to monitor it.
http://www.peter224722.blogspot.co.uk/
Posts: 55
Joined: Wed Nov 21, 2012 12:29 am
by sharix » Tue Dec 25, 2012 12:34 am
Steven Boelens wrote:In the datasheet (page 10) the serial bus address is specified. And there they have four different addresses. Anyone have experience with this? Most information I see about the tmp102 mentions that two devices can live on the same bus and not four.

Thanks for the tutorial.
Steven

The address changes according to which pin you connect with the ADD pin on the sensor.
Posts: 170
Joined: Thu Feb 16, 2012 11:29 am
Location: Slovenia
by Himbeere3.14 » Wed Dec 26, 2012 5:13 pm
Yes, you can add 4 sensors. TheMagPi-description use address 0x48 (hex for 0100 1000 bin).
The tmp102-data-sheet-table 12, Address Pin and Slave Adresses explained for all four addresses which pin must be connected.
E.g.:
0100 1000 -> 48 -> GND
0x48.JPG
tmp102 - 0x48
0x48.JPG (17.85 KiB) Viewed 5764 times


0100 1001 -> 49 -> V+
0x49.JPG
tmp102 - 0x49
0x49.JPG (18.5 KiB) Viewed 5764 times


See attached images for address 48, 49 and connection to the Raspberry Pi.
RaspiTMP102.JPG
Raspberry Pi and two tmp102 (fritzing-library from adafruit)
RaspiTMP102.JPG (40.78 KiB) Viewed 5764 times
Posts: 2
Joined: Wed May 23, 2012 3:34 pm
Location: Munich, Germany
by Mr-Leo » Fri Jan 11, 2013 3:04 pm
I want to read out the TMP102 with Python

This is my code:
Code: Select all
import smbus
bus = smbus.SMBus(0)
address = 0x48
temp1 = bus.read_byte_data(address,0x00)
print temp1


If i change line 4 with:
Code: Select all
temp1 = hex(bus.read_word_data(address,0x00))

I get the temp in hex format. How do i convert this hex format in Python?
Posts: 1
Joined: Fri Jan 11, 2013 2:59 pm
by Peter247 » Fri Jan 11, 2013 4:04 pm
Code: Select all
for smbus :

def get_temp():
   tmp = bus.read_word_data(HEAT_BASE_ADDRESS , 0 )
   Lo = (tmp & 0xff00) >> 8 ;    Hi = (tmp & 0x00ff)
   temp  = ((( Hi * 256 ) + Lo) >> 4 ) * 0.0625      
   return temp

for Quick2wire

class tmp102:

   def __init__( self , CHIP_BASE_ADDRESS ):
      self.CHIP_BASE_ADDRESS = CHIP_BASE_ADDRESS
   
   def __str__(self):
      return str(self.read())

# ( High byte * 256 ) + Low byte , then / 16 and the result * 0.0625
 
   def read(self):   
      with I2CMaster(1) as master:
         Hi_byte , Low_byte = master.transaction( quick.reading(self.CHIP_BASE_ADDRESS , 2))[0]
         heat = (((( Hi_byte << 8 ) + Low_byte) >> 4) * 0.0625 )

         return heat


there is a fault in my code , for minus temperature.

I`m waiting until a minus temp to check my code.
http://www.peter224722.blogspot.co.uk/
Posts: 55
Joined: Wed Nov 21, 2012 12:29 am
by Peter247 » Sun Jan 13, 2013 12:46 pm
I spent a couple of hour last night making my code work with minus temperatures.
After looking at every bit of code I can find , written in c++ , and python for any and every platform I`ve found no code deal with minus temperatures.

I think I`ve got to grips with i2c and can read and understand pdf chip document, But can say that the tmp102 pdf is the most confusing document I`v every seen in my life.

I`ve worked out how to deal with minus temperatures, Wow and my code works
http://www.peter224722.blogspot.co.uk/
Posts: 55
Joined: Wed Nov 21, 2012 12:29 am
by sharix » Mon Jan 14, 2013 7:19 pm
for temperatures ≥(>?)127, subtract 256.
Posts: 170
Joined: Thu Feb 16, 2012 11:29 am
Location: Slovenia
by Peter247 » Mon Jan 14, 2013 10:32 pm
I problem is easier than I thought , it says for negative values add 1 , which if Hi_byte was in a byte form would just make it overflow and return back to zero.
For the Hi_byte is really in a integer I just masked anything out of the byte range,
Not sure if I need to mask out the last bit yet , because it`s not got below zero yet.
http://www.peter224722.blogspot.co.uk/
Posts: 55
Joined: Wed Nov 21, 2012 12:29 am
by sharix » Tue Jan 15, 2013 10:40 am
you can test with some ice/frozen food from the fridge
Posts: 170
Joined: Thu Feb 16, 2012 11:29 am
Location: Slovenia
by Peter247 » Tue Jan 15, 2013 2:46 pm
Easy said than done , dragging all the stuff downstairs to test it out.
It would be easier to move the freezer upstairs !!!!!
http://www.peter224722.blogspot.co.uk/
Posts: 55
Joined: Wed Nov 21, 2012 12:29 am
by jamesh » Tue Jan 15, 2013 2:55 pm
Peter247 wrote:Easy said than done , dragging all the stuff downstairs to test it out.
It would be easier to move the freezer upstairs !!!!!


Presumably the freezer has some sort of opening on the front, from which you can extract frozen items (e.g. peas); these can then be transported upstairs, and here's the important bit, without taking the freezer itself.
Unemployed software engineer currently specialising in camera drivers and frameworks, but can put mind to most embedded tasks. Got a job in N.Cambridge or surroundings? I'm interested!
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11745
Joined: Sat Jul 30, 2011 7:41 pm
by Peter247 » Wed Jan 16, 2013 11:19 am
We had a big freeze last night ,so had a chance to check my code , and found I was totally wrong how to deal with minus temperatures , this is due to my translation of the your pdf document.
http://www.peter224722.blogspot.co.uk/
Posts: 55
Joined: Wed Nov 21, 2012 12:29 am
by sharix » Wed Jan 16, 2013 9:16 pm
jamesh wrote:
Peter247 wrote:Easy said than done , dragging all the stuff downstairs to test it out.
It would be easier to move the freezer upstairs !!!!!


Presumably the freezer has some sort of opening on the front, from which you can extract frozen items (e.g. peas); these can then be transported upstairs, and here's the important bit, without taking the freezer itself.

:lol:
Posts: 170
Joined: Thu Feb 16, 2012 11:29 am
Location: Slovenia
by Peter247 » Thu Jan 17, 2013 11:47 am
Nop , a big freeze is a big freeze , it`s -4.5 c outside and takes half a hour to get my car out each day .
So the snow is still there since Sunday night , and because it is not going above freezing will be that way until the sun starts shines again , welcome to the north of England.
http://www.peter224722.blogspot.co.uk/
Posts: 55
Joined: Wed Nov 21, 2012 12:29 am