![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
test code for hdc1080 humidity sensor
Fork of Nucleo-F303K8-SSD1306_OLED by
Revision 6:c5430cdc9861, committed 2016-09-14
- Comitter:
- joeata2wh
- Date:
- Wed Sep 14 02:37:29 2016 +0000
- Parent:
- 5:3c91772b714e
- Commit message:
- working version
Changed in this revision
hdc_1080.cpp.txt | Show diff for this revision Revisions of this file |
hdc_1080.h.txt | Show diff for this revision Revisions of this file |
diff -r 3c91772b714e -r c5430cdc9861 hdc_1080.cpp.txt --- a/hdc_1080.cpp.txt Wed Sep 14 02:36:12 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -/* -Arduino Library for Texas Instruments HDC1080 Digital Humidity and Temperature Sensor -Written by AA for ClosedCube ---- -The MIT License (MIT) -Copyright (c) 2016 ClosedCube Limited -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#include "hdc_1080.h" - - - -ClosedCube_HDC1080::ClosedCube_HDC1080() -{ -} - -char CONFIGURATION[] = "\000\000": - -void ClosedCube_HDC1080::begin(uint8_t address) { - _address = address; - Wire.begin(); - - /* - Heater disabled, - Temperature and Humidity Measurement Resolution 14 bit - */ - Wire.beginTransmission(_address); - Wire.write(CONFIGURATION); - Wire.write(0x0); - Wire.write(0x0); - Wire.endTransmission(); - -} - -float ClosedCube_HDC1080::readT() { - return readTemperature(); -} - -float ClosedCube_HDC1080::readTemperature() { - uint16_t rawT = readData(TEMPERATURE); - return (rawT / pow(2, 16)) * 165 - 40; -} - -float ClosedCube_HDC1080::readH() { - return readHumidity(); -} - -float ClosedCube_HDC1080::readHumidity() { - uint16_t rawH = readData(HUMIDITY); - return (rawH / pow(2, 16)) * 100; -} - -uint16_t ClosedCube_HDC1080::readManufacturerId() { - return readData(MANUFACTURER_ID); -} - -uint16_t ClosedCube_HDC1080::readDeviceId() { - return readData(DEVICE_ID); -} - -uint16_t ClosedCube_HDC1080::readData(uint8_t pointer) { - Wire.beginTransmission(_address); - Wire.write(pointer); - Wire.endTransmission(); - - delay(10); - Wire.requestFrom(_address, 2); - - byte msb = Wire.read(); - byte lsb = Wire.read(); - - return msb << 8 | lsb; -} \ No newline at end of file
diff -r 3c91772b714e -r c5430cdc9861 hdc_1080.h.txt --- a/hdc_1080.h.txt Wed Sep 14 02:36:12 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* -Arduino Library for Texas Instruments HDC1080 Digital Humidity and Temperature Sensor -Written by AA for ClosedCube ---- -The MIT License (MIT) -Copyright (c) 2016 ClosedCube Limited -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef _CLOSEDCUBE_HDC1080_h -#define _CLOSEDCUBE_HDC1080_h -#include "mbed.h" - -I2C i2chdc(I2C_SDA,I2C_SCL); - -typedef enum { - TEMPERATURE = 0x00, - HUMIDITY = 0x01, - CONFIGURATION = 0x02, - MANUFACTURER_ID = 0xFE, - DEVICE_ID = 0xFF, - SERIAL_ID_FIRST = 0xFB, - SERIAL_ID_MID = 0xFC, - SERIAL_ID_LAST = 0xFD, -} HDC1080_Pointers; - -class ClosedCube_HDC1080 { -public: - ClosedCube_HDC1080(); - - void begin(uint8_t address); - uint16_t readManufacturerId(); // 0x5449 ID of Texas Instruments - uint16_t readDeviceId(); // 0x1050 ID of the device - - float readTemperature(); - float readHumidity(); - - float readT(); // short-cut for readTemperature - float readH(); // short-cut for readHumidity - -private: - uint8_t _address; - uint16_t readData(uint8_t pointer); - -}; - -#endif