0.2.0 CHT8305

This commit is contained in:
Rob Tillaart 2023-12-05 20:46:08 +01:00
parent 581e65e705
commit ce66af044b
12 changed files with 114 additions and 101 deletions

View File

@ -6,13 +6,25 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/). and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.2.0] - 2023-12-05
- refactor API, constructor, begin()
- update readme.md
- rename setHumOffset => **setHumidityOffset()**
- rename getHumOffset => **getHumidityOffset()**
- rename setTempOffset => **setTemperatureOffset()**
- rename getTempOffset => **getTemperatureOffset()**
- update examples
- update keywords.txt
- minor edits
----
## [0.1.7] - 2023-09-21 ## [0.1.7] - 2023-09-21
- add Wire1 support for ESP32 - add Wire1 support for ESP32
- fix humidity offset underflow + overflow. - fix humidity offset underflow + overflow.
- update readme.md - update readme.md
- minor performance optimization in humidity math - minor performance optimization in humidity math
## [0.1.6] - 2023-02-01 ## [0.1.6] - 2023-02-01
- update GitHub actions - update GitHub actions
- update license 2023 - update license 2023

View File

@ -1,11 +1,10 @@
// //
// FILE: CHT8305.cpp // FILE: CHT8305.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.7 // VERSION: 0.2.0
// PURPOSE: Arduino library for CHT8305 temperature and humidity sensor // PURPOSE: Arduino library for CHT8305 temperature and humidity sensor
// URL: https://github.com/RobTillaart/CHT8305 // URL: https://github.com/RobTillaart/CHT8305
//
// HISTORY: see changelog.md
#include "CHT8305.h" #include "CHT8305.h"
@ -14,39 +13,16 @@
// //
// PUBLIC // PUBLIC
// //
CHT8305::CHT8305(TwoWire *wire) CHT8305::CHT8305(const uint8_t address, TwoWire *wire)
{ {
_wire = wire; _wire = wire;
_address = CHT8305_DEFAULT_ADDRESS; // default AD0 to GND. _address = address;
} }
#if defined (ESP8266) || defined(ESP32) int CHT8305::begin()
int CHT8305::begin(int sda, int scl, const uint8_t address)
{ {
if ((address < 0x40) || (address > 0x43)) return CHT8305_ERROR_ADDR; if ((_address < 0x40) || (_address > 0x43)) return CHT8305_ERROR_ADDR;
_address = address;
if ((sda < 255) && (scl < 255))
{
_wire->begin(sda, scl);
} else {
_wire->begin();
}
if (! isConnected()) return CHT8305_ERROR_CONNECT;
return CHT8305_OK;
}
#endif
int CHT8305::begin(const uint8_t address)
{
if ((address < 0x40) || (address > 0x43)) return CHT8305_ERROR_ADDR;
_address = address;
_wire->begin();
if (! isConnected()) return CHT8305_ERROR_CONNECT; if (! isConnected()) return CHT8305_ERROR_CONNECT;
return CHT8305_OK; return CHT8305_OK;
} }
@ -180,29 +156,30 @@ uint8_t CHT8305::getConversionDelay()
} }
void CHT8305::setHumOffset(float offset) void CHT8305::setHumidityOffset(float offset)
{ {
_humOffset = offset; _humOffset = offset;
}; };
void CHT8305::setTempOffset(float offset) void CHT8305::setTemperatureOffset(float offset)
{ {
_tempOffset = offset; _tempOffset = offset;
}; };
float CHT8305::getHumOffset() float CHT8305::getHumidityOffset()
{ {
return _humOffset; return _humOffset;
}; };
float CHT8305::getTempOffset() float CHT8305::getTemperatureOffset()
{ {
return _tempOffset; return _tempOffset;
}; };
//////////////////////////////////////////////// ////////////////////////////////////////////////
// //
// CONFIG REGISTER // CONFIG REGISTER
@ -484,5 +461,5 @@ void CHT8305::_clrConfigMask(uint16_t mask)
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -2,7 +2,7 @@
// //
// FILE: CHT8305.h // FILE: CHT8305.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.7 // VERSION: 0.2.0
// PURPOSE: Arduino library for CHT8305 temperature and humidity sensor // PURPOSE: Arduino library for CHT8305 temperature and humidity sensor
// URL: https://github.com/RobTillaart/CHT8305 // URL: https://github.com/RobTillaart/CHT8305
// //
@ -12,7 +12,7 @@
#include "Wire.h" #include "Wire.h"
#define CHT8305_LIB_VERSION (F("0.1.7")) #define CHT8305_LIB_VERSION (F("0.2.0"))
// DEFAULT ADDRESS // DEFAULT ADDRESS
#ifndef CHT8305_DEFAULT_ADDRESS #ifndef CHT8305_DEFAULT_ADDRESS
@ -54,14 +54,10 @@
class CHT8305 class CHT8305
{ {
public: public:
CHT8305(TwoWire *wire = &Wire); // default address = AD0 to GND.
CHT8305(const uint8_t address = CHT8305_DEFAULT_ADDRESS, TwoWire *wire = &Wire);
#if defined (ESP8266) || defined(ESP32) int begin();
// address is optional
int begin(int sda, int scl, const uint8_t address = CHT8305_DEFAULT_ADDRESS);
#endif
// address is optional
int begin(const uint8_t address = CHT8305_DEFAULT_ADDRESS);
bool isConnected(); bool isConnected();
uint8_t getAddress(); uint8_t getAddress();
@ -82,11 +78,11 @@ public:
// adding offsets works well in normal range // adding offsets works well in normal range
void setHumOffset(float offset); void setHumidityOffset(float offset);
// might introduce under- or overflow at the ends of the sensor range // might introduce under- or overflow at the ends of the sensor range
void setTempOffset(float offset); void setTemperatureOffset(float offset);
float getHumOffset(); float getHumidityOffset();
float getTempOffset(); float getTemperatureOffset();
// CONFIG REGISTER // CONFIG REGISTER
@ -181,5 +177,5 @@ private:
}; };
// -- END OF FILE -- // -- END OF FILE --

View File

@ -34,6 +34,17 @@ One of the interesting functions is the support of an ALERT function.
This prevents the need for continuous polling of the sensor. This prevents the need for continuous polling of the sensor.
#### 0.2.0 Breaking change
Version 0.2.0 introduced a breaking change.
You cannot set the pins in **begin()** any more.
This reduces the dependency of processor dependent Wire implementations.
The user has to call **Wire.begin()** and can optionally set the Wire pins
before calling **begin()**.
Moved the address parameter from **begin()** to constructor.
#### Tests #### Tests
- Temperature and humidity functions works on AVR. - Temperature and humidity functions works on AVR.
@ -108,9 +119,10 @@ Pull ups are needed on SDA, SCL and optional to ALERT.
#### Constructor #### Constructor
- **CHT8305(TwoWire \*wire = &Wire)** Constructor with default I2C bus. - **CHT8305(const uint8_t address = CHT8305_DEFAULT_ADDRESS, TwoWire \*wire = &Wire)** Constructor
- **int begin(const uint8_t address = CHT8305_DEFAULT_ADDRESS)** sets address, default = 0x40. with default address (0x40) and I2C bus.
- **int begin(int sda, int scl, const uint8_t address = CHT8305_DEFAULT_ADDRESS)** idem for ESP32 et. al. - **int begin()** initializes internals.
Returns error status.
- **bool isConnected()** checks if address (default 0x40) can be seen on the I2C bus. - **bool isConnected()** checks if address (default 0x40) can be seen on the I2C bus.
@ -146,10 +158,10 @@ Adding offsets works well in the "normal range" but might introduce
under- or overflow at the ends of the sensor range. under- or overflow at the ends of the sensor range.
These are not handled for temperature by the library (humidity since 0.1.7). These are not handled for temperature by the library (humidity since 0.1.7).
- **void setHumOffset(float offset)** idem. - **void setHumidityOffset(float offset)** idem.
- **void setTempOffset(float offset)** idem. - **void setTemperatureOffset(float offset)** idem.
- **float getHumOffset()** idem. - **float getHumidityOffset()** idem.
- **float getTempOffset()** idem. - **float getTemperatureOffset()** idem.
If the offset is not the same over the operational range, If the offset is not the same over the operational range,
consider a mapping function for temperature and humidity. consider a mapping function for temperature and humidity.
@ -289,7 +301,6 @@ See datasheet page 10 for details
#### Could #### Could
- make offset functions "full name" e.g. **setHumidityOffset()** (0.2,0)
- parameter testing - parameter testing
- parameter defaults? - parameter defaults?

View File

@ -27,21 +27,21 @@
#include "CHT8305.h" #include "CHT8305.h"
CHT8305 CHT; CHT8305 CHT(0x40); // CHT8305_DEFAULT_ADDRESS = 0x40
void setup() void setup()
{ {
CHT.begin(0x40); // CHT8305_DEFAULT_ADDRESS = 0x40
Wire.setClock(400000);
Serial.begin(115200); Serial.begin(115200);
Serial.println(__FILE__); Serial.println(__FILE__);
Serial.print("CHT8305_LIB_VERSION: "); Serial.print("CHT8305_LIB_VERSION: ");
Serial.println(CHT8305_LIB_VERSION); Serial.println(CHT8305_LIB_VERSION);
Serial.println(); Serial.println();
Wire.begin();
Wire.setClock(400000);
CHT.begin();
CHT.setVCCenable(true); CHT.setVCCenable(true);
Serial.println("voltage\t us"); Serial.println("voltage\t us");
@ -54,7 +54,7 @@ void loop()
if (millis() - CHT.lastRead() >= 1000) if (millis() - CHT.lastRead() >= 1000)
{ {
CHT.read(); CHT.read();
// READ DATA // READ DATA
uint32_t start = micros(); uint32_t start = micros();
float voltage = CHT.getVoltage(); float voltage = CHT.getVoltage();
uint32_t stop = micros(); uint32_t stop = micros();
@ -71,4 +71,4 @@ void loop()
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -25,15 +25,20 @@
#include "CHT8305.h" #include "CHT8305.h"
CHT8305 CHT; CHT8305 CHT(0x40); // CHT8305_DEFAULT_ADDRESS = 0x40
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("CHT8305_LIB_VERSION: ");
Serial.println(CHT8305_LIB_VERSION);
Serial.println();
CHT.begin(0x40); // CHT8305_DEFAULT_ADDRESS = 0x40 Wire.begin();
Wire.setClock(400000); Wire.setClock(400000);
CHT.begin();
delay(1000); delay(1000);
} }
@ -43,7 +48,7 @@ void loop()
{ {
if (millis() - CHT.lastRead() >= 1000) if (millis() - CHT.lastRead() >= 1000)
{ {
// READ DATA // READ DATA
CHT.read(); CHT.read();
Serial.print(millis()); Serial.print(millis());
@ -55,4 +60,4 @@ void loop()
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -25,7 +25,7 @@
#include "CHT8305.h" #include "CHT8305.h"
CHT8305 CHT; CHT8305 CHT(0x40); // CHT8305_DEFAULT_ADDRESS = 0x40
uint32_t start, stop; uint32_t start, stop;
@ -33,13 +33,18 @@ uint32_t start, stop;
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("CHT8305_LIB_VERSION: ");
Serial.println(CHT8305_LIB_VERSION);
Serial.println();
CHT.begin(0x40); // CHT8305_DEFAULT_ADDRESS = 0x40 Wire.begin();
Wire.setClock(400000); Wire.setClock(400000);
CHT.begin();
delay(1000); delay(1000);
CHT.setConversionDelay(10); // CHT.setConversionDelay(10);
CHT.setTemperatureResolution(0); // 14 bit CHT.setTemperatureResolution(0); // 14 bit
CHT.setHumidityResolution(0); // 14 bit CHT.setHumidityResolution(0); // 14 bit
@ -99,8 +104,7 @@ void setup()
void loop() void loop()
{ {
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -25,23 +25,23 @@
#include "CHT8305.h" #include "CHT8305.h"
CHT8305 CHT; CHT8305 CHT(0x40); // CHT8305_DEFAULT_ADDRESS = 0x40
uint8_t count = 0; uint8_t count = 0;
void setup() void setup()
{ {
CHT.begin(0x40); // CHT8305_DEFAULT_ADDRESS = 0x40
Wire.setClock(400000);
Serial.begin(115200); Serial.begin(115200);
Serial.println(__FILE__); Serial.println(__FILE__);
Serial.print("CHT8305_LIB_VERSION: "); Serial.print("CHT8305_LIB_VERSION: ");
Serial.println(CHT8305_LIB_VERSION); Serial.println(CHT8305_LIB_VERSION);
Serial.println(); Serial.println();
Wire.begin();
Wire.setClock(400000);
CHT.begin();
Serial.println(CHT.getManufacturer(), HEX); Serial.println(CHT.getManufacturer(), HEX);
Serial.println(CHT.getVersionID(), HEX); Serial.println(CHT.getVersionID(), HEX);
Serial.println(CHT.getVoltage()); Serial.println(CHT.getVoltage());
@ -54,7 +54,7 @@ void loop()
{ {
if (millis() - CHT.lastRead() >= 1000) if (millis() - CHT.lastRead() >= 1000)
{ {
// READ DATA // READ DATA
uint32_t start = micros(); uint32_t start = micros();
int status = CHT.read(); int status = CHT.read();
uint32_t stop = micros(); uint32_t stop = micros();
@ -68,7 +68,7 @@ void loop()
count++; count++;
Serial.print("CHT8305\t"); Serial.print("CHT8305\t");
// DISPLAY DATA, sensor has only one decimal. // DISPLAY DATA, sensor has only one decimal.
Serial.print(CHT.getHumidity(), 1); Serial.print(CHT.getHumidity(), 1);
Serial.print("\t\t"); Serial.print("\t\t");
Serial.print(CHT.getTemperature(), 1); Serial.print(CHT.getTemperature(), 1);
@ -101,4 +101,4 @@ void loop()
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -15,10 +15,10 @@ getHumidity KEYWORD2
setConversionDelay KEYWORD2 setConversionDelay KEYWORD2
getConversionDelay KEYWORD2 getConversionDelay KEYWORD2
setHumOffset KEYWORD2 setHumidityOffset KEYWORD2
setTempOffset KEYWORD2 setTemperatureOffset KEYWORD2
getHumOffset KEYWORD2 getHumidityOffset KEYWORD2
getTempOffset KEYWORD2 getTemperatureOffset KEYWORD2
setConfigRegister KEYWORD2 setConfigRegister KEYWORD2
getConfigRegister KEYWORD2 getConfigRegister KEYWORD2
@ -27,7 +27,7 @@ softReset KEYWORD2
setI2CClockStretch KEYWORD2 setI2CClockStretch KEYWORD2
getI2CClockStretch KEYWORD2 getI2CClockStretch KEYWORD2
setHeaterOn KEYWORD2 setHeaterOn KEYWORD2
getHeate KEYWORD2 getHeater KEYWORD2
setMeasurementMode KEYWORD2 setMeasurementMode KEYWORD2
getMeasurementMode KEYWORD2 getMeasurementMode KEYWORD2

View File

@ -15,7 +15,7 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/CHT8305.git" "url": "https://github.com/RobTillaart/CHT8305.git"
}, },
"version": "0.1.7", "version": "0.2.0",
"license": "MIT", "license": "MIT",
"frameworks": "*", "frameworks": "*",
"platforms": "*", "platforms": "*",

View File

@ -1,5 +1,5 @@
name=CHT8305 name=CHT8305
version=0.1.7 version=0.2.0
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for CHT8305 temperature and humidity sensor. sentence=Arduino library for CHT8305 temperature and humidity sensor.

View File

@ -81,21 +81,23 @@ unittest(test_constants_III)
unittest(test_offset) unittest(test_offset)
{ {
CHT8305 cht; CHT8305 cht(0x40);
Wire.begin();
// default hum = 0 // default hum = 0
assertEqualFloat(0.0, cht.getHumOffset(), 0.01); assertEqualFloat(0.0, cht.getHumidityOffset(), 0.01);
cht.setHumOffset(12.34); cht.setHumidityOffset(12.34);
assertEqualFloat(12.34, cht.getHumOffset(), 0.01); assertEqualFloat(12.34, cht.getHumidityOffset(), 0.01);
cht.setHumOffset(0.0); cht.setHumidityOffset(0.0);
assertEqualFloat(0.0, cht.getHumOffset(), 0.01); assertEqualFloat(0.0, cht.getHumidityOffset(), 0.01);
// default temp = 0 // default temp = 0
assertEqualFloat(0.0, cht.getTempOffset(), 0.01); assertEqualFloat(0.0, cht.getTemperatureOffset(), 0.01);
cht.setTempOffset(12.34); cht.setTemperatureOffset(12.34);
assertEqualFloat(12.34, cht.getTempOffset(), 0.01); assertEqualFloat(12.34, cht.getTemperatureOffset(), 0.01);
cht.setTempOffset(0.0); cht.setTemperatureOffset(0.0);
assertEqualFloat(0.0, cht.getTempOffset(), 0.01); assertEqualFloat(0.0, cht.getTemperatureOffset(), 0.01);
} }
@ -103,6 +105,8 @@ unittest(test_lastRead)
{ {
CHT8305 cht; CHT8305 cht;
Wire.begin();
assertEqual(0, cht.lastRead()); assertEqual(0, cht.lastRead());
} }
@ -111,6 +115,8 @@ unittest(test_AlertTriggerMode)
{ {
CHT8305 cht; CHT8305 cht;
Wire.begin();
// test range check only false can be checked // test range check only false can be checked
for (int mode = 4; mode < 10; mode++) for (int mode = 4; mode < 10; mode++)
{ {
@ -124,6 +130,8 @@ unittest(test_setAlertLevels)
{ {
CHT8305 cht; CHT8305 cht;
Wire.begin();
// temp range check only false can be checked // temp range check only false can be checked
assertFalse(cht.setAlertLevels(-41, 50)); assertFalse(cht.setAlertLevels(-41, 50));
assertFalse(cht.setAlertLevels(126, 50)); assertFalse(cht.setAlertLevels(126, 50));