Tom Kreyche / ADT7410

Dependents:   BLE_ADT7410_TMP102_Sample BLE_HTM_HRM1017 BLENano_SimpleTemplate_temp_170802 BLENano_SimpleTemplate_temp_170813 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ADT7410.h Source File

ADT7410.h

00001 /*
00002 Copyright (c) 2011 Tom Kreyche tkreyche@well.com
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a copy
00005 of this software and associated documentation files (the "Software"), to deal
00006 in the Software without restriction, including without limitation the rights
00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008 copies of the Software, and to permit persons to whom the Software is
00009 furnished to do so, subject to the following conditions:
00010 
00011 The above copyright notice and this permission notice shall be included in
00012 all copies or substantial portions of the Software.
00013 
00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020 THE SOFTWARE.
00021 */
00022 
00023 
00024 #ifndef ADT7410_H
00025 #define ADT7410_H
00026 
00027 #include "mbed.h"
00028 
00029 // sensor register addresses
00030 // only a partial list, don't use them all
00031 #define TEMP_REG_ADDR 0x00
00032 #define CONFIG_REG_ADDR 0x03
00033 #define RESET 0x2F
00034 
00035 // configuration register values
00036 // only a partial list, don't use them all
00037 #define ONE_SPS_MODE 0x40
00038 
00039 /**
00040 *
00041 * Example:
00042 * @code
00043 *
00044 * #include "mbed.h"
00045 * #include "ADT7410.h"
00046 *
00047 * ADT7410 tempSens1(p28, p27, 0x90, 100000);
00048 *
00049 * int main() {
00050 *
00051 *   // reset sensor to default values
00052 *   tempSens1.reset();
00053 *
00054 *   // read the config register, should be default
00055 *   printf("Config: 0x%x\n", tempSens1.getConfig());
00056 *
00057 *   // reduce sample rate to save power
00058 *   tempSens1.setConfig(ONE_SPS_MODE);
00059 *
00060 *   // check config register was set correctly
00061 *   printf("Config: 0x%x\n", tempSens1.getConfig());
00062 *
00063 *   // get temperature every two seconds
00064 *   while (1) {
00065 *       printf("Deg C %f\n", tempSens1.getTemp());
00066 *       wait(2);
00067 *   }
00068 * }
00069 *
00070 * @endcode
00071 */
00072 
00073 
00074 
00075 class ADT7410 {
00076 
00077 public:
00078 
00079     /** Create a temperature sensor object 
00080     * @param sda I2C data
00081     * @param scl I2C clock
00082     * @param addr I2C bus address
00083     * @param hz I2C bus speed
00084     */
00085     ADT7410(PinName sda, PinName scl, char addr, int hz);
00086 
00087     /** Destroys object
00088     */
00089     ~ADT7410();
00090 
00091     /** Reads the current temperature
00092     */
00093     float getTemp();
00094 
00095     /** Change config register, currently only used to reduce power via 1SPS mode
00096     * @param regVal new config register value, see datasheet for details
00097     */
00098     void setConfig(char regVal);
00099 
00100     /** Read back config register
00101     */
00102     char getConfig();
00103 
00104     /** Reset sensor to default setting
00105     */
00106     void reset();
00107 
00108 private:
00109     I2C i2c;
00110     char busAddr;
00111 
00112 };
00113 
00114 #endif