-->
Page 1 of 2

I2C and ESP8266 07 / 12 not working - Working in NodeMCU

PostPosted: Tue Jun 05, 2018 11:05 pm
by Jonhy
Hello,

I'm facing problems in order to use I2C in a Single ESP 8266 12 and 07 Chip. I'm not having this problem if I connect the I2C sensor to NodeMCU ESP 12, anyone faced this problem too?

Here is the configuration with problem:

- ESP8266 12 or 07 Chip (Not NodeMCU / Chip soldered direct on PCB);
- SHT20 connected to ports GPIO4 and GPIO5 (04 - SDA and 05 - SCL);
- Power to SHT20 comes from the same VCC and GND lines;

Configuration that works:

- NodeMCU ESP 12;
- SHT20 connected to ports D1 and D2;
- Power to SHT20 comes from the same VCC and GND pins from NodeMCU;

Both of configurations use this I2C Scanner Code:

Code: Select all#include <Wire.h>
 
 
void setup()
{
  Wire.begin();
 
  Serial.begin(9600);
  Serial.println("\nI2C Scanner");
}
 
 
void loop()
{
  byte error, address;
  int nDevices;
 
  Serial.println("Scanning...");
 
  nDevices = 0;
  for(address = 1; address < 127; 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("Unknow 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
}


Maybe the NodeMCU has a Pull Up, Voltage Divider, because since the ESP are the same and the ports are the same, this problem is something to blow the brain trying to solve and understand...

Re: I2C and ESP8266 07 / 12 not working - Working in NodeMCU

PostPosted: Wed Jun 06, 2018 1:04 am
by schufti
a) you'r sure you are using the right pins on NodeMCU? gpio4 != D4
b) do you set sda/scl explicitely? the defaults change for selecting NodeMCU or generic esp8266 board

Re: I2C and ESP8266 07 / 12 not working - Working in NodeMCU

PostPosted: Wed Jun 06, 2018 4:16 am
by QuickFix
Also, for I2C to work correctly, you should pull up the I2C lines (3k3 or 4k7 should be fine).

But, as schufti already mentioned, the port numbers on development boards do not correspond to the actual GPIO-pin of the ESP. :idea:
Normally/officially, the correct GPIO of an ESP should be matched with its board's port-name in the Arduino IDE when you select the correct board, but I've never trusted this feature and use the actual GPIO port in code instead of its name.

Re: I2C and ESP8266 07 / 12 not working - Working in NodeMCU

PostPosted: Wed Jun 06, 2018 8:39 am
by Jonhy
schufti wrote:a) you'r sure you are using the right pins on NodeMCU? gpio4 != D4
b) do you set sda/scl explicitely? the defaults change for selecting NodeMCU or generic esp8266 board


Sorry, I've corrected my post, on NodeMCU the sensor is connected to D1 and D2.

Yes I change the defaults for NodeMCU and Generic ESP8266 respectively. What you say to set sda/scl explicitly, is that on code, or in board configuration?