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.
Re: tmp102
Ok I got it to work with this script:
But it sometimes (not always) fails with a read error. How to fix this?
example outputs:
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
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
Re: tmp102
Alright, I fixed it by connecting ADD0 to GND (previously unconnected).
Re: tmp102
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
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
Re: tmp102
I have created a detailed tutorial on using the TMP102 with the Raspberry Pi here:
http://donalmorrissey.blogspot.co.uk/20 ... orial.html
Any comments on how to improve it would be great.
Cheers,
Donal
http://donalmorrissey.blogspot.co.uk/20 ... orial.html
Any comments on how to improve it would be great.
Cheers,
Donal
Re: tmp102
donster2k wrote:I have created a detailed tutorial on using the TMP102 with the Raspberry Pi here:
http://donalmorrissey.blogspot.co.uk/20 ... orial.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: 55
- Joined: Sat Sep 08, 2012 12:16 pm
Re: tmp102
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
Thanks for the tutorial.
Steven
-
- Posts: 129
- Joined: Sun Dec 23, 2012 9:44 pm
Re: tmp102
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
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
Re: tmp102
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: Sat Sep 08, 2012 12:16 pm
Re: tmp102
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.
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: 129
- Joined: Sun Dec 23, 2012 9:44 pm
Re: tmp102
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
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
Re: tmp102
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.
I`m using python2 & 3 with both quick2wire and smbus libraries to monitor it.
http://www.peter224722.blogspot.co.uk/
Re: tmp102
The address changes according to which pin you connect with the ADD pin on the sensor.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
-
- Posts: 2
- Joined: Wed May 23, 2012 3:34 pm
- Location: Munich, Germany
Re: tmp102
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 0100 1001 -> 49 -> V+ See attached images for address 48, 49 and connection to the Raspberry Pi.
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 0100 1001 -> 49 -> V+ See attached images for address 48, 49 and connection to the Raspberry Pi.
Re: tmp102
I want to read out the TMP102 with Python
This is my code:
If i change line 4 with:
I get the temp in hex format. How do i convert this hex format in 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
Code: Select all
temp1 = hex(bus.read_word_data(address,0x00))
Re: tmp102
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
I`m waiting until a minus temp to check my code.
http://www.peter224722.blogspot.co.uk/
Re: tmp102
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
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/
Re: tmp102
for temperatures ≥(>?)127, subtract 256.
Re: tmp102
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.
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/
Re: tmp102
you can test with some ice/frozen food from the fridge
Re: tmp102
Easy said than done , dragging all the stuff downstairs to test it out.
It would be easier to move the freezer upstairs !!!!!
It would be easier to move the freezer upstairs !!!!!
http://www.peter224722.blogspot.co.uk/
Re: tmp102
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.Peter247 wrote:Easy said than done , dragging all the stuff downstairs to test it out.
It would be easier to move the freezer upstairs !!!!!
Principal Software Engineer at Raspberry Pi Ltd.
Working in the Applications Team.
Working in the Applications Team.
Re: tmp102
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/
Re: tmp102
jamesh wrote: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.Peter247 wrote:Easy said than done , dragging all the stuff downstairs to test it out.
It would be easier to move the freezer upstairs !!!!!

Re: tmp102
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.
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/