RobTillaart / SHT31

Arduino library for the SHT31 temperature and humidity sensor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

prototype for 'bool SHT31::begin(uint8_t, uint8_t, uint8_t)' does not match any in class 'SHT31'

StefanL38 opened this issue · comments

I tried to compile the example SHT31_I2Cspeed but get a compiler-error

That's what I love best about "examples" if not even the examples compile
heres the full error-message

`C:\Users\Stefan\Documents\Arduino\libraries\SHT31\SHT31.cpp:47:6: error: prototype for 'bool SHT31::begin(uint8_t, uint8_t, uint8_t)' does not match any in class 'SHT31'

bool SHT31::begin(const uint8_t address, const uint8_t dataPin, const uint8_t clockPin)

  ^

In file included from C:\Users\Stefan\Documents\Arduino\libraries\SHT31\SHT31.cpp:21:0:

C:\Users\Stefan\Documents\Arduino\libraries\SHT31\SHT31.h:35:8: error: candidates are: bool SHT31::begin(uint8_t, TwoWire*)

bool begin(const uint8_t address, TwoWire *wire);

    ^

C:\Users\Stefan\Documents\Arduino\libraries\SHT31\SHT31.h:34:8: error: bool SHT31::begin(uint8_t)

bool begin(const uint8_t address);

    ^

C:\Users\Stefan\Documents\Arduino\libraries\SHT31\SHT31.h:32:8: error: void SHT31::begin(uint8_t, uint8_t, uint8_t)

void begin(const uint8_t address, uint8_t dataPin, uint8_t clockPin);

    ^

C:\Users\Stefan\Documents\Arduino\libraries\SHT31\SHT31.cpp: In member function 'void SHT31::setHeatTimeout(uint8_t)':

C:\Users\Stefan\Documents\Arduino\libraries\SHT31\SHT31.cpp:137:34: error: no matching function for call to 'min(int, uint8_t&)'

_heatTimeOut = min(180, seconds);

                              ^

C:\Users\Stefan\Documents\Arduino\libraries\SHT31\SHT31.cpp:137:34: note: candidates are:

In file included from c:\users\stefan\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\algorithm:62:0,

             from C:\Users\Stefan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266/Arduino.h:237,

             from C:\Users\Stefan\Documents\Arduino\libraries\SHT31\SHT31.h:12,

             from C:\Users\Stefan\Documents\Arduino\libraries\SHT31\SHT31.cpp:21:

c:\users\stefan\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\bits\stl_algo.h:4226:5: note: template<class _Tp, class _Compare> _Tp std::min(std::initializer_list<_Tp>, _Compare)

 min(initializer_list<_Tp> __l, _Compare __comp)

 ^

c:\users\stefan\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\bits\stl_algo.h:4226:5: note: template argument deduction/substitution failed:

C:\Users\Stefan\Documents\Arduino\libraries\SHT31\SHT31.cpp:137:34: note: mismatched types 'std::initializer_list<_Tp>' and 'int'

_heatTimeOut = min(180, seconds);

                              ^

In file included from c:\users\stefan\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\algorithm:62:0,

             from C:\Users\Stefan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266/Arduino.h:237,

             from C:\Users\Stefan\Documents\Arduino\libraries\SHT31\SHT31.h:12,

             from C:\Users\Stefan\Documents\Arduino\libraries\SHT31\SHT31.cpp:21:

c:\users\stefan\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\bits\stl_algo.h:4221:5: note: template _Tp std::min(std::initializer_list<_Tp>)

 min(initializer_list<_Tp> __l)

 ^

c:\users\stefan\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\bits\stl_algo.h:4221:5: note: template argument deduction/substitution failed:

C:\Users\Stefan\Documents\Arduino\libraries\SHT31\SHT31.cpp:137:34: note: mismatched types 'std::initializer_list<_Tp>' and 'int'

_heatTimeOut = min(180, seconds);

                              ^

In file included from c:\users\stefan\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\algorithm:61:0,

             from C:\Users\Stefan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266/Arduino.h:237,

             from C:\Users\Stefan\Documents\Arduino\libraries\SHT31\SHT31.h:12,

             from C:\Users\Stefan\Documents\Arduino\libraries\SHT31\SHT31.cpp:21:

c:\users\stefan\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\bits\stl_algobase.h:239:5: note: template<class _Tp, class _Compare> const _Tp& std::min(const _Tp&, const _Tp&, _Compare)

 min(const _Tp& __a, const _Tp& __b, _Compare __comp)

 ^

c:\users\stefan\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\bits\stl_algobase.h:239:5: note: template argument deduction/substitution failed:

C:\Users\Stefan\Documents\Arduino\libraries\SHT31\SHT31.cpp:137:34: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'uint8_t {aka unsigned char}')

_heatTimeOut = min(180, seconds);

                              ^

In file included from c:\users\stefan\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\algorithm:61:0,

             from C:\Users\Stefan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266/Arduino.h:237,

             from C:\Users\Stefan\Documents\Arduino\libraries\SHT31\SHT31.h:12,

             from C:\Users\Stefan\Documents\Arduino\libraries\SHT31\SHT31.cpp:21:

c:\users\stefan\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\bits\stl_algobase.h:193:5: note: template const _Tp& std::min(const _Tp&, const _Tp&)

 min(const _Tp& __a, const _Tp& __b)

 ^

c:\users\stefan\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\bits\stl_algobase.h:193:5: note: template argument deduction/substitution failed:

C:\Users\Stefan\Documents\Arduino\libraries\SHT31\SHT31.cpp:137:34: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'uint8_t {aka unsigned char}')

_heatTimeOut = min(180, seconds);

                              ^

Bibliothek Wire in Version 1.0 im Ordner: C:\Users\Stefan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\Wire wird verwendet
Bibliothek SHT31 in Version 0.2.1 im Ordner: C:\Users\Stefan\Documents\Arduino\libraries\SHT31 wird verwendet
exit status 1
Fehler beim Kompilieren für das Board Generic ESP8266 Module.
`

Good morning Stefan,

I tested the examples mainly with an UNO, but I understand you use them with an ESP8266 module.
Can you confirm?
Did you test the other examples?
Did that result in the same error message (no need to dump them here right now)

I'll have a look asap

reverting SHT library to 0.2.1

  • selecting sketch - SHT31_I2Cspeed.ino (0.02)
  • compiling with UNO works
  • compiling ESP32 fails so I can recreate the error (I do not have 8266 nearby so this should be close enough)

OK, compiling now works

  1. replace void with bool in line 32 of the SHT31.h file
  bool begin(const uint8_t address, uint8_t dataPin, uint8_t clockPin);
  1. replace the setHeatTimeout function in SHT31.cpp so it does not use min()
void SHT31::setHeatTimeout(uint8_t seconds)
{
  _heatTimeOut = seconds;
  if (_heatTimeOut > 180) _heatTimeOut = 180;
}

Thanks for finding this bug, can you please verify above fix works?
I will prepare a pull request right away.

Ho Rob,

thank you very much. Now it compiles.

Your I2C-speed test also explains how to do fast or slow readings

best regards Stefan

Not investigated the latest Adafruit lib but from my head:

When my library doeas a read(), it reads both the T and H does the math for both and puts them into 2 variables. This takes time (~15 millis). When you call getTemperature() or getHumidity() it just copies the variables from the library to your code. This is fast.
To update the internal variables you must call read again, otherwise you get the cached variables again.

The Adafruit library works slightly differently.
A call to getTemperature() or getHumidity() always reads the sensor again, but when reading the T it ignores the H and vice versa.
So it throws away information e.g. H and most of the time it rereads it immediately again. This results in a double delay (don't know if that is 500 ms but it will do double work. The advantage is that you will have the latest measurement, always.

Conclusion
My library stores all fetched information and can deliver info faster as 99% of the cases applications ask temperature and humidity right after each other. If you want my lib to behave like the Adafruit's, you must call read() before every getTemperature() or getHumidity().

Ho Rob,

thank you very much. Now it compiles.

Your I2C-speed test also explains how to do fast or slow readings

best regards Stefan

I will merge the pull request, thanks for pointing out the bug and testing.