Problem with reading Thermistor

On Arduino I have the following (working) code:

#include <math.h>
void setup()
{
Serial.begin(115200);
}

void loop()
{
int AnalogValue = analogRead(0);

Serial.print(AnalogValue);
Serial.print(" = ");
Serial.println(Thermistor(AnalogValue)); // display Fahrenheit Serial.println("c");
delay(200); 

}

double Thermistor(int RawADC)
{
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15; // Convert Kelvin to Celcius
return Temp;
}

In TinyCLR, using the same thermistor, I needed to perform the following:

private static UartController DebugPort = null;

static void Main()
{
var adc = AdcController.FromName(SC20100.AdcChannel.Controller1.Id);
var analog = adc.OpenChannel(SC20100.AdcChannel.Controller1.PA0);
int AnalogValue = 0;

ConfigDebugPort();

while (true)
{
    AnalogValue = analog.ReadValue();

    AnalogValue = (int)((double)AnalogValue / 88.5);

    DebugWrite(AnalogValue.ToString());
    DebugWrite(" = ");
    DebugWrite(Thermistor(AnalogValue) + "\r\n");

    Thread.Sleep(200);
    
}

}

private static double Thermistor(int RawADC)
{
double Temp;
Temp = Math.Log((((double)10240000 / (double)RawADC) - (double)10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp)) * Temp);
Temp = Temp - 273.15; // Convert Kelvin to Celcius
return Temp;
}

The problem is the use of the 88.5 value. Why do I need to divide the returned value by this arbitrary value to get the same result as with the Arduino?

Resolution of the adc?
5v vs 3.3v?

you say there’s a “problem” with dividing by a constant. But the whole thing is just one big calculation using constants, so not sure why you think that’s a “problem”? As Gus said it could be as simple as the ADC differences (although I would have thought that would have been an .666666 problem). And differences in platform don’t really equate to a “problem”, just a difference.

The problem is that through trial and error, I worked out that I needed to divide the raw reading by 88.5 to get the same result as the Arduino. This to me feels like a hack and I want to know if I’ve just got something wrong.

Yes it’s 5v vs 3.3 and probably different ADC resolution. I was hopeful that someone had done this before and had some hints.

1 Like

there are some of things you could consider for differences

5 vs 3.3
1024 (10 Bit) vs 4096(12 bit)
speed of mcu

1 Like

You should read ratio instead of raw value. This way your coffee will work on any system. If you need the voltage then multiply by 3.3

Is this a tease about a new GHI product? Will decaf be available?

1 Like

Lol. It is a special kind!! It should say code

so the simplest answer is, show us your datasheet.