I have an artemis redboard with a normal thermistor connected to pin A0. I have no problems reading values from the ADC with analogRead(), but when I try to convert that ADC value to a temperature my sketch ultimately hangs when calling the log() function. The sketch is pretty simple (below). I’ve tried various things in the adcToTemp() method, such as using floats vs. double, etc., but the sketch will always hang when calling log(). You can also see where I added a call to log() in the sketch’s setup method - that one works fine. I’m not sure what I’m missing here?
#define thermistorAdcPin A0
void setup()
{
Serial.begin(115200);
delay(1000);
float test = log(22579.617188);
Serial.print("\nInitial float test: "); Serial.println(test);
}
double adcToTemp(int RawADC)
{
long Resistance;
double Temp;
Serial.print("\nConvert RAW: "); Serial.println(RawADC);
Resistance = ((10240000 / RawADC) - 10000);
Serial.print("Convert Resistance: "); Serial.println(Resistance);
Temp = log(Resistance); // <--- this line causes the hang
Serial.print("Convert Temp: "); Serial.println(Temp);
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
Temp = Temp - 273.15;
Temp = (Temp * 9.0) / 5.0 + 32.0;
return Temp;
}
void loop()
{
int adcTempVal = analogRead(thermistorAdcPin);
Serial.print("Temp ADC Pin: "); Serial.println(adcTempVal);
Serial.print("Temp F: "); Serial.println(adcToTemp(adcTempVal));
}
The output is:
16:09:20.659 -> ⸮⸮
16:09:21.699 -> Initial float test: 10.02
16:09:21.699 -> Temp ADC Pin: 780
16:09:21.699 -> Temp F:
16:09:21.699 -> Convert RAW: 780
16:09:21.699 -> Convert Resistance: 3128
Thanks for the help!
Chris