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

Moderator: igrr

User avatar
By meneldor
#94503 Guys

I have not touched my ESPs since a few months and I'm going back to them...

It seems that a sketch that was working some time ago does not work any more. The sketch should scan I2C and display the addresses of the sensors found (based on a well known sketch) . I am using it since years without issue, but here ... :roll:

Here are the elements
- the sketch works on an Arduino UNO with same HTU21D and ports
- I'm using Arduino IDE 1.8.19, all libraries are up to date
- I'm very comfortable with the I2C device, it is a HTU21D (i used also a BMP280) . I test it each time on an Arduino UNO (I always restart from the UNO when troubleshooting)
- same with cables
- I tried several Wemos mini D1 or Nodemcu V3 without success (it works on UNO)
- I tried to change clock
- I tried with different pins (ie : D5 D6)
- i'm using 3.3V without any resistor

Here is the code


I'm working on this since 3 days, one time it worked but retrying with same combination some hours after it was not working any more. Strange no ? :(
Code: Select all // --------------------------------------
// works OK on an Arduino UNO
// does not work on Nodemcu V3 or Wemos D1 Mini
//

#include <Wire.h>
#define PINI2C_SDA D2 // pin for I2C SDA GPIO4/D2/4
#define PINI2C_SCL D1 // pin for I2C SCL GPIO5/D1/5

void setup()
{

  Serial.begin(115200);
  Serial.println();
  Serial.println("Start... -------------");
  Serial.println(__FILE__); // when i use an ESP after a long time gives an indication of what it is
  Serial.println();
  Wire.begin(PINI2C_SDA,PINI2C_SCL);

  Serial.println("\nI2C Scanner");
  Serial.println("Used ports");
  Serial.print("SDA Port :");
  Serial.println(PIN_WIRE_SDA); // Just to be sure , this is a variable i found in wire.cpp
  Serial.print("SCL Port :");
  Serial.println(PIN_WIRE_SCL);
}


void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");
      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }   
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");
  delay(5000);           // wait 5 seconds for next scan
}


What i get is "No I2C devices found"

Any bright idea is more than welcome !!! :idea: