Thermistors and the Spark Core

How well does it ship? Bacon be damned! That is the most delicious image I have ever seen on the Internet.

2 Likes

cool @avidan !

Looks like my pastrami, and I do it almost exactly the same way. What temp are you running @48?

I also do quite a bit of pulled pork, smoked 6@65C, then about 40hrs at 65.

1 Like

64c for the sous vide. i gotta try the smoked pulled pork that way. usually the shoulders are too big for my chamber vac.
i love me some geeky cooking.

and yes, the pastrami ships wellā€¦if it makes it to the post office.

1 Like

First time poster. Had my Spark Core about 2 weeks. Itā€™s pretty awesome.

I got a lot of input from this thread on creating the following TermisterProbe class. Its meant to be fairly generic as you can specify the pullup resistor value, uC reference voltage and probe type. I know itā€™s not real significant but I was hoping to share it on github. Since some code came from @avidan and @BDub I was wondering how to properly credit them and what license to attach to it. If no one cares on the license part I can figure that out. Just wanted to give credit where due.

Also I havenā€™t figured out constants for the ET732 yet so I have same ones specified for both probe types right now.

Example:

#include "ThermisterProbe.h"

#define PROBE1 A7

ThermisterProbe probe(21570.0, 4095);

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

void loop() {
    Serial.print("Temperature (F): ");
    Serial.println(probe.getTempF(PROBE1, ThermisterProbe::ET72));
    delay(1000);
}

ThermisterProbe.cpp:

#include "ThermisterProbe.h"
#include "application.h"
#include "math.h"

// TermisterProbe constructor
// pur - Pullup resistor value in ohms
// adcRef - ADC reference value
ThermisterProbe::ThermisterProbe(double pur, int adc)
{
    _pur = pur;
    _adc = adc;
}

// Returns the temperature in Kelvin based off of the Steinhart-Hart equation.
// http://en.wikipedia.org/wiki/Steinhart%E2%80%93Hart_equation
double ThermisterProbe::getTempK(int pin, enum ProbeType probeType)
{
    // Read in analog value
    int aval = analogRead(pin);
    
    _probeType = probeType;
    
    // select probe specific constants
    switch (_probeType) {
        case ET72:
            // ET-7, ET-72, ET-73, ET-72/73 probe constants
            A = -2.20911E-06;
            B = 7.02421E-04;
            C = 1.99476E-05;
            break;
        case ET732: default:
            // ET-732 probe constants
            A = -2.20911E-06;
            B = 7.02421E-04;
            C = 1.99476E-05;
            break;
    }

    // calculate resistance; log() is natural log here
    double R = log((1 / ((_adc / (double) aval) - 1)) * (double)_pur);

    // calculate and return temp
    return (1 / (A + B * R + C * R * R * R));
}

// Returns temp in Celcius
double ThermisterProbe::getTempC(int pin, enum ProbeType probeType) {
    return getTempK(pin, probeType) - 273.15;
}

// Return temp in Fahrenheit
double ThermisterProbe::getTempF(int pin, enum ProbeType probeType) {
    return ((getTempC(pin, probeType) * 9.0) / 5.0 + 32.0);
}

ThermisterProbe.h:

#ifndef ThermisterProbe_h
#define ThermisterProbe_h

#include "application.h"

class ThermisterProbe
{
    public:
        enum ProbeType{ET72, ET732};
        ThermisterProbe(double pur, int adc);
        double getTempK(int pin, enum ProbeType probeType);
        double getTempC(int pin, enum ProbeType probeType);
        double getTempF(int pin, enum ProbeType probeType);
    private:
        double _pur, A, B, C;
        int _adc;
        enum ProbeType _probeType;
};

#endif
4 Likes

Personally, I credit usernames and forum links as comments above the relevant code blocks. If itā€™s scattered all over, I put a note at the top of the file (or files). I canā€™t comment about licensing, though. Is there a licensing wizard that can help figure out what kind of license we want to use?

Library support in the web IDE is getting pretty close. If you plan on publishing your code to GitHub, you can format it similar to my own thermistor library (go easy on me, itā€™s my first C class ever) or the uber library example. That will allow it to be easily importable when the web IDE library functionality is rolled out! @jgoggins is spearheading this project, so he may be interested as well.

1 Like

Thanks for the guidance. I put it here: https://github.com/coolnewt/ThermisterProbe

Please let me know if something doesnā€™t look right.

Itā€™s close. Youā€™ll need a spark.json file in the root directory of the repo, and in ThermisterProbeExample.cpp, change your #include "ThermisterProbe.h" to #include "ThermisterProbe/ThermisterProbe.h".

After typing that out, I just noticed a little spelling mistake. ā€œThermisterā€ should be ā€œThermistorā€ (with the ā€œorā€ at the end).

Once you get the changes above made, let me know, and Iā€™ll run it through a validator to see if everything is good!

Alright changes made. Had to rename the repo of course and decided to change my username while I was at it.

What is the validator? Any doc you can point me to? Maybe I can do this.

It looks good and validates!

It's not open to the public yet, but it will be in just a few days! I don't want to put a hard date on it because we still may break something in our testing between now and the planned go-live date.

Cool, I look forward to it. Thanks @wgbartley for all the help!

much fun watching this develop!
id love to make a small spark powered smoker controller.
who wants to join?

2 Likes

Iā€™m in, sending pm :smiley:

1 Like

Count me in! My father-in-law is an avid smoker. There's a reason I didn't want to eat any of the BBQ at Maker Faire. I get plenty at home, and I'm pretty spoiled, too.

2 Likes

I don't "smoke" but I'll help in any way I can :smile:

2 Likes

I can do the write-up if you need though iā€™m not an avid meat eater :smiley:

So much help offered, awwww so much love :smiley:

1 Like

Generally all code examples I put on the forum and most of the stuff in my github is unlicensed... I.e., completely free to steal and do whatever you want with.

I like the MIT license for it's simple terms, but it's not the best license for code in my opinion. It basically gives someone the right to do whatever they want with your code, and not have to make their changes known. The GNU GPL v3 license is better for this reason, and I think I will start to license my code with it going forward.

Check out these very simple explanations here:


1 Like

Ya, that makes sense. I found http://choosealicense.com useful. I was thinking Iā€™d attach MIT to things that were simple and/or generic and GPL to things specific to a project.

1 Like

On the surface that sounds perfect, but letā€™s say someone made a great improvement to your otherwise simple codeā€¦ they donā€™t have to share it with you or anyone else if you used the MIT license. GPLv3 would require that they share the improvement. Sharing is caring, which is the only reason I write examples in the first place. A proper license ensures that your work continues to Pay it Forward in the future.

Part of what Iā€™m coming to realize is that itā€™s also not only just about picking a proper license, but also making it super easy for people that grab your code to understand what they are required to doā€¦ in simple terms. Most people wonā€™t even bother to read the license, so one of these days Iā€™ll have to come up with a fancy header that helps explain the license in a sentence or two.

Ya, and thatā€™s exactly why I would use it. Nice to connect w/ you on here finally. Iā€™ve read a lot of your content :smile:

1 Like

Here is how to calibrate a thermistor using the log formula rather than the polynomial formula. Unlike the polynomial there are only two unknown constants so in theory you could do the calibration with only two points. What is more many thermistors come with the B value so you only need to adjust Rinf to get the correct temperature.

@Bdub has correctly pointed out that the cubic relationship is more accurate. If you calibrate the log relationship to be correct at 0C and 100C you will be 1.25C low at the mid point (for one brand of thermistor that comes with a full calibration curve). This means that if you calibrate to be correct at 20C you will be within 0.5C across pretty much the whole habitable range.