This library demonstrates how to use the sensors on the QW Shield.

Dependents:   QW-TEMP_GPS-NMEA QW-Motiondetection QW-Closet-detection

Committer:
quicksand
Date:
Wed May 18 14:44:57 2016 +0000
Revision:
3:1b27ad5eb94a
Parent:
0:4b56d28cc7e9
Renamed main.cpp to main.txt (example usage code) to avoid conflicts and confusion.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
quicksand 0:4b56d28cc7e9 1 /* mbed Linear Temperature Sensor library
quicksand 0:4b56d28cc7e9 2 * Supports Microchip MCP9700/9701, National Semiconductor LM35
quicksand 0:4b56d28cc7e9 3 *
quicksand 0:4b56d28cc7e9 4 * Written by Todotani, Nov 22 2010
quicksand 0:4b56d28cc7e9 5 */
quicksand 0:4b56d28cc7e9 6
quicksand 0:4b56d28cc7e9 7 #ifndef MBED_LINEARTEMPSENSOR_H
quicksand 0:4b56d28cc7e9 8 #define MBED_LINEARTEMPSENSOR_H
quicksand 0:4b56d28cc7e9 9
quicksand 0:4b56d28cc7e9 10 #include "mbed.h"
quicksand 0:4b56d28cc7e9 11
quicksand 0:4b56d28cc7e9 12 /** Linear Temperature Sensor class.
quicksand 0:4b56d28cc7e9 13 * Sample and store sensor acuired value in N (default=10) times and
quicksand 0:4b56d28cc7e9 14 * calculate avarage temperature from sampled data
quicksand 0:4b56d28cc7e9 15 * Supports Microchip MCP9700/9701, National Semiconductor LM35
quicksand 0:4b56d28cc7e9 16 * @author Todotani
quicksand 0:4b56d28cc7e9 17 */
quicksand 0:4b56d28cc7e9 18 class LinearTempSensor {
quicksand 0:4b56d28cc7e9 19 public:
quicksand 0:4b56d28cc7e9 20 /** Sensor Type Definitions */
quicksand 0:4b56d28cc7e9 21 enum SensorType {
quicksand 0:4b56d28cc7e9 22 MCP9700, /**< Microchip MCP9700 (Default) */
quicksand 0:4b56d28cc7e9 23 MCP9701, /**< Microchip MCP9701 */
quicksand 0:4b56d28cc7e9 24 LM35 /**< National Semiconductor LM35 */
quicksand 0:4b56d28cc7e9 25 };
quicksand 0:4b56d28cc7e9 26
quicksand 0:4b56d28cc7e9 27 /** Create a Temperature Sensor instanse
quicksand 0:4b56d28cc7e9 28 *
quicksand 0:4b56d28cc7e9 29 * @param ain PinName of analog input
quicksand 0:4b56d28cc7e9 30 * @param N Number of samples to calculate average temperature (default = 10)
quicksand 0:4b56d28cc7e9 31 * @param type Sensor type (default = MCP9700)
quicksand 0:4b56d28cc7e9 32 */
quicksand 0:4b56d28cc7e9 33 LinearTempSensor(PinName ain, int N = 10, SensorType type = MCP9700);
quicksand 0:4b56d28cc7e9 34
quicksand 0:4b56d28cc7e9 35 /** Sample (read) sensor data and store to buffer
quicksand 0:4b56d28cc7e9 36 *
quicksand 0:4b56d28cc7e9 37 * @param None
quicksand 0:4b56d28cc7e9 38 * @return Sensor-acuired value (mV)
quicksand 0:4b56d28cc7e9 39 */
quicksand 0:4b56d28cc7e9 40 float Sense();
quicksand 0:4b56d28cc7e9 41
quicksand 0:4b56d28cc7e9 42 /** Calculate average temperature from sample buffer
quicksand 0:4b56d28cc7e9 43 *
quicksand 0:4b56d28cc7e9 44 * @param None
quicksand 0:4b56d28cc7e9 45 * @return Average temperature from N times of sumple (Centigrade)
quicksand 0:4b56d28cc7e9 46 */
quicksand 0:4b56d28cc7e9 47 float GetAverageTemp();
quicksand 0:4b56d28cc7e9 48
quicksand 0:4b56d28cc7e9 49 /** Calculate temperature from the latest sample
quicksand 0:4b56d28cc7e9 50 *
quicksand 0:4b56d28cc7e9 51 * @param None
quicksand 0:4b56d28cc7e9 52 * @return Temperature from the latest sampled data (Centigrade)
quicksand 0:4b56d28cc7e9 53 */
quicksand 0:4b56d28cc7e9 54 float GetLatestTemp();
quicksand 0:4b56d28cc7e9 55
quicksand 0:4b56d28cc7e9 56 ~LinearTempSensor();
quicksand 0:4b56d28cc7e9 57
quicksand 0:4b56d28cc7e9 58 private:
quicksand 0:4b56d28cc7e9 59 AnalogIn _ain;
quicksand 0:4b56d28cc7e9 60 int _samples;
quicksand 0:4b56d28cc7e9 61 SensorType _type;
quicksand 0:4b56d28cc7e9 62
quicksand 0:4b56d28cc7e9 63 float *sampleBuffer; // Buffer to store sensor acuired data
quicksand 0:4b56d28cc7e9 64 bool bufferNotFilled; // Flag shows that buffer have not filled
quicksand 0:4b56d28cc7e9 65 uint32_t sampleCount;
quicksand 0:4b56d28cc7e9 66 uint32_t index;
quicksand 0:4b56d28cc7e9 67
quicksand 0:4b56d28cc7e9 68 float V0; // Sensor read value in case 0 degree
quicksand 0:4b56d28cc7e9 69 float Tc; // Tmperature coefficient (temprature inclease) in each degree
quicksand 0:4b56d28cc7e9 70 float Vref; // Reference volgate for ADC
quicksand 0:4b56d28cc7e9 71 };
quicksand 0:4b56d28cc7e9 72
quicksand 0:4b56d28cc7e9 73 #endif