Mobile Life IoT project using the AT&T IoT Starter Kit Software and files for my device to monitor the status or our Airstream travel trailer RV. A full description of the project is at Hackster.IO here as part of the Realtime AT&T IoT Starter Kit Challenge: https://www.hackster.io/Anubus/mobile-life-iot-9c10be

Dependencies:   FXOS8700CQ MODSERIAL mbed

Committer:
Anubus
Date:
Sun Apr 02 12:28:21 2017 +0000
Revision:
0:bd276b1f1249
public version commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Anubus 0:bd276b1f1249 1 /* ===================================================================
Anubus 0:bd276b1f1249 2 Copyright © 2016, AVNET Inc.
Anubus 0:bd276b1f1249 3
Anubus 0:bd276b1f1249 4 Licensed under the Apache License, Version 2.0 (the "License");
Anubus 0:bd276b1f1249 5 you may not use this file except in compliance with the License.
Anubus 0:bd276b1f1249 6 You may obtain a copy of the License at
Anubus 0:bd276b1f1249 7
Anubus 0:bd276b1f1249 8 http://www.apache.org/licenses/LICENSE-2.0
Anubus 0:bd276b1f1249 9
Anubus 0:bd276b1f1249 10 Unless required by applicable law or agreed to in writing,
Anubus 0:bd276b1f1249 11 software distributed under the License is distributed on an
Anubus 0:bd276b1f1249 12 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
Anubus 0:bd276b1f1249 13 either express or implied. See the License for the specific
Anubus 0:bd276b1f1249 14 language governing permissions and limitations under the License.
Anubus 0:bd276b1f1249 15
Anubus 0:bd276b1f1249 16 ======================================================================== */
Anubus 0:bd276b1f1249 17
Anubus 0:bd276b1f1249 18 #ifndef HTS221_H_
Anubus 0:bd276b1f1249 19 #define HTS221_H_
Anubus 0:bd276b1f1249 20
Anubus 0:bd276b1f1249 21 class HTS221 {
Anubus 0:bd276b1f1249 22 public:
Anubus 0:bd276b1f1249 23 HTS221(void);
Anubus 0:bd276b1f1249 24 int begin(void);
Anubus 0:bd276b1f1249 25 int activate(void);
Anubus 0:bd276b1f1249 26 int deactivate(void);
Anubus 0:bd276b1f1249 27
Anubus 0:bd276b1f1249 28 int bduActivate(void);
Anubus 0:bd276b1f1249 29 int bduDeactivate(void);
Anubus 0:bd276b1f1249 30
Anubus 0:bd276b1f1249 31 int readHumidity(void);
Anubus 0:bd276b1f1249 32 double readTemperature(void);
Anubus 0:bd276b1f1249 33 private:
Anubus 0:bd276b1f1249 34 int storeCalibration(void);
Anubus 0:bd276b1f1249 35 unsigned char _h0_rH, _h1_rH;
Anubus 0:bd276b1f1249 36 unsigned int _T0_degC, _T1_degC;
Anubus 0:bd276b1f1249 37 unsigned int _H0_T0, _H1_T0;
Anubus 0:bd276b1f1249 38 unsigned int _T0_OUT, _T1_OUT;
Anubus 0:bd276b1f1249 39 double _temperature;
Anubus 0:bd276b1f1249 40 int _humidity;
Anubus 0:bd276b1f1249 41 unsigned char _address;
Anubus 0:bd276b1f1249 42
Anubus 0:bd276b1f1249 43 unsigned char readRegister(unsigned char slaveAddress, unsigned char regToRead);
Anubus 0:bd276b1f1249 44 int writeRegister(unsigned char slaveAddress, unsigned char regToWrite, unsigned char dataToWrite);
Anubus 0:bd276b1f1249 45 };
Anubus 0:bd276b1f1249 46
Anubus 0:bd276b1f1249 47 #define HTS221_ADDRESS 0xBF
Anubus 0:bd276b1f1249 48
Anubus 0:bd276b1f1249 49 //Define a few of the registers that we will be accessing on the HTS221
Anubus 0:bd276b1f1249 50 #define WHO_AM_I 0x0F
Anubus 0:bd276b1f1249 51 #define WHO_AM_I_RETURN 0xBC //This read-only register contains the device identifier, set to BCh
Anubus 0:bd276b1f1249 52
Anubus 0:bd276b1f1249 53 #define AVERAGE_REG 0x10 // To configure humidity/temperature average.
Anubus 0:bd276b1f1249 54 #define AVERAGE_DEFAULT 0x1B
Anubus 0:bd276b1f1249 55
Anubus 0:bd276b1f1249 56 /*
Anubus 0:bd276b1f1249 57 * [7] PD: power down control
Anubus 0:bd276b1f1249 58 * (0: power-down mode; 1: active mode)
Anubus 0:bd276b1f1249 59 *
Anubus 0:bd276b1f1249 60 * [6:3] Reserved
Anubus 0:bd276b1f1249 61 *
Anubus 0:bd276b1f1249 62 * [2] BDU: block data update
Anubus 0:bd276b1f1249 63 * (0: continuous update; 1: output registers not updated until MSB and LSB reading)
Anubus 0:bd276b1f1249 64 The BDU bit is used to inhibit the output register update between the reading of the upper
Anubus 0:bd276b1f1249 65 and lower register parts. In default mode (BDU = ?0?), the lower and upper register parts are
Anubus 0:bd276b1f1249 66 updated continuously. If it is not certain whether the read will be faster than output data rate,
Anubus 0:bd276b1f1249 67 it is recommended to set the BDU bit to ?1?. In this way, after the reading of the lower (upper)
Anubus 0:bd276b1f1249 68 register part, the content of that output register is not updated until the upper (lower) part is
Anubus 0:bd276b1f1249 69 read also.
Anubus 0:bd276b1f1249 70 *
Anubus 0:bd276b1f1249 71 * [1:0] ODR1, ODR0: output data rate selection (see table 17)
Anubus 0:bd276b1f1249 72 */
Anubus 0:bd276b1f1249 73 #define CTRL_REG1 0x20
Anubus 0:bd276b1f1249 74 #define POWER_UP 0x80
Anubus 0:bd276b1f1249 75 #define BDU_SET 0x4
Anubus 0:bd276b1f1249 76 #define ODR0_SET 0x1 // setting sensor reading period 1Hz
Anubus 0:bd276b1f1249 77
Anubus 0:bd276b1f1249 78 #define CTRL_REG2 0x21
Anubus 0:bd276b1f1249 79 #define CTRL_REG3 0x22
Anubus 0:bd276b1f1249 80 #define REG_DEFAULT 0x00
Anubus 0:bd276b1f1249 81
Anubus 0:bd276b1f1249 82 #define STATUS_REG 0x27
Anubus 0:bd276b1f1249 83 #define TEMPERATURE_READY 0x1
Anubus 0:bd276b1f1249 84 #define HUMIDITY_READY 0x2
Anubus 0:bd276b1f1249 85
Anubus 0:bd276b1f1249 86 #define HUMIDITY_L_REG 0x28
Anubus 0:bd276b1f1249 87 #define HUMIDITY_H_REG 0x29
Anubus 0:bd276b1f1249 88 #define TEMP_L_REG 0x2A
Anubus 0:bd276b1f1249 89 #define TEMP_H_REG 0x2B
Anubus 0:bd276b1f1249 90 /*
Anubus 0:bd276b1f1249 91 * calibration registry should be read for temperature and humidity calculation.
Anubus 0:bd276b1f1249 92 * Before the first calculation of temperature and humidity,
Anubus 0:bd276b1f1249 93 * the master reads out the calibration coefficients.
Anubus 0:bd276b1f1249 94 * will do at init phase
Anubus 0:bd276b1f1249 95 */
Anubus 0:bd276b1f1249 96 #define CALIB_START 0x30
Anubus 0:bd276b1f1249 97 #define CALIB_END 0x3F
Anubus 0:bd276b1f1249 98 /*
Anubus 0:bd276b1f1249 99 #define CALIB_T0_DEGC_X8 0x32
Anubus 0:bd276b1f1249 100 #define CALIB_T1_DEGC_X8 0x33
Anubus 0:bd276b1f1249 101 #define CALIB_T1_T0_MSB 0x35
Anubus 0:bd276b1f1249 102 #define CALIB_T0_OUT_L 0x3C
Anubus 0:bd276b1f1249 103 #define CALIB_T0_OUT_H 0x3D
Anubus 0:bd276b1f1249 104 #define CALIB_T1_OUT_L 0x3E
Anubus 0:bd276b1f1249 105 #define CALIB_T1_OUT_H 0x3F
Anubus 0:bd276b1f1249 106 */
Anubus 0:bd276b1f1249 107
Anubus 0:bd276b1f1249 108 #endif