Library for Silicon Labs Si7006 digital temperature and humidity chip.

Dependents:   acd52832_Humidity_Temp_Example iBeacon acnsensa acnSENSA

Committer:
jurica238814
Date:
Mon Sep 25 10:21:52 2017 +0000
Revision:
1:155934570c14
Parent:
0:cc2c5d49fe63
Child:
2:7c3c7db34528
aconno i2c class implemented. Temeprature and humidity methods tested and work.

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 0:cc2c5d49fe63 46
jurica238814 0:cc2c5d49fe63 47 /**
jurica238814 0:cc2c5d49fe63 48 * Si7006 constructor.
jurica238814 0:cc2c5d49fe63 49 *
jurica238814 0:cc2c5d49fe63 50 * @param sda mbed pin to use for SDA line of I2C interface.
jurica238814 0:cc2c5d49fe63 51 * @param scl mbed pin to use for SCL line of I2C interface.
jurica238814 0:cc2c5d49fe63 52 */
jurica238814 0:cc2c5d49fe63 53 Si7006(PinName sda, PinName scl);
jurica238814 0:cc2c5d49fe63 54
jurica238814 0:cc2c5d49fe63 55 /**
jurica238814 0:cc2c5d49fe63 56 * @brief Get Electronic ID.
jurica238814 0:cc2c5d49fe63 57 * @details Gets the Electronic ID of the connected device. Verifies the
jurica238814 0:cc2c5d49fe63 58 * ID with an 8-bit CRC.
jurica238814 0:cc2c5d49fe63 59 *
jurica238814 0:cc2c5d49fe63 60 * @param Character buffer to store the id. Needs to be at least 8 bytes.
jurica238814 0:cc2c5d49fe63 61 * @returns 0 if no errors, -1 if error.
jurica238814 0:cc2c5d49fe63 62 */
jurica238814 1:155934570c14 63 uint8_t getElectronicId(char *id);
jurica238814 0:cc2c5d49fe63 64
jurica238814 0:cc2c5d49fe63 65 /**
jurica238814 0:cc2c5d49fe63 66 * @brief Configure sample resolution.
jurica238814 0:cc2c5d49fe63 67 * @details Sets the number of bits used for humidity and temperature readings.
jurica238814 0:cc2c5d49fe63 68 * @param resolution Enum for the resolution setting.
jurica238814 0:cc2c5d49fe63 69 * @returns 0 if no errors, -1 if error.
jurica238814 0:cc2c5d49fe63 70 */
jurica238814 0:cc2c5d49fe63 71 int configResolution(Si7006::resolution_t resolution);
jurica238814 0:cc2c5d49fe63 72
jurica238814 0:cc2c5d49fe63 73 /**
jurica238814 0:cc2c5d49fe63 74 * @brief Get temperature reading.
jurica238814 0:cc2c5d49fe63 75 * @details Initiates a temperature reading and blocks until reading has
jurica238814 0:cc2c5d49fe63 76 * been calculated.
jurica238814 0:cc2c5d49fe63 77 *
jurica238814 0:cc2c5d49fe63 78 * @note Will hold the I2C bus until reading is complete. Refer to datasheet
jurica238814 0:cc2c5d49fe63 79 * for timing specifications.
jurica238814 0:cc2c5d49fe63 80 *
jurica238814 0:cc2c5d49fe63 81 * @param tempC Pointer for temperature reading. Unit is degree Celcius.
jurica238814 0:cc2c5d49fe63 82 * @returns 0 if no errors, -1 if error.
jurica238814 0:cc2c5d49fe63 83 */
jurica238814 1:155934570c14 84 float getTemperature();
jurica238814 0:cc2c5d49fe63 85
jurica238814 0:cc2c5d49fe63 86 /**
jurica238814 0:cc2c5d49fe63 87 * @brief Check temperature reading.
jurica238814 0:cc2c5d49fe63 88 * @details Checks to see if the temperature reading has been completed.
jurica238814 0:cc2c5d49fe63 89 Returns temperature if reading complete.
jurica238814 0:cc2c5d49fe63 90 * @note Must call startTemperature() prior to calling this function.
jurica238814 0:cc2c5d49fe63 91 * @param tempC Pointer for temperature reading. Unit is degree Celcius.
jurica238814 0:cc2c5d49fe63 92 * @returns 0 if reading taken, -1 if reading pending.
jurica238814 0:cc2c5d49fe63 93 */
jurica238814 1:155934570c14 94 float calculateTemperature(char *rawTemp);
jurica238814 0:cc2c5d49fe63 95
jurica238814 0:cc2c5d49fe63 96 /**
jurica238814 0:cc2c5d49fe63 97 * @brief Get humidity reading.
jurica238814 0:cc2c5d49fe63 98 * @details Initiates a humidity reading and blocks until reading has
jurica238814 0:cc2c5d49fe63 99 * been calculated.
jurica238814 0:cc2c5d49fe63 100 *
jurica238814 0:cc2c5d49fe63 101 * @note Will hold the I2C bus until reading is complete. Refer to datasheet
jurica238814 0:cc2c5d49fe63 102 * for timing specifications.
jurica238814 0:cc2c5d49fe63 103 *
jurica238814 0:cc2c5d49fe63 104 * @param humidx10 Pointer for humidity reading. Unit is 1/10th percent.
jurica238814 0:cc2c5d49fe63 105 * @returns 0 if no errors, -1 if error.
jurica238814 0:cc2c5d49fe63 106 */
jurica238814 1:155934570c14 107 float getHumidity();
jurica238814 0:cc2c5d49fe63 108
jurica238814 0:cc2c5d49fe63 109 /**
jurica238814 0:cc2c5d49fe63 110 * @brief Get humidity reading.
jurica238814 0:cc2c5d49fe63 111 * @details Initiates a humidity reading and blocks until reading has
jurica238814 0:cc2c5d49fe63 112 * been calculated.
jurica238814 0:cc2c5d49fe63 113 *
jurica238814 0:cc2c5d49fe63 114 * @note Will hold the I2C bus until reading is complete. Refer to datasheet
jurica238814 0:cc2c5d49fe63 115 * for timing specifications.
jurica238814 0:cc2c5d49fe63 116 *
jurica238814 0:cc2c5d49fe63 117 * @param humid Pointer for humidity reading. Unit is percent.
jurica238814 0:cc2c5d49fe63 118 * @returns 0 if no errors, -1 if error.
jurica238814 0:cc2c5d49fe63 119 */
jurica238814 1:155934570c14 120 float checkHumidity(char *rawHumidity);
jurica238814 1:155934570c14 121
jurica238814 0:cc2c5d49fe63 122 /**
jurica238814 0:cc2c5d49fe63 123 * @brief Get temperature from humidity reading.
jurica238814 0:cc2c5d49fe63 124 * @details Gets temperature reading from previous humidity reading.
jurica238814 0:cc2c5d49fe63 125 * @note Must call startHumidity() prior to calling this function.
jurica238814 0:cc2c5d49fe63 126 * @param tempC Pointer for temperature reading. Unit is degree Celcius.
jurica238814 0:cc2c5d49fe63 127 * @returns 0 if reading taken, -1 if reading pending.
jurica238814 0:cc2c5d49fe63 128 */
jurica238814 0:cc2c5d49fe63 129 int getPrevTemperature(float* tempC);
jurica238814 0:cc2c5d49fe63 130
jurica238814 0:cc2c5d49fe63 131 /**
jurica238814 0:cc2c5d49fe63 132 * @brief Get temperature from humidity reading.
jurica238814 0:cc2c5d49fe63 133 * @details Gets temperature reading from previous humidity reading.
jurica238814 0:cc2c5d49fe63 134 * @note Must call startHumidity() prior to calling this function.
jurica238814 0:cc2c5d49fe63 135 * @param tempCx10 Pointer for temperature reading. Unit is 1/10th degree Celcius.
jurica238814 0:cc2c5d49fe63 136 * @returns 0 if reading taken, -1 if reading pending.
jurica238814 0:cc2c5d49fe63 137 */
jurica238814 0:cc2c5d49fe63 138 int getPrevTemperature(int16_t *tempCx10);
jurica238814 0:cc2c5d49fe63 139
jurica238814 0:cc2c5d49fe63 140 /**
jurica238814 0:cc2c5d49fe63 141 * @brief Get firmware revision.
jurica238814 0:cc2c5d49fe63 142 * @details Reads the firmware revision, refer to datasheet for codes.
jurica238814 0:cc2c5d49fe63 143 * @param rev Pointer to store firmware revision.
jurica238814 0:cc2c5d49fe63 144 * @returns 0 if no errors, -1 if error.
jurica238814 0:cc2c5d49fe63 145 */
jurica238814 0:cc2c5d49fe63 146 int getRev(char *rev);
jurica238814 0:cc2c5d49fe63 147
jurica238814 0:cc2c5d49fe63 148 /**
jurica238814 0:cc2c5d49fe63 149 * @brief Control heater.
jurica238814 0:cc2c5d49fe63 150 * @details Enable or disable the heater.
jurica238814 0:cc2c5d49fe63 151 * @param enable True to enable heater, false to disable.
jurica238814 0:cc2c5d49fe63 152 * @returns 0 if no errors, -1 if error.
jurica238814 0:cc2c5d49fe63 153 */
jurica238814 0:cc2c5d49fe63 154 int heater(bool enable);
jurica238814 1:155934570c14 155
jurica238814 0:cc2c5d49fe63 156 private:
jurica238814 0:cc2c5d49fe63 157
jurica238814 0:cc2c5d49fe63 158 char crc8(char value, char seed);
jurica238814 1:155934570c14 159 aconno_i2c i2c;
jurica238814 0:cc2c5d49fe63 160 bool i2c_owner;
jurica238814 0:cc2c5d49fe63 161 };
jurica238814 0:cc2c5d49fe63 162
jurica238814 0:cc2c5d49fe63 163 #endif /* _Si7006_H_ */