Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Daemach
#30668 I'm attempting to connect an SHT20 (compatible with SHT21) with an ESP8266 in Arduino mode. I have 3 identical boards - on all of them, the IAQ sensor and barometric pressure sensor works perfectly, so I know the i2c bus is OK, but none of the SHT20's work. I'm using the standard SHT21 library - has anyone tried/been able to get an SHT to work with an ESP?

Here's the relevant library function - Wire.begin() has already been called - it was hanging on the commented-out //wait so I substituted the return -999 code instead, and that's what it returns: -999.

Code: Select allunsigned int SHT21Class::readData(byte command)
{
  unsigned int result;

  Wire.beginTransmission(0x40);   //begin
  Wire.write(command);             //send the pointer location
  delay(100);
  Wire.endTransmission();         //end

if (Wire.requestFrom(0x40, 3) != 3) { // Request three bytes
    return -999;
  }


  // Wire.requestFrom(0x40, 3);
  // while(Wire.available() < 3)
  // {
  //   //wait
  // }

  //Store the result
  result = ((Wire.read()) << 8);
  result += Wire.read();
  result &= ~0x0003;   // clear two low bits (status bits)
  return result;
}

Last edited by Daemach on Sat Oct 10, 2015 1:59 pm, edited 1 time in total.
User avatar
By schufti
#30671 Hi,
no the i2c lib is not ok.

There has been issue #698 with a woking solution but allthough the issue was closed it nerver found its way into the git .... I don't know why igrr ignores this fault, I deliberately started a thread about also.

you can use i2c-scanner to verify that your sht20 will not be found (other i2c devices may or may not)

use board search for these keywords and you may find the corrected core_esp8266_si2c.c
User avatar
By Daemach
#30680 I tried multispeed i2c scanner and it didn't find any i2c devices. Oddly, 2 of the 3 devices work with their licenses. It's only the SHT20 that doesn't.

I can't find a way to download that file and, though I saw where you modified the file according to igrr's instructions, I couldn't find those instructions either :/ If you could post the fixes somewhere that would be great!
User avatar
By martinayotte
#30681
Daemach wrote:I can't find a way to download that file

When browsing the GitHub up to the relevant file, there is a "raw" button to download it.
But here is the link that the button provide :
https://github.com/petrd/Arduino/raw/a2 ... 266_si2c.c
But, beware that maybe you can't simply replace this file in your tree without needs of other files, that's depend which version you are using ...