Thermistors and the Spark Core

He mentioned a thermapen, which is supposed to be very good. I agree, take resistance measurements from 0 to 100 C and try generating your constants again.

If that doesn’t sound like fun, just subtract 24 degrees from your reading :stuck_out_tongue:

@BDub I am beyond excited that you are inspired…i am more of a culinary hacker than an electrical engineer, so getting others working on a similar project only makes it more amazing.

Here is a video as to why I think my constants are OK ( i used the defaults from heatermeter)

The blue box is a heatermeter. Here is the schematic

As you can see in the video, the Thermapen and Heatermeter are pretty close in temp.
But at the same time Spark reads:

Analog Reading:3760
Resistance:235701.49
Temperature:69

and yes, @amanfredi i am pretty close to just hardcoding a -24 :smile:

In your video setup, what happens if you swap the probes that are plugged into the spark and heatermeter? You could also try measuring the resistance of both probes in the ice bath with your multimeter, both with and without the jack attached.

My guess is there is some non-trivial resistance added to the probe the way it is hooked up to the spark core.

The two probes show the same resistance in the water (with and without the jack attached)

I think you are right about their being added resistance the way its hooked up to the spark.

How else could I be wiring this up?

Assuming you trust the Heatmeter, you’ll find this very interesting!

I just spent about 20 minutes looking through their code… OMG that all fits on Arduino??

Anyhoo, check out how they calculate the resistance and temperature:

And the constants are slightly different than the ones you have:

My best guess at how these match up!

Steinhart[0] = 2.4723753e-4; // A
Steinhart[1] = 2.3402251e-4; // B
Steinhart[2] = 1.3879768e-7; // C
Steinhart[3] = 1.0e+4; // The fixed resistor, 10k ohms (SUBSTITUTE YOURS IN AS 20.8e+3)

FINGERS CROSSED!!! :smiley:

EDIT: I guess it’s the same equation, but with those slightly different constants and your reported resistances, they still don’t make any sense to me.

I am far from an electronics expert, but I had (have) a similar issue getting a platinum RTD probe registering accurate temperatures with an Arduino, just weeks before getting my spark core.

Additional resistance could be coming from the connections between arduino/breadboard/jumper wires.

When you measured the same resistance in both probes, what was the value, and what did the arduino calculate as the resistance?

ya, its funny, i keep switching between the heatermeter equations and the ones I have, but to no avail.
so i guess the equations are the same. here is the nutty part.

i pulled the constants from the heatermeter UI, but there it is in the arduino code, looking totally different.

with the constants from the UI
Analog Reading:3607
Resistance:155219.26
Temperature:89

with the constants from the source code
Analog Reading:3607
Resistance:153740.98
Temperature:89

OK. My new theory is that this is a 5V vs 3.3V issue.
I pulled out a Arduino Nano (it seems so “useless” next to the spark), and I confirmed that my code works perfectly when the transistor is thrown into the 5V pin.
Analog Reading:972
Resistance:186923.17
Temperature:79

When I connect to the 3.3v pin, the temps come out whacky like this:
Analog Reading:691
Resistance:20750.75
Temperature:204

It seems bizarre to me that the constants would somehow be effect by the voltage, but this is where my electrical engineering ignorance comes in…
any thoughts?

Ok I have some good news for a change!

Tonight I set off to characterize my temp probe from my wireless grill thermometer mentioned above.

I made a few resistance measurements and compared to my type-K Simpson thermocouple:
Imgur

18.3C - 215.5k (room temp)
-1.2C - 653k
0C    - 625k (ice water)
1.1C  - 596k
97.1C - 10.5k (boiling water)

Then I set off in Excel to solve the linear simultaneous equations… not too bad:

Some tests in excel with different resistances and rooms temps looked great! The equation and constants were as good as I’ve ever seen. Download the excel 2007 spreadsheet here.

Then I put your program into my :spark: Core with a little tweaking for my constants. And I also used a 10k 5% pull up resistor which measured 9900 ohms.

I got all that running on the Core, but had some bad readings!

First of all, my readings were supposed to be 3930 and were coming in low at about 3600. This makes a BIG deal when dealing with a 3rd order equation. The readings were -62C and should have been about +20C.

So I went to the Arduino IDE and busted out the same code on the Arduino, with a tweak for the ADC resolution, and it was giving me the right readings, but the temps were even worse! -148C.

I knew I had two problems: 1) ADC readings on spark are known to be flaky, and 2) I know the equation is messing up in the code somehow.

After much screwing around, I broke out all of the equations and figured out how to print 10 decimal places, to check the math at various stages. Turns out… the R = Log(R); was the problem! Looking up the arduino math.h library, I saw that log(x) was actually the Natural Logarithm of x, and what I really wanted was log10(x) logarithm of x to base 10! You’ll see, if you look at thermistor equations on enough forums and wikipedia, you can tell that some use Ln® and some use Log®. Well typically Log® is base 10, but you’ll also know that whichever type of Log/Ln you used to SOLVE for your A,B,C constants, is the same Log/Ln you have to use to solve for your Temperature!

Once I made this change the Arduino was cranking out temps within 0-2C, good enough for a Meat Probe for sure!

Then I came back to the Spark Core :spark: and knew what I had to do to fix my Logginess… and had a plan for the ADC issue as well. There are doubts about the validity of this fix, but I added a 0.1uF ceramic capacitor from the A3 input to the GND rail of my breadboard… which was connected over the top of the spark to the GND on the digital side. Despite how messed up that in itself is… IT WORKED!!! I was getting readings within 0-2C on the Spark Core as well!

I had some other issues with the Serial1 not sending me everything that I was trying to send, so I tried a bunch of different baud rates to no avail… what seemed to fix it was just adding a 1 second delay in four places after various bursts of calculations. It might have something to do with the floating point math… I’m not really sure but it’s late and I wanted to share this with you as soon as I could.

Here’s my Arduino Sketch:

#include <math.h>

void setup()
{
    Serial.begin(115200);
}

void loop()
{
    thermister_temp(analogRead(A3));
    delay(1000);
}

void thermister_temp(int aval)
{
  double R, T;

  Serial.print("Analog Reading:");
  Serial.println(aval);

  R = (double)(1 / ((1023 / (double) aval) - 1)) * 9900.0;
  Serial.print("Resistance:");
  Serial.println(R,2);

  R = (double)log10(R);
  Serial.print("LOG10(R): ");
  Serial.println(R,10);
  
  T = (0.00000220911 * R * R * R);
  Serial.print("(0.00000220911 * R * R * R): ");
  Serial.println(T,10);
  
  T = (0.000702421 * R);
  Serial.print("(0.000702421 * R): ");
  Serial.println(T,10);
  
  T = ((((0.00000220911 * R * R) + 0.000702421) * R) + 0.0000199476);
  Serial.print("((((-0.00000220911 * R * R) + 0.000702421) * R) + 0.0000199476): ");
  Serial.println(T,10);
  
  // Compute degrees K
  T = 1 / ((((-0.00000220911 * R * R) + 0.000702421) * R) + 0.0000199476);
  
  Serial.print("Temperature (K): ");
  Serial.println(T);
  Serial.print("Temperature (C): ");
  Serial.println(T - 273.15);
  Serial.print("Temperature (F): ");
  Serial.println((((T - 273.15) * 9.0) / 5.0 + 32.0));
} 

And here’s my Spark Core program:

#include <math.h>

void setup()
{
    Serial.begin(115200);
}

void loop()
{
    thermister_temp(analogRead(A3));
}

void thermister_temp(int aval)
{
  double R, T;

  Serial.print("Analog Reading:");
  Serial.println(aval);

  R = (double)(1 / ((4095 / (double) aval) - 1)) * 9900.0;
  Serial.print("Resistance:");
  Serial.println(R,2);

  R = (double)log10(R);
  Serial.print("LOG10(R): ");
  Serial.println(R,10);
  delay(1000);
  
  T = (0.00000220911 * R * R * R);
  Serial.print("(0.00000220911 * R * R * R): ");
  Serial.println(T,10);
  
  T = (0.000702421 * R);
  Serial.print("(0.000702421 * R): ");
  Serial.println(T,10);
  delay(1000);
  
  T = ((((0.00000220911 * R * R) + 0.000702421) * R) + 0.0000199476);
  Serial.print("((((-0.00000220911 * R * R) + 0.000702421) * R) + 0.0000199476): ");
  Serial.println(T,10);
  
  // Compute degrees K
  T = 1 / ((((-0.00000220911 * R * R) + 0.000702421) * R) + 0.0000199476);
  delay(1000);
  
  Serial.print("Temperature (K): ");
  Serial.println(T);
  Serial.print("Temperature (C): ");
  Serial.println(T - 273.15);
  Serial.print("Temperature (F): ");
  Serial.println((((T - 273.15) * 9.0) / 5.0 + 32.0));
  delay(1000);
}

@avidan Thanks for the push to work on this!! :smile: I was following your progress and really wanted to try my hand at it… I hope these things help you get it solved!

4 Likes

OMG! You are my freakin hero!

Can i buy you a :beer:? or a :spark:? No seriously, if there was a way to gift a :spark:

@zach I have a request. spark gifting.

I have to wake up early for a flight, but i think im going to trade in sleep to at least give this a try.

2 Likes

just out of curiosity, any idea why that helps?

@avidan you’re welcome! Get yours working we can have those :beers: Have a look at this thread for a bunch of theories on why the 0.1uF cap helps. I’m going to add a new one in second here :wink:

2 Likes

Hey man, in the post above you say…

“Have a look at this thread for a bunch of theories on why the 0.1uF cap helps. I’m going to add a new one in second here”

But there are no links :frowning:

Ken

:smile:

1 Like

:: smacks forehead ::

Thanks!

Ken

1 Like

BDub, I just want to say that I’m a huge fan of your annotated images.

2 Likes

:wink: Thanks I love having the power to do them so easily with an Imgur.com account and the best screen capture software I have found in a long time using everything since SnagIt. It’s called ShareX http://getsharex.com/ Make sure you go through ALL of the settings and options to see what power it has.

1 Like

@BDub - I’m a total snagit whore. Seriously, I love sending screenshots.

2 Likes

@avidan, did you ever get your project working as you wanted?

I’m also mostly a culinary hack… a heater meter 4 sitting here alongside my homemade sous vide and spark core wifi temperature probe.

1 Like