Сбор информации о погодных условиях
Dependencies: RF24 USBDevice mbed
Revision 1:8766173d267f, committed 2015-10-19
- Comitter:
- pro100kot14
- Date:
- Mon Oct 19 22:03:12 2015 +0000
- Parent:
- 0:1e03d2cd238f
- Child:
- 2:ad2653bcf93f
- Commit message:
- ???????? ?????, ??????????? ?????????? ? ????????? ?????? ? ??????????????.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Thermistor.cpp Mon Oct 19 22:03:12 2015 +0000 @@ -0,0 +1,56 @@ +#include "Thermistor.h" + +Thermistor::Thermistor(AnalogIn inputChanel, double a, double b, double c):input(inputChanel), error(0){ + this->a = a; + this->b = b; + this->c = c; +} + +double Thermistor::getTemperature(){ + double temp; + double realV; + double resistance; + //3.3 - ADC maximum + realV = input.read()*3.3; + resistance = (10000 * 5.0) / realV - 10000; + //Considering the error + resistance -= error; + //Calculations using Steinhart–Hart equation + temp = log(resistance); + temp = 1/(a+b*temp+c*temp*temp*temp); + //Convert from Fahrenheit to Celsius + temp -= 273.15; + return temp; +} + + void Thermistor::setError(double error){ + this->error = error; + } + + double Thermistor::getError(){ + return error; + } + + void Thermistor::setCoefficientA(double a){ + this->a = a; + } + + void Thermistor::setCoefficientB(double b){ + this->b = b; + } + + void Thermistor::setCoefficientC(double c){ + this->c = c; + } + + double Thermistor::getCoefficientA(){ + return a; + } + + double Thermistor::getCoefficientB(){ + return b; + } + + double Thermistor::getCoefficientC(){ + return c; + } \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Thermistor.h Mon Oct 19 22:03:12 2015 +0000 @@ -0,0 +1,88 @@ +#ifndef Thermistor_H +#define Thermistor_H + +#include "mbed.h" +#include <math.h> +/** +* Reads the resistance of thermistor and using Steinhart–Hart equation +* converts it to Celsius +* +*/ +class Thermistor{ +public: + /** + * Constructor. In the calculations used a model of + * the resistance of a semiconductor at different temperatures - + * The Steinhart–Hart equation. Need to set the coefficients a, b, c. + * + * @param inputChanel The analog input is connected to the sensor + * @param a Steinhart–Hart coefficient + * @param b Steinhart–Hart coefficient + * @param c Steinhart–Hart coefficient + */ + Thermistor(AnalogIn inputChanel, double a, double b, double c); + + /** + * The temperature in degrees Celsius + * @returns Temperature + */ + double getTemperature(); + + /** + * Set error value used in the calculation. + * The resulting resistance is computed as <real resistance> - error; + * @param error Error in Ohms + */ + void setError(double error); + + /** + * Error value used in the calculation + * The resulting resistance is computed as <real resistance> - error; + * @returns Error in Ohms + */ + double getError(); + + /** + * Set a coefficient of Steinhart–Hart equation + * @param a a-coefficient + */ + void setCoefficientA(double a); + + /** + * Set b coefficient of Steinhart–Hart equation + * @param b b-coefficient + */ + void setCoefficientB(double b); + + /** + * Set c coefficient of Steinhart–Hart equation + * @param c c-coefficient + */ + void setCoefficientC(double c); + + /** + * a coefficient of Steinhart–Hart equation + * @returns a coefficient + */ + double getCoefficientA(); + + /** + * b coefficient of Steinhart–Hart equation + * @returns b coefficient + */ + double getCoefficientB(); + + /** + * c coefficient of Steinhart–Hart equation + * @returns c coefficient + */ + double getCoefficientC(); + +private: + AnalogIn input; + //Thermistor error in Ohms + double error; + double a, b, c; +}; + +#endif \ No newline at end of file
--- a/main.cpp Sat Oct 17 17:14:48 2015 +0000 +++ b/main.cpp Mon Oct 19 22:03:12 2015 +0000 @@ -1,15 +1,18 @@ #include "mbed.h" #include "USBSerial.h" -#include <math.h> #include "ThermometerTmp36.h" +#include "Thermistor.h" USBSerial pc; -AnalogIn ain(A0); +AnalogIn tmp36(A0); +AnalogIn thermist(A2); int main() { -ThermometerTmp36 term(ain); + ThermometerTmp36 termTmp36(tmp36); + Thermistor term503(thermist, 0.001995, 0.00007997, 0.0000003863); + term503.setError(-5000); while(1) { - pc.printf("temperatureC: %f\r\n",term.getTemperature()); + pc.printf("TMP36: %f degC\tTermistor: %f degC\r\n", termTmp36.getTemperature(), term503.getTemperature()); wait(1); } }