Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to thermistor resistance calculation. #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions thermistor.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/**
* Copyright (c) 2014 panStamp <[email protected]>
*
*
* This file is part of the panStamp project.
*
*
* panStamp is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* any later version.
*
*
* panStamp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public License
* along with panStamp; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
* USA
*
*
* Author: Daniel Berenguer
* Creation date: 11/05/2014
*
Expand All @@ -39,7 +39,7 @@
#define TEMPERATURENOMINAL 25

// Number of ADC samples
#define NUMSAMPLES 5
#define NUMSAMPLES 5

// ADC resolution
#if defined(PANSTAMP_NRG) || defined(ESP_PLATFORM)
Expand All @@ -50,15 +50,15 @@
#define VERBOSE_SENSOR_ENABLED 1
/**
* THERMISTOR
*
*
* Class constructor
*
* @param adcPin Analog pin where the thermistor is connected
* @param nomRes Nominal resistance at 25 degrees Celsius
* @param bCoef beta coefficient of the thermistor
* @param serialRes Value of the serial resistor
*/
THERMISTOR::THERMISTOR(uint8_t adcPin, uint16_t nomRes, uint16_t bCoef, uint16_t serialRes)
THERMISTOR::THERMISTOR(uint8_t adcPin, uint16_t nomRes, uint16_t bCoef, uint16_t serialRes)
{
analogPin = adcPin;
nominalResistance = nomRes;
Expand Down Expand Up @@ -92,20 +92,20 @@ int THERMISTOR::read(void)
}
average /= NUMSAMPLES;

#ifdef VERBOSE_SENSOR_ENABLED
Serial.print("Average analog reading ");
#ifdef VERBOSE_SENSOR_ENABLED
Serial.print("Average analog reading ");
Serial.println(average);
#endif

// convert the value to resistance
average = ADC_RESOLUTION / average - 1;
average = serialResistance * average;
average = serialResistance / average;

#ifdef VERBOSE_SENSOR_ENABLED
Serial.print("Thermistor resistance ");
Serial.print("Thermistor resistance ");
Serial.println(average);
#endif

float steinhart;
steinhart = average / nominalResistance; // (R/Ro)
#ifdef PANSTAMP_NRG
Expand All @@ -117,13 +117,12 @@ int THERMISTOR::read(void)
steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
steinhart = 1.0 / steinhart; // Invert
steinhart -= 273.15; // convert to C

#ifdef VERBOSE_SENSOR_ENABLED
Serial.print("Temperature ");
Serial.print("Temperature ");
Serial.print(steinhart);
Serial.println(" *C");
#endif

return (int)(steinhart * 10);
}