Hi All,
I have a very strange problem with ESP8266-01S as below:
- 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.
- 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()
{
Wire.begin(0,2);
Serial.begin(9600);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}
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
}
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
SOLUTION:
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!