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.
tmp102
27 posts
Page 1 of 2 1, 2
- Posts: 100
- Joined: Thu Feb 16, 2012 11:29 am
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
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: 100
- Joined: Thu Feb 16, 2012 11:29 am
Alright, I fixed it by connecting ADD0 to GND (previously unconnected).
- Posts: 100
- Joined: Thu Feb 16, 2012 11:29 am
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
- Posts: 39
- Joined: Sat Aug 18, 2012 2:52 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
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
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
- Posts: 39
- Joined: Sat Aug 18, 2012 2:52 pm
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: 29
- Joined: Sat Sep 08, 2012 12:16 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
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: 9
- Joined: Sun Dec 23, 2012 9:44 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: 54
- Joined: Wed Nov 21, 2012 12:29 am
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: 29
- Joined: Sat Sep 08, 2012 12:16 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
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: 9
- Joined: Sun Dec 23, 2012 9: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.
I`m using python2 & 3 with both quick2wire and smbus libraries to monitor it.
http://www.peter224722.blogspot.co.uk/
- Posts: 54
- Joined: Wed Nov 21, 2012 12:29 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: 100
- Joined: Thu Feb 16, 2012 11:29 am
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.
- Posts: 2
- Joined: Wed May 23, 2012 3:34 pm
- Location: Munich, Germany
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
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
- 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: 54
- Joined: Wed Nov 21, 2012 12:29 am
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/
- Posts: 54
- Joined: Wed Nov 21, 2012 12:29 am
for temperatures ≥(>?)127, subtract 256.
- Posts: 100
- Joined: Thu Feb 16, 2012 11:29 am
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/
- Posts: 54
- Joined: Wed Nov 21, 2012 12:29 am
you can test with some ice/frozen food from the fridge
- Posts: 100
- Joined: Thu Feb 16, 2012 11:29 am
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/
- Posts: 54
- Joined: Wed Nov 21, 2012 12:29 am
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.
- Moderator
- Posts: 6385
- Joined: Sat Jul 30, 2011 7:41 pm
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: 54
- Joined: Wed Nov 21, 2012 12:29 am
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.
- Posts: 100
- Joined: Thu Feb 16, 2012 11:29 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.
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: 54
- Joined: Wed Nov 21, 2012 12:29 am