![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Smart
HTU21D.h@0:69293b19ee19, 2018-02-28 (annotated)
- Committer:
- Team_Eta_MBED
- Date:
- Wed Feb 28 16:34:40 2018 +0000
- Revision:
- 0:69293b19ee19
Smart Baby Monitor Foundations
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Team_Eta_MBED | 0:69293b19ee19 | 1 | /** |
Team_Eta_MBED | 0:69293b19ee19 | 2 | * EE 4391 Senior Design |
Team_Eta_MBED | 0:69293b19ee19 | 3 | * Professor Hinkle and Dr. Compeau |
Team_Eta_MBED | 0:69293b19ee19 | 4 | * @author Team Eta |
Team_Eta_MBED | 0:69293b19ee19 | 5 | * Texas State University |
Team_Eta_MBED | 0:69293b19ee19 | 6 | * |
Team_Eta_MBED | 0:69293b19ee19 | 7 | * @section DESCRIPTION |
Team_Eta_MBED | 0:69293b19ee19 | 8 | * |
Team_Eta_MBED | 0:69293b19ee19 | 9 | * Honeywell HTU21D Humidity and Temperature sensor. |
Team_Eta_MBED | 0:69293b19ee19 | 10 | * Datasheet, specs, and information: |
Team_Eta_MBED | 0:69293b19ee19 | 11 | * https://cdn.sparkfun.com/assets/6/a/8/e/f/525778d4757b7f50398b4567.pdf |
Team_Eta_MBED | 0:69293b19ee19 | 12 | */ |
Team_Eta_MBED | 0:69293b19ee19 | 13 | |
Team_Eta_MBED | 0:69293b19ee19 | 14 | #ifndef HTU21D_H |
Team_Eta_MBED | 0:69293b19ee19 | 15 | #define HTU21D_H |
Team_Eta_MBED | 0:69293b19ee19 | 16 | |
Team_Eta_MBED | 0:69293b19ee19 | 17 | /** |
Team_Eta_MBED | 0:69293b19ee19 | 18 | * Includes |
Team_Eta_MBED | 0:69293b19ee19 | 19 | */ |
Team_Eta_MBED | 0:69293b19ee19 | 20 | #include "mbed.h" |
Team_Eta_MBED | 0:69293b19ee19 | 21 | |
Team_Eta_MBED | 0:69293b19ee19 | 22 | /** |
Team_Eta_MBED | 0:69293b19ee19 | 23 | * Defines |
Team_Eta_MBED | 0:69293b19ee19 | 24 | */ |
Team_Eta_MBED | 0:69293b19ee19 | 25 | // Acquired from Datasheet. |
Team_Eta_MBED | 0:69293b19ee19 | 26 | |
Team_Eta_MBED | 0:69293b19ee19 | 27 | #define HTU21D_I2C_ADDRESS 0x40 |
Team_Eta_MBED | 0:69293b19ee19 | 28 | #define TRIGGER_TEMP_MEASURE 0xE3 |
Team_Eta_MBED | 0:69293b19ee19 | 29 | #define TRIGGER_HUMD_MEASURE 0xE5 |
Team_Eta_MBED | 0:69293b19ee19 | 30 | |
Team_Eta_MBED | 0:69293b19ee19 | 31 | |
Team_Eta_MBED | 0:69293b19ee19 | 32 | //Commands. |
Team_Eta_MBED | 0:69293b19ee19 | 33 | #define HTU21D_EEPROM_WRITE 0x80 |
Team_Eta_MBED | 0:69293b19ee19 | 34 | #define HTU21D_EEPROM_READ 0x81 |
Team_Eta_MBED | 0:69293b19ee19 | 35 | |
Team_Eta_MBED | 0:69293b19ee19 | 36 | |
Team_Eta_MBED | 0:69293b19ee19 | 37 | /** |
Team_Eta_MBED | 0:69293b19ee19 | 38 | * Honeywell HTU21D digital humidity and temperature sensor. |
Team_Eta_MBED | 0:69293b19ee19 | 39 | */ |
Team_Eta_MBED | 0:69293b19ee19 | 40 | class HTU21D { |
Team_Eta_MBED | 0:69293b19ee19 | 41 | |
Team_Eta_MBED | 0:69293b19ee19 | 42 | public: |
Team_Eta_MBED | 0:69293b19ee19 | 43 | |
Team_Eta_MBED | 0:69293b19ee19 | 44 | /** |
Team_Eta_MBED | 0:69293b19ee19 | 45 | * Constructor. |
Team_Eta_MBED | 0:69293b19ee19 | 46 | * |
Team_Eta_MBED | 0:69293b19ee19 | 47 | * @param sda mbed pin to use for SDA line of I2C interface. |
Team_Eta_MBED | 0:69293b19ee19 | 48 | * @param scl mbed pin to use for SCL line of I2C interface. |
Team_Eta_MBED | 0:69293b19ee19 | 49 | */ |
Team_Eta_MBED | 0:69293b19ee19 | 50 | HTU21D(PinName sda, PinName scl); |
Team_Eta_MBED | 0:69293b19ee19 | 51 | |
Team_Eta_MBED | 0:69293b19ee19 | 52 | |
Team_Eta_MBED | 0:69293b19ee19 | 53 | //Samples the temperature, input void, outputs an int in celcius. |
Team_Eta_MBED | 0:69293b19ee19 | 54 | int sample_ctemp(void); |
Team_Eta_MBED | 0:69293b19ee19 | 55 | |
Team_Eta_MBED | 0:69293b19ee19 | 56 | //Samples the temperature, input void, outputs an int in fahrenheit. |
Team_Eta_MBED | 0:69293b19ee19 | 57 | int sample_ftemp(void); |
Team_Eta_MBED | 0:69293b19ee19 | 58 | |
Team_Eta_MBED | 0:69293b19ee19 | 59 | //Samples the temperature, input void, outputs an int in kelvin. |
Team_Eta_MBED | 0:69293b19ee19 | 60 | int sample_ktemp(void); |
Team_Eta_MBED | 0:69293b19ee19 | 61 | |
Team_Eta_MBED | 0:69293b19ee19 | 62 | //Samples the humidity, input void, outputs and int. |
Team_Eta_MBED | 0:69293b19ee19 | 63 | int sample_humid(void); |
Team_Eta_MBED | 0:69293b19ee19 | 64 | |
Team_Eta_MBED | 0:69293b19ee19 | 65 | |
Team_Eta_MBED | 0:69293b19ee19 | 66 | |
Team_Eta_MBED | 0:69293b19ee19 | 67 | private: |
Team_Eta_MBED | 0:69293b19ee19 | 68 | |
Team_Eta_MBED | 0:69293b19ee19 | 69 | I2C* i2c_; |
Team_Eta_MBED | 0:69293b19ee19 | 70 | |
Team_Eta_MBED | 0:69293b19ee19 | 71 | /** |
Team_Eta_MBED | 0:69293b19ee19 | 72 | * Write to EEPROM or RAM on the device. |
Team_Eta_MBED | 0:69293b19ee19 | 73 | * |
Team_Eta_MBED | 0:69293b19ee19 | 74 | * @param EepromOrRam 0x80 -> Writing to EEPROM |
Team_Eta_MBED | 0:69293b19ee19 | 75 | * @param address Address to write to. |
Team_Eta_MBED | 0:69293b19ee19 | 76 | * @param data Data to write. |
Team_Eta_MBED | 0:69293b19ee19 | 77 | */ |
Team_Eta_MBED | 0:69293b19ee19 | 78 | void write(int EepromOrRam, int address, int data); |
Team_Eta_MBED | 0:69293b19ee19 | 79 | |
Team_Eta_MBED | 0:69293b19ee19 | 80 | /** |
Team_Eta_MBED | 0:69293b19ee19 | 81 | * Read EEPROM or RAM on the device. |
Team_Eta_MBED | 0:69293b19ee19 | 82 | * |
Team_Eta_MBED | 0:69293b19ee19 | 83 | * @param EepromOrRam 0x81 -> Reading from EEPROM |
Team_Eta_MBED | 0:69293b19ee19 | 84 | * @param address Address to read from. |
Team_Eta_MBED | 0:69293b19ee19 | 85 | * @return The contents of the memory address. |
Team_Eta_MBED | 0:69293b19ee19 | 86 | */ |
Team_Eta_MBED | 0:69293b19ee19 | 87 | int read(int EepromOrRam, int address); |
Team_Eta_MBED | 0:69293b19ee19 | 88 | |
Team_Eta_MBED | 0:69293b19ee19 | 89 | }; |
Team_Eta_MBED | 0:69293b19ee19 | 90 | |
Team_Eta_MBED | 0:69293b19ee19 | 91 | #endif /* HTU21D_H */ |