[SOLVED] Grove High Temperature sensor giving widely different, but consistent temperatures

Hi @quasipickle,

Sorry for the delay, but I think I’ll need more time to spend on this thing.
I think I got something and I’m working on it. I’ll come back ASAP.

Thank you for your patience!

Hi Robert,

Your support has been exceptional. Thanks for working on this - take all the time you need.

1 Like

We bought and installed a new GrovePi+. The sensor results are the same. Other, digital, sensors continue to work as expected.

Hi @quasipickle,

I haven’t forgot you.
The code you’re currently trying out is not going to give the expected results.
I’m working on something that I think it’s going to do the job.

I’m truly sorry for the delay and I’ll try to get back to you by the end of this week.

Thank you!

I’m curious why it wouldn’t, as I’m pulling it right from GitHub. I’m guessing you found something in the code?

I do appreciate your dedication to solving my problem. I look forward to hearing more.

Hi @quasipickle,

I’ve come back with an update on the software of this high temperature sensor.


So lets start by inserting the following command in your Raspberry Pi's terminal:
git clone -b feature/software/library/python/grove_high_temperature_sensor https://github.com/RobertLucian/GrovePi.git

Then just cd to the grove_hightemperature_sensor folder and try again the example program we’ve already been trying with so far.


So, for the last few days, the sensor worked really nice - the temperatures were on match with a classic glass thermometer I have. I’ve went up to 100 Celsius Degrees and the error stayed at +-2.5 Celsius Degrees - which I think that’s more than okay.

During this night, I’ve experimented again with the sensor, but unfortunately I think it went bad, since it started oscillating a lot. Otherwise it wouldn’t oscillate that much, right? Maybe there’s something with the on-board amplifier.


Can you measure the readings this sensor gives by taking it gradually from 0°C up to 100°C with increments of 10°C? Please measure the temperature by inserting the probe into the water - the process of finding out the temperature is going to be much faster and more reliable.


I’m curious to see what’s the error (if there’s one) the sensor gives when compared to a more professional thermometer.

Thank you!

Hi Robert,

After installing the scipy dependency, I ran some tests. I hope it doesn’t matter, but I went from hot to cold rather than cold to hot. Below are the results. The column on the left is the professional datalogger. The column on the right is the high temp sensor.

I tested multiple sensors at room temperature and got really close, so I only did the greater-temperature-range test with one sensor.

Other than the sample explicitly mentioned, all these numbers were measured in water.

The room temperature from the sensor was 22C. The datalogger read a little under 19C.

| 84  | 76                               |
| 80  | 76                               |
| 78  | 72                               |
| 77  | 70-72                            |
| 75  | 70                               |
| 74  | 73                               |
| 73  | 67                               |
| 68  | 62                               |
| 61  | 57                               |
| 54  | 50                               |
| 32  | 30                               |
| 45  | 41                               |
| 26  | 23.8                             |
| 24  | 21-24                            |
| 18  | 15-17 (measured air temperature) |
| 17  | 15-17                            |
| 7.2 | 8.7                              |

Hi @quasipickle,

I’ve been trying to perfect the configuration values for the high temperature sensor.


So, you can either git pull the changes or you can click on the following link:
github.com/DexterInd/GrovePi/tree/master/Software/Python/grove_hightemperature_sensor


Going to grove_hightemperature_sensor directory, you’re going to see 4 files:

  • high_temperature_example.py - this is our example program which we always run - you already know this, but I’m thinking for newcomers too.

  • grove_hightemperature_sensor.py - this is our library which we need to import in a Python script in order to access the high temperature sensor. This library is dependent on thermocouple_table.json file.

  • thermocouple_table.json - this is where K-Type's sensor table resides. It’s used for describing the relation between the voltage & the temperature. You can think of it as a non-linear function where the input of it is the voltage we get on the amplifier and the output is the temperature.
    Also, thermocouple_table.json is required by grove_hightemperature_sensor.py. Without it, you can’t run the program. So these files need to be in the same directory.

  • README.md - this is a tutorial for calibrating the sensor. Again, as I have specified in the tutorial, the temperature sensor is already calibrated and it’s good to go.


Now, @quasipickle, what you can do is test again with the changes I’ve brought and see if the temperature gets closer to the real value.

In my tests, I’ve seen the measured temperature being slightly lower than the real value - by 2-4 Celsius Degrees (which was measured with a professional thermometer). So I think that’s okay, considering the great range of temperatures this sensor can measure.

I’ve written this tutorial thinking that maybe you can calibrate it by yourself, provided these new updates are still not giving the satisfying answer.
Seeing that both of us have different values made me think that each sensor / batch of sensors are / is different and may need appropriate calibration.


Please keep us updated with your experiments.
I’m curious to see if this is going to solve the issue.


Thank you!

Hi Robert,

On average the new range is a little closer to reality (or at least closer to the datalogger). I haven’t done a calibration, but I will do so tomorrow. I think I’ll write a script that gets the average of 10 samples, as I’ll probably end up doing that in my final code. I’ll let you know what my amp_offset and amp_factor values end up being.

Thanks again.

Hi Robert,

I tried to calibrate and I think either your calibration formula or my math is wrong. Here are my values:

| Datalogger                | Pi                |
|------------|------|-------|----|------|-------|
|            | Temp | Table |    | Temp | Table |
|------------|------|-------|----|------|-------|
| i1         | 82.6 | 3.557 | o1 | 76.9 | 3.142 |
| i2         | 7.0  | 0.277 | o2 | 5.88 | 0.238 |

Plugging that into your formula of (i1 * o2 - i2 * o1) / (o2 - o1), I get:
(3.557 * 0.238 - 0.277 * 3.142) / (0.238 - 3.142)
= (0.846566 - 0.870334) / -2.904
= -0.023768 / -2.904
= 0.00818457...

That number is way different from the 58.359759 in the file.

Hi @quasipickle,

That’s my bad. It was a typo.

Please pull the new changes and take a look at the updated README.md.


Short note: o1 and o2 values are actually values that we read with the GrovePi with the analogRead() function.


Thank you!

Hi Robert,

I’m getting different values now, but still way off:

| Datalogger |      |       | Pi |              |
|------------|------|-------|----|--------------|
|            | Temp | Table |    | Analog value |
| i1         | 85.4 | 3.474 | o1 | 95.9         |
| i2         | 6.0  | 0.238 | o2 | 61           |

Plugging those numbers in I get an offset of -5.418045845272206 and a factor of 0.0927220630372493

I wrote a script to do the calculations for me:

#!/usr/bin/env python3

import json

hotTemp = float(input('Enter hot temperature: '))
o1 = float(input('Enter the pin value at the hot temperature: '))
coldTemp = float(input('Enter cold temperature: '))
o2 = float(input('Enter the pin value at the cold temperature: '))

hotTemp = str(round(hotTemp))
coldTemp = str(round(coldTemp))

with open('thermocouple_table.json') as table_file:
    table = json.load(table_file)

i1 = table['degrees_table'][hotTemp]
i2 = table['degrees_table'][coldTemp]

offset = (i1 * o2 - i2 * o1) / (o2 - o1)
factor = (i1 - offset) / o1

print('\nOffset: {0}\nFactor: {1}'.format(offset,factor))

Hi @quasipickle,

I noticed what the problem was.
I’ve done again the equations and it was a math error.


I’ve updated the README again and now it should be okay.
Using the values you’ve provided I got something similar with what I had calculated when I wrote the code. And there’s enough difference that would make your sensor read differently. So, please, try it out.

Here’s the link to the README - it points to my repository as the changes to DexterInd haven’t been accepted yet:


After you calibrate it, please let me know if the sensor reports different temperatures.
A table with what you get can be real handy.


Thank you!

After calibration (offset: 58.4331891, factor: 10.7849197), the temperatures are MUCH closer.

| Datalogger | Pi    |
|------------|-------|
| 8          | 8.57  |
| 27.5       | 27.92 |
| 37         | 37.92 |
| 53         | 53.71 |
| 77         | 76.96 |

I’m using a modified version of your test script that gets a 10 sample average. I’m thinking of changing that to 20. Would altitude be a contributing factor to why we need different amp_* values? I’m at 740 metres.

I see you have posted elsewhere some code for removing garbage outliers from the DHT code. Is that something that would be of use here?

And if I haven’t said it enough, thank you!

1 Like

Hi @quasipickle,

I’m so glad to hear that the sensor gives good readings.
It’s been a long journey, I can say.


Would altitude be a contributing factor to why we need different amp_* values? I’m at 740 metres

I think a better question would be : Does the altitude affect the output voltage on the board (while referring to the board and not the metal wire alone) ?
And the answer is : I’m not sure. Only by testing it at different altitudes (while keeping the exact same temperature) is going to help you find out.


I think the code for removing the garbage outliers from an array of data points can be helpful if you observe big changes in the read temperature (aka noise).

Here’s the PR to the garbage outlier remover code :

You’ll see that the only function we truly need is :

  • statisticalNoiseReduction(values, std_factor_threshold = 2) which is found in grovepi.py file.

Please let me know if there are things left unclear.

Thank you!

1 Like

Hi Robert,

I think everything is cleared up now. Thanks again for your dedication to this problem.

Do you have a timeline for when I can expect this code to be in the main grovePi repository? How will the JSON file be editable if I just run the grovePi install script that comes in the repository?

1 Like

Hi @quasipickle,

Well, the team has to review it as-well and give their approval, before accepting the pull request merge to master.


When the code is going to get approved, you’ll need to place the JSON's configs somewhere safe, otherwise they will get overwritten.

We can’t come up with definite calibration values, as each sensor is different and as you may have seen, your sensor gave not such good readings whilst mine showed the right values - and that’s because each sensor / batch of sensors need personalized calibration values.


Please let me know if we’re good to close the thread.
I think we’re done here.

If there’re any more questions, please feel free to contact us.
We’ll gladly help you.

Thank you!

If the decision is that each batch needs to be recalibrated, I suggest you put some calibration assistance code in the library so people don’t have to always write their own like I did.

Also, you’ll probably have to tweak your code a bit with a property of method that specifies where the JSON file is.

This thread is done. Thanks again.