Sensor compatibilty


#1

Hi,

i’ve just purchased a High Temperature Sensor ( http://www.seeedstudio.com/depot/Grove-High-Temperature-Sensor-p-1810.html ) and I would like to know if it is compatible with the GrovePi. It doesn’t work, I think I do something wrong :smiley:

When I plug it on a I2C port, a ‘sudo i2cdetect -y 1’ does nothing but in a digital or analog port, the GrovePi is detected. I’ve not found any example code with this model.

Thanks for your help and sorry for my english :slight_smile:


#2

Hey Bearfr,
Just to reconfirm, when you run sudo ‘i2cdetect -y 1’ you do see the GrovePi, correct?

It looks like this is an I2C sensor and if it was working, it would show up on the scan (http://www.seeedstudio.com/wiki/Grove_-_High_Temperature_Sensor). You might need to return your High Temp Sensor to Seeed. Sorry about that!


#3

Thanks for your answer.

When I plug the sensor on a I2C port, I haven’t anything prompted ( with the command i2cdetect ), only if I unplug it, I see the GrovePi (I have 04)

Is there a way to monitor the port like in Arduino (the link you’ve posted ?).


#4

A member of seeedstudio answers me that this sensor is not for I2C but for an analogic port (so A0 or A1 for example).

So I’ve tried the script ‘grove_analog_read.py’ and I have some values … 376 or 377. (with and unpluged port, I have 72/73).

With the sheet for thermocouple, how can I convert the temperature ? (the doc for the arduino script is not very easy …)

Of course, if the data of 376/377 is right. I haven’t any clue to tell if it is right or not …

Thanks again and again :slight_smile:


#5

Hey bearfr,
The sensor is not an I2C sensor and by plugging it to the I2C ports, you might have been disabling communication between the GrovePi and the Raspberry Pi.

The sensor is indeed connected to an Analog port and it gives out analog values. Right now we don;t have a python example for this sensor but it should be pretty easy to write it and get it to work. Basically, you’ll have to port this library: https://github.com/Seeed-Studio/Grove_HighTemp_Sensor/blob/master/Hight_Temp.cpp to get it to work with Python.

In this example: https://github.com/Seeed-Studio/Grove_HighTemp_Sensor/blob/master/examples/getTemperature/getTemperature.ino , the call to read the temperature is : ht.getThmc(). To read the temperature, you just run these three lines: https://github.com/Seeed-Studio/Grove_HighTemp_Sensor/blob/master/Hight_Temp.cpp#L92-L94, i.e., you read the analog port 32 times and find the mean of the values. Then you find the resistance and then you convert the resistance to temperature.

Let us know if you are able to get the sensor to work.

-Karan


#6

Hi,

thanks for your help Karan & John.

I’m not familiar with thermocouple and high math formula so it has to be improved …

import time
import grovepi
import math

#Sensor connected to A0 Port
sensor = 1
grove_vcc = 5

grovepi.pinMode(sensor,"INPUT")
while True:
    try:
        sensor_value = grovepi.analogRead(sensor)

        # Calculate voltage
        voltage = round( (float)(sensor_value) * grove_vcc / 1024,4)

        print "sensor_value =", sensor_value, " voltage =", voltage
        time.sleep(.5)
    except IOError:
        print ("Error")

If my code is good, the value returned is around 1.92. Perhaps you have an idea or a couple of lines of code to convert the voltage to temperature ?

I’ve studied this doc : http://srdata.nist.gov/its90/download/type_k.tab and this is not the same value as the sheet : http://www.seeedstudio.com/wiki/Grove_-_High_Temperature_Sensor

If you have an idea … :slight_smile:

Thanks you again.


#7

There was a mistake in the comment, I’ve tested the A0 and A1 port and I have the same values, so I think it’s the good ones.

sensor_value = 70 voltage = 0.3418

In the table http://srdata.nist.gov/its90/download/type_k.tab, which column should I read ? I don’t understand, at all :smiley:

Thanks :slight_smile:

EDIT : I think my error is on the voltage. I think I understand how read the table (in fact, my two links above are the same :D). Is the sensor is really 5V ? My code is right ? :slight_smile:


#8

Hey,
Can you try using these 3 lines: https://github.com/Seeed-Studio/Grove_HighTemp_Sensor/blob/master/Hight_Temp.cpp#L92-L94 . “a” is the voltage, then you calculate the resistance and with the resistance, you calculate the temperature. The voltage code does look a bit weird for the sensor, but it might be worth trying it.

-Karan


#9

Hum, I think I’ve reached my tech limits :smiley:

Here’s my code and the output. In fact, I live in south of France, there is 32°C this afternoon, so I think the values are not good :slight_smile:

import time
import grovepi
import math

#Sensor connected to A0 Port
sensor = 0
grove_vcc = 5

grovepi.pinMode(sensor,"INPUT")
while True:
    try:
        sensor_value = grovepi.analogRead(sensor)

        voltage = round( (float)(sensor_value) * grove_vcc / 1023,4)
        resistance = (float)(1023-voltage)*10000/voltage;
        temperature = 1/(math.log(resistance/10000)/3975+1/298.15)-273.15;

        print "sensor_value =", sensor_value, " voltage =", voltage, "resistance =", resistance, " temperature =", temperature
        time.sleep(.5)
    except IOError:
        print ("Error")

pi@raspberrypi ~/GrovePi/Software/Python $ sudo ./temp.py
sensor_value = 69  voltage = 0.3372 resistance = 30328078.2918  temperature = -86.9626164307
sensor_value = 70  voltage = 0.3421 resistance = 29893536.9775  temperature = -86.8366736603
sensor_value = 70  voltage = 0.3421 resistance = 29893536.9775  temperature = -86.8366736603
sensor_value = 70  voltage = 0.3421 resistance = 29893536.9775  temperature = -86.8366736603

I’ve no idea.

EDIT : yesterday, I had the same values in the morning (18-20°C). Mayble the problem doesn’t come with the code.


#10

Hey,
Looking deeper into the code and schematics of the High temp sensor, it looks like the information that I had given you earlier was wrong and we need to read the data from 2 analog sensors and then call getThmc() function https://github.com/Seeed-Studio/Grove_HighTemp_Sensor/blob/master/Hight_Temp.cpp#L67.

I am trying to dry run right now so it would be great if you could post what analogRead(0) and analogRead(1) show when the sensor is connected to Port A0

-Karan


#11

Yeah :slight_smile:

pi@raspberrypi ~/GrovePi/Software/Python $ sudo ./temp.py
analog0 = 69 analog1 = 386
analog0 = 69 analog1 = 386
analog0 = 69 analog1 = 386


#12

Hey,
I pretty much ended up porting the whole code to Python and tried running it with the input that you gave. I am getting the output as 25.6.

Can you add the GrovePi library to it and replace inp0 by analogRead(0) and inp1 by analogRead(1) and run the code to see if it works for you.

import math
import time

VOL_OFFSET = 350.0                   
AMP_AV     = 54.16                  

def getThmc(i0,i1):
	tempRoom   = getRoomTmp(i0)
	vol  = getThmcVol(i1)
	tempThmc = K_VtoT(vol) + tempRoom

	return tempThmc;

def getRoomTmp(aread):
    a = aread*50.0/33;                                
    resistance=(float)(1023-a)*10000/a;                           
    temperature=1/(math.log(resistance/10000)/3975+1/298.15)-273.15;   
    return temperature;

def getThmcVol(aread):                                             
    vout = aread/1023.0*5.0*1000
    vin  = (vout - VOL_OFFSET)/AMP_AV
    return (vin)   

def K_VtoT( mV):
	i = 0
	value = 0

	if(mV >= -6.478 and mV < 0):
		Var_VtoT_K=[0, 2.5173462e1, -1.1662878, -1.0833638, -8.9773540/1e1, -3.7342377/1e1,-8.6632643/1e2, -1.0450598/1e2, -5.1920577/1e4]
		value = Var_VtoT_K[8]
		for i in range(8,0,-1):
			value = mV * value + Var_VtoT_K[i-1]
    
	elif(mV >= 0 and mV < 20.644):
		Var_VtoT_K=[0, 2.508355e1, 7.860106/1e2, -2.503131/1e1, 8.315270/1e2,-1.228034/1e2, 9.804036/1e4, -4.413030/1e5, 1.057734/1e6, -1.052755/1e8]
		value = Var_VtoT_K[9]
		for i in range(9,0,-1):
			value = mV * value + Var_VtoT_K[i-1]
        
    
	elif(mV >= 20.644 and mV <= 54.900):  
		Var_VtoT_K=[-1.318058e2, 4.830222e1, -1.646031, 5.464731/1e2, -9.650715/1e4,8.802193/1e6, -3.110810/1e8]
		value = Var_VtoT_K[6]
		for i in range(6,0,-1):
			value = mV * value + Var_VtoT_K[i-1]
    
	return value

while True:
	inp0=69
	inp1=386

	print getThmc(inp1,inp0)
	time.sleep(1)

Do let me know how it goes.

-Karan


#13

If the formatting is broken, try the attached file.

-Karan


#14

Really, really awesome !

I’ve 25°C. I will try to find a real thermoter to compare but I think it’s pretty realistic values.

A big, big thanks to you, you’re welcome in France when you want :wink:


#15

Glad to hear that it worked.

It would be great if you could test this a bit and if it really works well, can you clean up the code a bit and send a pull request to the GrovePi repository here: github.com/DexterInd/GrovePi or just upload the code on the forums so that others can use it in the future.

-Karan


#16

No problem. I’m not familiar with github, but I will try this week-end.

Thanks again.


#17

Hey,
We have a guide here: http://www.dexterindustries.com/howto/raspberry-pi-tutorials/contribute-code-dexter-industries-projects/ on how to contribute code to our projects or any open source project.

Do let us know if you face any problems or if you don;t want to go down that path, just attach the code here and I’ll add it to the repository.

-Karab