LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

TMP-102 Temperature Sensor (i2C)

I wanted to get some input from anyone about this layout for my TMP102.

I finally got my TMP102 working, yay!   To get this to work, i mulled over the Arduino "Processing" code to get the math to convert Celcius to Fahrenheit.. My only hiccup so far is the temperature readout. I've got it printing to a chart and a gauge, and the temps are not very "detailed" they are only showing up with these exact numbers:

77.0

78.8

80.6

82.4

84.2

So if i put my hand over the TMP102 and make it hotter, it jumps from 77, to 78.8 to 80.6 respectively and shows no numbers in between.  My chart readout looks like a square wave, not a sine wave if you know what i mean...  I'm not sure why its doing that.  I was hoping to get precise measurements down to the .00.

By looking at my layout does anyone see anything wrong with it so far?

https://decibel.ni.com/content/servlet/JiveServlet/download/24235-31008/TMP102-LABVIEW.jpg

0 Kudos
Message 1 of 8
(8,373 Views)

On page 6 of the TMP102 datasheet it shows that there are 2 bytes containing 12 bits representing the temperature.  I suspect that somehow you are not reading or using the least significant 4 bits which represent the fraction of a degree Celsius.  You should be able to get down to a 0.0625 degree Celsius resolution.  You must use the fractional portion as well to come up with the correct floating point numbers to feed into your "multiply by 9" function.  Then you should get accurate results.



0 Kudos
Message 2 of 8
(4,313 Views)

Thanks for the reply, i should  say i'm completely new to electronics and my background in anything related to LabVIEW is using Modular Synthszizers for music production, like Reaktor or KYMA.. so most responses i have to do alot of googling to understand where you guys are coming from   

I cant figure out how to get the 2 bytes/12 bits to work.   There is a wire on the i2c read module called "bytes to read" so i figured that is where you tell it to read the "2 bytes" to get back the 12 bit temperature so i wired up a numeric constant and called it "2".  That got it spitting out the Celcius temps but not very "precise" I  don't see anywhere in the 3 "i2c" modules available in the LabVIEW Interface for Arduino where you can tell it to receive 12 bits or anything like that. 

Maybe i need to alter the Firmware that is uploaded to the Arduino?  I noticed in another thread someone had to do that to get a 1 wire temperature device working.

0 Kudos
Message 3 of 8
(4,313 Views)

Ambient_Temp,

I'll give you a breakdown of what the I2C commands in LabVIEW do:

Init - Sets the Arduino pins to the proper state for I2C communication and causes the Arduino to join the I2C bus as a master device.

I2C Write - Sends the address of the device you want to talk to out on the bus (at this point that device starts listening the rest ignore the following commands).  Then sends the data bytes to be sent to the slave device.  The data bytes can be anything from configuration values to requests for information.  If you send a request packet you are requesting data from the device.  With your temperature sensors (I'm guessing) you send a request temp command that should return 2 bytes.

I2C Read - For the master to read data from the slave the master must let the slave know it is ready to listen.  I2C Read.vi sends the 'ready to read' command from the Arduino so that the slave knows it is safe to go ahead and output its data.  The slave then transfers out the data which is buffered by the arduino before being returned to LabVIEW.  There is a 100 mS timeout build into the I2C read firmware.  This is to prevent the code from locking up if the user tries to read from an address that does not exist.

The read VI should return a byte array.  The length of the array should match the 'Bytes To Read' input of the I2C Read VI.

Now that I look at the code you posted I have an idea of what is going on.

The I2C read VI is returning an array of bytes.  When you multiply this by 9 it multiplies each element in the array by 9.  Then you divide by 5 which will divide each element in the array by five.  The same for + 32.  Finally you index the array wich give you the first byte *9 / 5 +32.

What you really want to do is something like the code below, where you take the two bytes returned by the I2C Read VI and build them back into a single number, then do your conversion. 

SP32-156.png

I think this should solve your problem.   Let me know if you have any questions about how / why this works.  The main problem was that you were multiplying the array of bytes rather than building them back into a single number to work with...its an honest mistake if you are new to this type of thing.

Let us know if this helps.

-Sam

LIFA Developer

0 Kudos
Message 4 of 8
(4,313 Views)

Awesome, that helps put it into perspective for me thank you.  The image did not load though, maybe you can relink it?   I see i was not including the i2c write which i will now add to the vi.  I look forward to getting this working properly and share the info.

0 Kudos
Message 5 of 8
(4,313 Views)

Ambient_Temp,

That was weird.  The image wasn't broken for me until this morning.   Oh well I've re-uploaded it.  Let me know if it still doesn't show correctly for you.

-Sam

LIFA Developer

0 Kudos
Message 6 of 8
(4,313 Views)

Ok, i've figured out what i need to do in order to get the proper temperature readings.  I was confused on the bit math so now i'm trying to get it done in LabVIEW as opposed to "Processing Language"

This is the processing code of what i'm trying to do in LabVIEW

 int TemperatureSum = ((MSB << 8) | LSB) >> 4; //it's a 12bit int, using two's compliment for negative  float celsius = TemperatureSum*0.0625; float fahrenheit = (TemperatureSum*0.1125) + 32; 

The TMP-102 spits out 2 bytes of 8 bits.   I need to combine to the 2 bytes by putting them next to each other to create a 16 bit number, then i need to remove the first 4 bits leaving me with a 12 bit number that can then be translated into the proper temperature.   So i'm trying to figure out which module i'd use to put the (2) 8 bit numbers next to each other to create a 16 bit number, then how to remove the first 4 bits so i have  12 bit number.

0 Kudos
Message 7 of 8
(4,313 Views)

Ambient_Temp,

  Check this discussion forum out: http://forums.ni.com/t5/LabVIEW/How-can-you-split-a-byte-in-8-bits/m-p/264682?requireLogin=False

Essentially we will change the bytes into arrays of booleans, then do our array manipulation from there.

-Ben

Ben J.
National Instruments
Applications Engineer
0 Kudos
Message 8 of 8
(4,313 Views)