Chat freely about anything...

User avatar
By TS-Tec
#64868 Hello!

I have Problems to get I2C running. Following enviroment:

NodeMCU ESP-12E
Arduino IDE
wire.h Libary

I tried all this in regards of HW:
- Connection of SDA and SCL to different Pins (D1/D2, D4/D5, etc.)
- with and without 4,7k pull ups
- diffenrent I2C modules (SSD1306 Display, 2x BME280 sensors, ..)
- different ESP-12E boards
- different wiring

For my sketch I tried very simple implementations like the I2S Scanner:

Code: Select all#include <Wire.h>
 
void setup()
{
  Wire.begin(4,5); //also tried different Pins like 0,2 or D1,D2
   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);     
}


I also tried differnt sketches and also some WIRE.h Options like
Wire.setClock(clockFrequency) with 100000, 400000, 80000 etc
and
Wire.pins(sda, scl).

All same result: I dont get I2C running. No devices found...

Any idea???
User avatar
By daniel_ezsbc
#64886 Nothing seem to be obviously wrong but if you are using existing Arduino code, libraries, sketches etc, you should use :
I2C SDA = GPIO #4
I2C SCL = GPIO #5
In general the I2C just works. You should always have the pull-up resistors in place so that reset doesn't cause strange transitions on the bus. The 'correct' value for I2C pull-up resistors is 2.2k although this is strictly true only for 5V busses it has become the default for 3.3V systems as well. Higher value resistors may cause you to violate the timing rules, specially on a breadboard. The slave devices you chose are not the easiest to get going and I normally use a 24L02 memory device to test with. All speeds below 400,000 should work but since the signals are bit-banged I suggest using the library default.
User avatar
By TS-Tec
#64925 OK, thanks for your confirmation Daniel.. But does this mean I have to give up :cry:

Except the hint with the changed resistor values I nearly tried everything... What about the build-in pull-ups of the NodeMCU? Are pull ups really necessary? Do you think my 4,7 Ohms could be the cause that it is not working?

I also thought about the bread board and tried a direct wiring.. Without success :(

Maybe both of my Node boards are bad and have an issue with I2C? Can I do some more tests which help to find the root cause??

Thank you!
User avatar
By tjm
#66921 I also am having similar problems with I2C. I'm using an mcp23017 i2c chip as the slave target and have tried 2 different nodemcu chips, 2 different Arduino i2c libraries, native ESP8266 C driver, different pins and different pull-up resistors (including none). My Ardunio sketch checked for only 1 address and if I let it run long enough (several hours) it would get an ack ~30% of the time. If I move the data and clock to a Raspberry it runs just fine. Unfortunately, I don't know what else to try - any suggestions would be welcome.