Weird problem on I2C on ESP8266-01S

Hi All,
I have a very strange problem with ESP8266-01S as below:

  1. Setting: ESP8266-01S is connected to 3.3V power and connect to I2C bus with 1 PCF8574 port expander (known address of 0x20) on GPIO0-SDA/GPIO2 - SCL. The bus does not need pullup resitors as the module itself has built in 1k pullup resistor already. VCC for the I2C is 3.3 V.
  2. Problem:
  • When I connect the port and use wire library to connect via I2C, the connection was just fine with a declared address of 0x20. Also, If I connect another Pcf8574 module to the bus, with address 0x27, the connection is just fine also.
  • However, when I used the scanner procedure (see below
#include <Wire.h>
void setup()
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
void loop()
  byte error, address;
  int nDevices;
  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.
    error = Wire.endTransmission();
    if (error == 0)
      Serial.print("I2C device found at address 0x");
      if (address<16)
      Serial.println("  !");
    else if (error==4)
      Serial.print("Unknown error at address 0x");
      if (address<16)
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  delay(5000);           // wait 5 seconds for next scan

The result is "No I2C devices found" if Wifi is on for Blynk and OTA services. If I turn off all Wifi features, the scanning result was okay with 02 devices found (0x20 and 0x27).
I doubt the problem from the wifi. However, I measured on VCC/GND >> 3.1-3.2V and on port expander VCC/GND was still 3.1 V (within the range of valid power for I2C). I also tried putting pull-up resiter 1K, 3.3K, 4.7 K on the bus but no option worked. Turn of wifi make scanner work and found devices returned!
Can any one advice me on how to solve the problem with thanks. I need the scanner to work as I have to scan for new device on the bus when user plug in a new device.
Thank you very much

After sometime struggling with turning off Wifi, did not work, I applied an old trick, set the GPIO2 to LOW before Wire.begin(SDA, SCL),
The Scanner worked as expected!
The next thing I have to deal with is to conduct reading status of all connected I2C devices with Interupt!

I'm glad have it working :smiley:

Here you can see your board, the pinout and what the pins should do at startup:

Please don't try to do something with I2C in a interrupt.
Can you buy a common ESP32 (or ESP8266) board ? I think you are making it unnecessary hard for yourself with that small board.

Thank Koepel for your reply, I actually have no problem at boot with GPIO2. ESP8266-01S boots find with i2C on GPIO0 (SCL) and GPIO2 (SDA). The only thing happened strangely that, when GPIO2 is HIGH, I2C scanner will return nothing if Wifi/ blynk was activated earlier. Without wifi (just normal boot, no OTA, no blynk) Scanner worked fine. That why I feel frustrated. With the trick above, now I can use blynk to request the ESP866-01S module to scan automatically after sometime for checking new devices without any problem.
I have to use ESP8266-01S for developing low cost application on my farm. In Vietnam this module is about 1USD, higher versions are abour double and ESP32 is about 7 USD.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.