mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.5 CHT8305
This commit is contained in:
parent
9fffc38114
commit
c8c9f1177a
@ -24,4 +24,5 @@ compile:
|
||||
- esp32
|
||||
- esp8266
|
||||
# - mega2560
|
||||
- rpipico
|
||||
- rpipico
|
||||
|
||||
|
42
libraries/CHT8305/CHANGELOG.md
Normal file
42
libraries/CHT8305/CHANGELOG.md
Normal file
@ -0,0 +1,42 @@
|
||||
# Change Log CHT8305
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
----
|
||||
|
||||
## [0.1.5] - 2022-10-29
|
||||
- fix changelog.md
|
||||
- add readTemperature()
|
||||
- add readHumidity()
|
||||
|
||||
|
||||
## [0.1.4] - 2022-10-15
|
||||
- add CHT8305_DEFAULT_ADDRESS (0x40).
|
||||
- add CHANGELOG.md.
|
||||
- minor refactor.
|
||||
- update readme.md.
|
||||
|
||||
## [0.1.3] - 2022-10-13
|
||||
- adjust getVoltage() formula. (still unclear).
|
||||
- update readme.md (some AVR test results).
|
||||
- add get- setConversionDelay().
|
||||
|
||||
## [0.1.2] - 2022-10-09
|
||||
- update unit tests.
|
||||
- fix humidity resolution parameter.
|
||||
- fix setAlertLevels().
|
||||
- refactor, move code to .cpp file.
|
||||
|
||||
## [0.1.1] - 2022-10-08
|
||||
- add configuration specific functions.
|
||||
- fix ESP32 begin() address check.
|
||||
- add configuration ALERT functions.
|
||||
- add constants for registers.
|
||||
- fix getVoltage() register.
|
||||
|
||||
## [0.1.0] - 2022-10-06
|
||||
- initial version.
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: CHT8305.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.4
|
||||
// VERSION: 0.1.5
|
||||
// PURPOSE: Arduino library for CHT8305 temperature and humidity sensor
|
||||
// URL: https://github.com/RobTillaart/CH8305
|
||||
//
|
||||
@ -60,6 +60,12 @@ bool CHT8305::isConnected()
|
||||
}
|
||||
|
||||
|
||||
uint8_t CHT8305::getAddress()
|
||||
{
|
||||
return _address;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
//
|
||||
// READ THE SENSOR
|
||||
@ -88,6 +94,48 @@ int CHT8305::read()
|
||||
}
|
||||
|
||||
|
||||
int CHT8305::readTemperature()
|
||||
{
|
||||
// do not read too fast
|
||||
if (millis() - _lastRead < 1000)
|
||||
{
|
||||
return CHT8305_ERROR_LASTREAD;
|
||||
}
|
||||
_lastRead = millis();
|
||||
|
||||
uint8_t data[2] = {0, 0};
|
||||
_readRegister(CHT8305_REG_TEMPERATURE, &data[0], 2);
|
||||
|
||||
uint16_t tmp = data[0] << 8 | data[1];
|
||||
_temperature = tmp * (165.0 / 65535.0) - 40.0;
|
||||
|
||||
if (_tempOffset != 0.0) _temperature += _tempOffset;
|
||||
|
||||
return CHT8305_OK;
|
||||
}
|
||||
|
||||
|
||||
int CHT8305::readHumidity()
|
||||
{
|
||||
// do not read too fast
|
||||
if (millis() - _lastRead < 1000)
|
||||
{
|
||||
return CHT8305_ERROR_LASTREAD;
|
||||
}
|
||||
_lastRead = millis();
|
||||
|
||||
uint8_t data[2] = {0, 0};
|
||||
_readRegister(CHT8305_REG_HUMIDITY, &data[0], 2);
|
||||
|
||||
uint16_t tmp = data[0] << 8 | data[1];
|
||||
_humidity = tmp / 655.35; // == / 65535 * 100%
|
||||
|
||||
if (_humOffset != 0.0) _humidity += _humOffset;
|
||||
|
||||
return CHT8305_OK;
|
||||
}
|
||||
|
||||
|
||||
// MilliSeconds since start sketch
|
||||
uint32_t CHT8305::lastRead()
|
||||
{
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: CHT8305.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.4
|
||||
// VERSION: 0.1.5
|
||||
// PURPOSE: Arduino library for CHT8305 temperature and humidity sensor
|
||||
// URL: https://github.com/RobTillaart/CH8305
|
||||
//
|
||||
@ -12,7 +12,7 @@
|
||||
#include "Wire.h"
|
||||
|
||||
|
||||
#define CHT8305_LIB_VERSION (F("0.1.4"))
|
||||
#define CHT8305_LIB_VERSION (F("0.1.5"))
|
||||
|
||||
// DEFAULT ADDRESS
|
||||
#ifndef CHT8305_DEFAULT_ADDRESS
|
||||
@ -63,9 +63,16 @@ public:
|
||||
// address and writeProtectPin is optional
|
||||
int begin(const uint8_t address = CHT8305_DEFAULT_ADDRESS);
|
||||
bool isConnected();
|
||||
uint8_t getAddress();
|
||||
|
||||
// read the temperature and humidity.
|
||||
|
||||
// read both the temperature and humidity.
|
||||
int read();
|
||||
// read only temperature (slightly faster)
|
||||
int readTemperature();
|
||||
// read only humidity (slightly faster)
|
||||
int readHumidity();
|
||||
|
||||
// lastRead is in MilliSeconds since start sketch
|
||||
uint32_t lastRead();
|
||||
float getHumidity();
|
||||
@ -73,6 +80,7 @@ public:
|
||||
void setConversionDelay(uint8_t cd = 14);
|
||||
uint8_t getConversionDelay();
|
||||
|
||||
|
||||
// adding offsets works well in normal range
|
||||
// might introduce under- or overflow at the ends of the sensor range
|
||||
void setHumOffset(float offset);
|
||||
@ -80,6 +88,7 @@ public:
|
||||
float getHumOffset();
|
||||
float getTempOffset();
|
||||
|
||||
|
||||
// CONFIG REGISTER
|
||||
void setConfigRegister(uint16_t bitmask);
|
||||
uint16_t getConfigRegister();
|
||||
@ -107,7 +116,8 @@ public:
|
||||
void setI2CClockStretch(bool on = false);
|
||||
bool getI2CClockStretch();
|
||||
|
||||
void setHeaterOn(bool on = false); // WARNING: user is responsible for timing!
|
||||
// WARNING: user is responsible for timing! WARNING!
|
||||
void setHeaterOn(bool on = false);
|
||||
bool getHeater();
|
||||
|
||||
void setMeasurementMode(bool both = true);
|
||||
@ -115,11 +125,13 @@ public:
|
||||
|
||||
bool getVCCstatus();
|
||||
|
||||
void setTemperatureResolution(uint8_t res = 0); // 1 = 11 bit, other = 14 bit
|
||||
// 1 = 11 bit, other = 14 bit
|
||||
void setTemperatureResolution(uint8_t res = 0);
|
||||
uint8_t getTemperatureResolution();
|
||||
|
||||
void setHumidityResolution(uint8_t res = 0); // 2 = 8 bit, 1 = 11 bit, other = 14 bit
|
||||
uint8_t getHumidityResolution(); // idem
|
||||
// 2 = 8 bit, 1 = 11 bit, other = 14 bit
|
||||
void setHumidityResolution(uint8_t res = 0);
|
||||
uint8_t getHumidityResolution();
|
||||
|
||||
void setVCCenable(bool enable = true);
|
||||
bool getVCCenable();
|
||||
@ -130,7 +142,7 @@ public:
|
||||
// 1 T
|
||||
// 2 H
|
||||
// 3 T and H
|
||||
bool setAlertTriggerMode(uint8_t mode = 0); // 0, 1, 2, 3
|
||||
bool setAlertTriggerMode(uint8_t mode = 0);
|
||||
uint8_t getAlertTriggerMode();
|
||||
bool getAlertPendingStatus();
|
||||
bool getAlertHumidityStatus();
|
||||
@ -149,6 +161,7 @@ public:
|
||||
uint16_t getManufacturer(); // expect 0x5959
|
||||
uint16_t getVersionID(); // may vary
|
||||
|
||||
|
||||
private:
|
||||
float _humOffset = 0.0;
|
||||
float _tempOffset = 0.0;
|
||||
|
@ -110,12 +110,18 @@ Pull ups are needed on SDA, SCL and optional to ALERT.
|
||||
- **int begin(int sda, int scl, const uint8_t address = CHT8305_DEFAULT_ADDRESS)** idem ESP32 et. al.
|
||||
- **bool isConnected()** checks if address can be seen on the I2C bus.
|
||||
- **int read()** reads both the temperature and humidity.
|
||||
Can be called once per second.
|
||||
- **int readTemperature()** read only temperature (slightly faster than read)
|
||||
- **int readHumidity()** read only humidity (slightly faster than read)
|
||||
- **uint32_t lastRead()** returns lastRead in MilliSeconds since start sketch.
|
||||
- **float getHumidity()** returns last humidity read.
|
||||
Will return the same value until **read()** is called again.
|
||||
- **float getTemperature()** returns last temperature read.
|
||||
Will return the same value until **read()** is called again.
|
||||
|
||||
Note: read(), readTemperature() and readHumidity() blocks each other,
|
||||
so you can call one of them every second.
|
||||
|
||||
|
||||
### Conversion delay
|
||||
|
||||
@ -252,9 +258,6 @@ Test returned 0x8305.
|
||||
- test ALERT functions.
|
||||
- test write / readRegister with a single uint16_t to simplify code.
|
||||
|
||||
### Could
|
||||
#### Could
|
||||
|
||||
- add **uint8_t getAddress()**
|
||||
- add **void readTemperature()** does single acquisition.
|
||||
- add **void readHumidity()** does single acquisition.
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/CHT8305.git"
|
||||
},
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=CHT8305
|
||||
version=0.1.4
|
||||
version=0.1.5
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for CHT8305 temperature and humidity sensor.
|
||||
|
Loading…
Reference in New Issue
Block a user