Library for Silicon Labs Si7006 digital temperature and humidity chip.

Dependents:   acd52832_Humidity_Temp_Example iBeacon acnsensa acnSENSA

Committer:
jurica238814
Date:
Tue Sep 26 12:04:12 2017 +0000
Revision:
2:7c3c7db34528
Parent:
1:155934570c14
I2C object replaced by I2C reference.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jurica238814 0:cc2c5d49fe63 1 /*******************************************************************************
jurica238814 0:cc2c5d49fe63 2 * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved.
jurica238814 0:cc2c5d49fe63 3 *
jurica238814 0:cc2c5d49fe63 4 * Permission is hereby granted, free of charge, to any person obtaining a
jurica238814 0:cc2c5d49fe63 5 * copy of this software and associated documentation files (the "Software"),
jurica238814 0:cc2c5d49fe63 6 * to deal in the Software without restriction, including without limitation
jurica238814 0:cc2c5d49fe63 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
jurica238814 0:cc2c5d49fe63 8 * and/or sell copies of the Software, and to permit persons to whom the
jurica238814 0:cc2c5d49fe63 9 * Software is furnished to do so, subject to the following conditions:
jurica238814 0:cc2c5d49fe63 10 *
jurica238814 0:cc2c5d49fe63 11 * The above copyright notice and this permission notice shall be included
jurica238814 0:cc2c5d49fe63 12 * in all copies or substantial portions of the Software.
jurica238814 0:cc2c5d49fe63 13 *
jurica238814 0:cc2c5d49fe63 14 *
jurica238814 0:cc2c5d49fe63 15 * The library is modified to suite Si7006A20 Humidity and Temperature Sesor
jurica238814 0:cc2c5d49fe63 16 * Made by Jurica Resetar @ aconno
jurica238814 0:cc2c5d49fe63 17 * More info and contact: aconno.de
jurica238814 0:cc2c5d49fe63 18 *
jurica238814 0:cc2c5d49fe63 19 *******************************************************************************
jurica238814 0:cc2c5d49fe63 20 */
jurica238814 0:cc2c5d49fe63 21
jurica238814 0:cc2c5d49fe63 22 #ifndef _Si70006A20_H_
jurica238814 0:cc2c5d49fe63 23 #define _Si70006A20_H_
jurica238814 0:cc2c5d49fe63 24
jurica238814 0:cc2c5d49fe63 25 #include "mbed.h"
jurica238814 1:155934570c14 26 #include "aconno_i2c.h"
jurica238814 0:cc2c5d49fe63 27
jurica238814 1:155934570c14 28 /***** Definitions *****/
jurica238814 1:155934570c14 29 #define I2C_ADDR (0x80) // 1000000x
jurica238814 1:155934570c14 30 #define POLYVAL (0x131)
jurica238814 1:155934570c14 31
jurica238814 1:155934570c14 32
jurica238814 0:cc2c5d49fe63 33 class Si7006{
jurica238814 0:cc2c5d49fe63 34 public:
jurica238814 0:cc2c5d49fe63 35
jurica238814 0:cc2c5d49fe63 36 /**
jurica238814 0:cc2c5d49fe63 37 * @brief Measurement resolution.
jurica238814 0:cc2c5d49fe63 38 * @details Controls the resolution of the humidity and temperarure readings.
jurica238814 0:cc2c5d49fe63 39 */
jurica238814 0:cc2c5d49fe63 40 typedef enum {
jurica238814 0:cc2c5d49fe63 41 RH_12b_TEMP_14b = 0x0, ///< 12 bits for RH, 14 bits for Temp
jurica238814 0:cc2c5d49fe63 42 RH_8b_TEMP_12b = 0x1, ///< 8 bits for RH, 12 bits for Temp
jurica238814 0:cc2c5d49fe63 43 RH_10b_TEMP_13b = 0x2, ///< 10 bits for RH, 13 bits for Temp
jurica238814 0:cc2c5d49fe63 44 RH_11b_TEMP_11b = 0x3, ///< 11 bits for RH, 11 bits for Temp
jurica238814 0:cc2c5d49fe63 45 } resolution_t;
jurica238814 2:7c3c7db34528 46
jurica238814 0:cc2c5d49fe63 47 /**
jurica238814 2:7c3c7db34528 48 * Si7006 constructor
jurica238814 0:cc2c5d49fe63 49 *
jurica238814 0:cc2c5d49fe63 50 */
jurica238814 2:7c3c7db34528 51 Si7006(I2C *ic2);
jurica238814 0:cc2c5d49fe63 52
jurica238814 0:cc2c5d49fe63 53 /**
jurica238814 0:cc2c5d49fe63 54 * @brief Get Electronic ID.
jurica238814 0:cc2c5d49fe63 55 * @details Gets the Electronic ID of the connected device. Verifies the
jurica238814 0:cc2c5d49fe63 56 * ID with an 8-bit CRC.
jurica238814 0:cc2c5d49fe63 57 *
jurica238814 0:cc2c5d49fe63 58 * @param Character buffer to store the id. Needs to be at least 8 bytes.
jurica238814 0:cc2c5d49fe63 59 * @returns 0 if no errors, -1 if error.
jurica238814 0:cc2c5d49fe63 60 */
jurica238814 1:155934570c14 61 uint8_t getElectronicId(char *id);
jurica238814 0:cc2c5d49fe63 62
jurica238814 0:cc2c5d49fe63 63 /**
jurica238814 0:cc2c5d49fe63 64 * @brief Configure sample resolution.
jurica238814 0:cc2c5d49fe63 65 * @details Sets the number of bits used for humidity and temperature readings.
jurica238814 0:cc2c5d49fe63 66 * @param resolution Enum for the resolution setting.
jurica238814 0:cc2c5d49fe63 67 * @returns 0 if no errors, -1 if error.
jurica238814 0:cc2c5d49fe63 68 */
jurica238814 0:cc2c5d49fe63 69 int configResolution(Si7006::resolution_t resolution);
jurica238814 0:cc2c5d49fe63 70
jurica238814 0:cc2c5d49fe63 71 /**
jurica238814 0:cc2c5d49fe63 72 * @brief Get temperature reading.
jurica238814 0:cc2c5d49fe63 73 * @details Initiates a temperature reading and blocks until reading has
jurica238814 0:cc2c5d49fe63 74 * been calculated.
jurica238814 0:cc2c5d49fe63 75 *
jurica238814 0:cc2c5d49fe63 76 * @note Will hold the I2C bus until reading is complete. Refer to datasheet
jurica238814 0:cc2c5d49fe63 77 * for timing specifications.
jurica238814 0:cc2c5d49fe63 78 *
jurica238814 0:cc2c5d49fe63 79 * @param tempC Pointer for temperature reading. Unit is degree Celcius.
jurica238814 0:cc2c5d49fe63 80 * @returns 0 if no errors, -1 if error.
jurica238814 0:cc2c5d49fe63 81 */
jurica238814 1:155934570c14 82 float getTemperature();
jurica238814 0:cc2c5d49fe63 83
jurica238814 0:cc2c5d49fe63 84 /**
jurica238814 0:cc2c5d49fe63 85 * @brief Check temperature reading.
jurica238814 0:cc2c5d49fe63 86 * @details Checks to see if the temperature reading has been completed.
jurica238814 0:cc2c5d49fe63 87 Returns temperature if reading complete.
jurica238814 0:cc2c5d49fe63 88 * @note Must call startTemperature() prior to calling this function.
jurica238814 0:cc2c5d49fe63 89 * @param tempC Pointer for temperature reading. Unit is degree Celcius.
jurica238814 0:cc2c5d49fe63 90 * @returns 0 if reading taken, -1 if reading pending.
jurica238814 0:cc2c5d49fe63 91 */
jurica238814 1:155934570c14 92 float calculateTemperature(char *rawTemp);
jurica238814 0:cc2c5d49fe63 93
jurica238814 0:cc2c5d49fe63 94 /**
jurica238814 0:cc2c5d49fe63 95 * @brief Get humidity reading.
jurica238814 0:cc2c5d49fe63 96 * @details Initiates a humidity reading and blocks until reading has
jurica238814 0:cc2c5d49fe63 97 * been calculated.
jurica238814 0:cc2c5d49fe63 98 *
jurica238814 0:cc2c5d49fe63 99 * @note Will hold the I2C bus until reading is complete. Refer to datasheet
jurica238814 0:cc2c5d49fe63 100 * for timing specifications.
jurica238814 0:cc2c5d49fe63 101 *
jurica238814 0:cc2c5d49fe63 102 * @param humidx10 Pointer for humidity reading. Unit is 1/10th percent.
jurica238814 0:cc2c5d49fe63 103 * @returns 0 if no errors, -1 if error.
jurica238814 0:cc2c5d49fe63 104 */
jurica238814 1:155934570c14 105 float getHumidity();
jurica238814 0:cc2c5d49fe63 106
jurica238814 0:cc2c5d49fe63 107 /**
jurica238814 0:cc2c5d49fe63 108 * @brief Get humidity reading.
jurica238814 0:cc2c5d49fe63 109 * @details Initiates a humidity reading and blocks until reading has
jurica238814 0:cc2c5d49fe63 110 * been calculated.
jurica238814 0:cc2c5d49fe63 111 *
jurica238814 0:cc2c5d49fe63 112 * @note Will hold the I2C bus until reading is complete. Refer to datasheet
jurica238814 0:cc2c5d49fe63 113 * for timing specifications.
jurica238814 0:cc2c5d49fe63 114 *
jurica238814 0:cc2c5d49fe63 115 * @param humid Pointer for humidity reading. Unit is percent.
jurica238814 0:cc2c5d49fe63 116 * @returns 0 if no errors, -1 if error.
jurica238814 0:cc2c5d49fe63 117 */
jurica238814 1:155934570c14 118 float checkHumidity(char *rawHumidity);
jurica238814 1:155934570c14 119
jurica238814 0:cc2c5d49fe63 120 /**
jurica238814 0:cc2c5d49fe63 121 * @brief Get temperature from humidity reading.
jurica238814 0:cc2c5d49fe63 122 * @details Gets temperature reading from previous humidity reading.
jurica238814 0:cc2c5d49fe63 123 * @note Must call startHumidity() prior to calling this function.
jurica238814 0:cc2c5d49fe63 124 * @param tempC Pointer for temperature reading. Unit is degree Celcius.
jurica238814 0:cc2c5d49fe63 125 * @returns 0 if reading taken, -1 if reading pending.
jurica238814 0:cc2c5d49fe63 126 */
jurica238814 0:cc2c5d49fe63 127 int getPrevTemperature(float* tempC);
jurica238814 0:cc2c5d49fe63 128
jurica238814 0:cc2c5d49fe63 129 /**
jurica238814 0:cc2c5d49fe63 130 * @brief Get temperature from humidity reading.
jurica238814 0:cc2c5d49fe63 131 * @details Gets temperature reading from previous humidity reading.
jurica238814 0:cc2c5d49fe63 132 * @note Must call startHumidity() prior to calling this function.
jurica238814 0:cc2c5d49fe63 133 * @param tempCx10 Pointer for temperature reading. Unit is 1/10th degree Celcius.
jurica238814 0:cc2c5d49fe63 134 * @returns 0 if reading taken, -1 if reading pending.
jurica238814 0:cc2c5d49fe63 135 */
jurica238814 0:cc2c5d49fe63 136 int getPrevTemperature(int16_t *tempCx10);
jurica238814 0:cc2c5d49fe63 137
jurica238814 0:cc2c5d49fe63 138 /**
jurica238814 0:cc2c5d49fe63 139 * @brief Get firmware revision.
jurica238814 0:cc2c5d49fe63 140 * @details Reads the firmware revision, refer to datasheet for codes.
jurica238814 0:cc2c5d49fe63 141 * @param rev Pointer to store firmware revision.
jurica238814 0:cc2c5d49fe63 142 * @returns 0 if no errors, -1 if error.
jurica238814 0:cc2c5d49fe63 143 */
jurica238814 0:cc2c5d49fe63 144 int getRev(char *rev);
jurica238814 0:cc2c5d49fe63 145
jurica238814 0:cc2c5d49fe63 146 /**
jurica238814 0:cc2c5d49fe63 147 * @brief Control heater.
jurica238814 0:cc2c5d49fe63 148 * @details Enable or disable the heater.
jurica238814 0:cc2c5d49fe63 149 * @param enable True to enable heater, false to disable.
jurica238814 0:cc2c5d49fe63 150 * @returns 0 if no errors, -1 if error.
jurica238814 0:cc2c5d49fe63 151 */
jurica238814 0:cc2c5d49fe63 152 int heater(bool enable);
jurica238814 1:155934570c14 153
jurica238814 0:cc2c5d49fe63 154 private:
jurica238814 0:cc2c5d49fe63 155
jurica238814 0:cc2c5d49fe63 156 char crc8(char value, char seed);
jurica238814 1:155934570c14 157 aconno_i2c i2c;
jurica238814 0:cc2c5d49fe63 158 bool i2c_owner;
jurica238814 0:cc2c5d49fe63 159 };
jurica238814 0:cc2c5d49fe63 160
jurica238814 0:cc2c5d49fe63 161 #endif /* _Si7006_H_ */