test code for hdc1080 humidity sensor
Fork of Nucleo-F303K8-SSD1306_OLED by
Diff: hdc_1080.cpp.txt
- Revision:
- 6:c5430cdc9861
- Parent:
- 5:3c91772b714e
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