th
Dependents: condato_Coldchainlogger condato_Coldchainlogger
Thermistor.h@0:000a8be2414d, 2016-03-09 (annotated)
- Committer:
- unix_guru
- Date:
- Wed Mar 09 13:52:45 2016 +0000
- Revision:
- 0:000a8be2414d
- Child:
- 1:601e1435dfb8
Created Thermistor Library for re-use
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
unix_guru | 0:000a8be2414d | 1 | #ifndef THERMISTOR_H |
unix_guru | 0:000a8be2414d | 2 | #define THERMISTOR_H |
unix_guru | 0:000a8be2414d | 3 | /// |
unix_guru | 0:000a8be2414d | 4 | /// @mainpage Thermistor Temperature library |
unix_guru | 0:000a8be2414d | 5 | /// |
unix_guru | 0:000a8be2414d | 6 | /// This is a Thermistor to Temerature conversion library |
unix_guru | 0:000a8be2414d | 7 | /// |
unix_guru | 0:000a8be2414d | 8 | /// Much thanks to @Adafruit for this tutorial: |
unix_guru | 0:000a8be2414d | 9 | /// https://learn.adafruit.com/thermistor/using-a-thermistor |
unix_guru | 0:000a8be2414d | 10 | /// |
unix_guru | 0:000a8be2414d | 11 | /// The 100K Thermistor is configured with a 4.7k series resistor |
unix_guru | 0:000a8be2414d | 12 | /// tied to vcc (3.3v) like this: |
unix_guru | 0:000a8be2414d | 13 | /// |
unix_guru | 0:000a8be2414d | 14 | /// +3.3v |
unix_guru | 0:000a8be2414d | 15 | /// | |
unix_guru | 0:000a8be2414d | 16 | /// \ |
unix_guru | 0:000a8be2414d | 17 | /// / 4.7k series resistor |
unix_guru | 0:000a8be2414d | 18 | /// \ |
unix_guru | 0:000a8be2414d | 19 | /// / |
unix_guru | 0:000a8be2414d | 20 | /// | |
unix_guru | 0:000a8be2414d | 21 | /// .-----------O To Anlog pin on FRDM board |
unix_guru | 0:000a8be2414d | 22 | /// | |
unix_guru | 0:000a8be2414d | 23 | /// \ |
unix_guru | 0:000a8be2414d | 24 | /// / |
unix_guru | 0:000a8be2414d | 25 | /// Thermistor 100k Nominal |
unix_guru | 0:000a8be2414d | 26 | /// \ |
unix_guru | 0:000a8be2414d | 27 | /// / |
unix_guru | 0:000a8be2414d | 28 | /// | |
unix_guru | 0:000a8be2414d | 29 | /// --- |
unix_guru | 0:000a8be2414d | 30 | /// GND |
unix_guru | 0:000a8be2414d | 31 | /// |
unix_guru | 0:000a8be2414d | 32 | /// |
unix_guru | 0:000a8be2414d | 33 | /// @author Michael J. Ball |
unix_guru | 0:000a8be2414d | 34 | /// unix_guru at hotmail.com |
unix_guru | 0:000a8be2414d | 35 | /// @unix_guru on Twitter |
unix_guru | 0:000a8be2414d | 36 | /// March 2016 |
unix_guru | 0:000a8be2414d | 37 | /// |
unix_guru | 0:000a8be2414d | 38 | /// @code |
unix_guru | 0:000a8be2414d | 39 | /// Thermistor bed(PTB10); |
unix_guru | 0:000a8be2414d | 40 | /// printf("Temperature is %f Celcius", bed.get_temperature()); |
unix_guru | 0:000a8be2414d | 41 | /// |
unix_guru | 0:000a8be2414d | 42 | /// ... |
unix_guru | 0:000a8be2414d | 43 | /// @endcode |
unix_guru | 0:000a8be2414d | 44 | /// |
unix_guru | 0:000a8be2414d | 45 | /// @license |
unix_guru | 0:000a8be2414d | 46 | /// Licensed under the Apache License, Version 2.0 (the "License"); |
unix_guru | 0:000a8be2414d | 47 | /// you may not use this file except in compliance with the License. |
unix_guru | 0:000a8be2414d | 48 | /// You may obtain a copy of the License at |
unix_guru | 0:000a8be2414d | 49 | /// |
unix_guru | 0:000a8be2414d | 50 | /// http://www.apache.org/licenses/LICENSE-2.0 |
unix_guru | 0:000a8be2414d | 51 | /// |
unix_guru | 0:000a8be2414d | 52 | /// Unless required by applicable law or agreed to in writing, software |
unix_guru | 0:000a8be2414d | 53 | /// distributed under the License is distributed on an "AS IS" BASIS, |
unix_guru | 0:000a8be2414d | 54 | /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
unix_guru | 0:000a8be2414d | 55 | /// See the License for the specific language governing permissions and |
unix_guru | 0:000a8be2414d | 56 | /// limitations under the License. |
unix_guru | 0:000a8be2414d | 57 | /// |
unix_guru | 0:000a8be2414d | 58 | |
unix_guru | 0:000a8be2414d | 59 | |
unix_guru | 0:000a8be2414d | 60 | #include "mbed.h" |
unix_guru | 0:000a8be2414d | 61 | |
unix_guru | 0:000a8be2414d | 62 | |
unix_guru | 0:000a8be2414d | 63 | #define THERMISTORNOMINAL 100000 // 100k default |
unix_guru | 0:000a8be2414d | 64 | // temp. for nominal resistance (almost always 25 C) |
unix_guru | 0:000a8be2414d | 65 | #define TEMPERATURENOMINAL 25 |
unix_guru | 0:000a8be2414d | 66 | // The beta coefficient of the thermistor (usually 3000-4000) |
unix_guru | 0:000a8be2414d | 67 | #define BCOEFFICIENT 3950 |
unix_guru | 0:000a8be2414d | 68 | // the value of the 'other' resistor |
unix_guru | 0:000a8be2414d | 69 | #define SERIESRESISTOR 4700 |
unix_guru | 0:000a8be2414d | 70 | |
unix_guru | 0:000a8be2414d | 71 | |
unix_guru | 0:000a8be2414d | 72 | class Thermistor { |
unix_guru | 0:000a8be2414d | 73 | public: |
unix_guru | 0:000a8be2414d | 74 | Thermistor(PinName pin); |
unix_guru | 0:000a8be2414d | 75 | /** Receives a PinName variable. |
unix_guru | 0:000a8be2414d | 76 | * @param pin mbed pin to which the thermistor is connected |
unix_guru | 0:000a8be2414d | 77 | */ |
unix_guru | 0:000a8be2414d | 78 | |
unix_guru | 0:000a8be2414d | 79 | |
unix_guru | 0:000a8be2414d | 80 | float get_temperature(); |
unix_guru | 0:000a8be2414d | 81 | /** This is the workhorse routine that calculates the temperature |
unix_guru | 0:000a8be2414d | 82 | * using the Steinhart-Hart equation for thermistors |
unix_guru | 0:000a8be2414d | 83 | * https://en.wikipedia.org/wiki/Steinhart%E2%80%93Hart_equation |
unix_guru | 0:000a8be2414d | 84 | */ |
unix_guru | 0:000a8be2414d | 85 | void init(); // Set default Steinhart-Hart values |
unix_guru | 0:000a8be2414d | 86 | void set_ThermistorNominal(float thermnom); // Change the thermistors nominal resistance |
unix_guru | 0:000a8be2414d | 87 | void set_TemperatureNominal(float tempnom); // Change the thermistors nominal temperature |
unix_guru | 0:000a8be2414d | 88 | void set_BCoefficient(float bcoefficient); // Change the thermistors BCoefficient |
unix_guru | 0:000a8be2414d | 89 | void set_SeriesResistor(float resistor); // Change the value of the series resistor |
unix_guru | 0:000a8be2414d | 90 | |
unix_guru | 0:000a8be2414d | 91 | private: |
unix_guru | 0:000a8be2414d | 92 | AnalogIn _pin; |
unix_guru | 0:000a8be2414d | 93 | float ThermistorNominal; |
unix_guru | 0:000a8be2414d | 94 | float TemperatureNominal; |
unix_guru | 0:000a8be2414d | 95 | float BCoefficient; |
unix_guru | 0:000a8be2414d | 96 | float SeriesResistor; |
unix_guru | 0:000a8be2414d | 97 | }; |
unix_guru | 0:000a8be2414d | 98 | |
unix_guru | 0:000a8be2414d | 99 | #endif |