Closed pikim closed 2 years ago
I have different libraries and some have default addresses, some will get them, some in the constructor and some in begin.
What I learned is that having code in the constructor (e.g. an address) is not always reliable. Somehow the compiler (assumption) messes up the execution order of the code. So I tend to move code from constructor to begin() instead of the other way around.
That said, reading your request between the lines I see you want to have a default address for the class.
So what could be the solution is to add another begin() statement in the .h file
// allow command line option overrule the default address.
#ifndef SHT85_DEFAULT_ADDRESS
#define SHT85_DEFAULT_ADDRESS 0x44
#endif
bool begin(TwoWire *wire = &Wire)
{
return begin(SHT85_DEFAULT_ADDRESS , wire);
}
// similar construct for ESP32
{
#if defined(ESP8266) || defined(ESP32)
bool begin(uint8_t dataPin, uint8_t clockPin)
{
return begin(SHT85_DEFAULT_ADDRESS, dataPin, clockPin);
}
#endif
Could you verify if that works for you?
Currently I'm just preparing my sketch, but I have no hardware available, yet. I'll test it as soon as I have it on my table.
Another question: which version will be maintained in the future? This one or SHT31?
Another question: which version will be maintained in the future?
For the foreseeable future both, currently I try to keep them compatible / interchangeable. Merging is not my highest priority at the moment
Currently I'm just preparing my sketch, but I have no hardware available, yet. I'll test it as soon as I have it on my table.
I crashed my SHT85 due to swapping the pins, it created temperature for a moment instead of measuring it, so I cannot test either (except software only). On my private TODO list is an idea (somewhere LOW) to make an I2C slave Arduino that simulates an SHT sensor. Did such thing for a DHT sensor and except from being useful, I learned a lot from it.
@pikim
Any progress? Close this issue?
Didn't test it, as I have no appropriate hardware, yet.
I have created a develop branch for this issue. Will merge a.s.a.p. please verify if this works for you.
Hi, this is not a bug, but an improvement suggestion: the sensor address could be passed to the constructor to simplify usage a bit. I've seen it in https://github.com/wemos/WEMOS_SHT3x_Arduino_Library but your lib offers more functionality.