diff --git a/thermistor.cpp b/thermistor.cpp index ae8b2ab..2bc988b 100755 --- a/thermistor.cpp +++ b/thermistor.cpp @@ -1,23 +1,23 @@ /** * Copyright (c) 2014 panStamp - * + * * 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 * @@ -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) @@ -50,7 +50,7 @@ #define VERBOSE_SENSOR_ENABLED 1 /** * THERMISTOR - * + * * Class constructor * * @param adcPin Analog pin where the thermistor is connected @@ -58,7 +58,7 @@ * @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; @@ -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 @@ -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); } -