ESP8266 Change i2c pins

Hello to all.
Can I change esp8266 i2c pins by code, for example I want to use GPIO9 and GPIO10 as SDA and SCL.
Very thank you.

(deleted)

I have esp8266-12F like below picture.Which pins are SDA and SCL.
very thanks.

1.jpg

(deleted)

OK. there is in google a lot pictures about ESP 12-F.
But which one is true.
And in ESP 12-F datasheet is different.
Below I have uploaded the datasheet.
I'm still in doubt that which pins are SDA and SCL.

(deleted)

But I have a problem that first I want to design PCB so I can't see.
This is true about 12-E but how about 12-F.
Is there any datasheet for it?
very thank you

(deleted)

Sorry my English is so poor.Can you tell me which one is the SDA and SCL from below links:
http://www.electrodragon.com/w/ESP-12F_ESP8266_Wifi_Board
Thanks.

Just trying it would give you an answer sooner than waiting around and arguing with people who give you answers.
Use 4.7K pullup resistors.

spycatcher2k:
GPIO 4 is SDA
GPIO 5 is SCL

2 seconds on GOOGLE : ESP8266-12 Pinout was all it took.

There is another, perhaps more up to date, point of view on this matter: ESP8266 Thing Hookup Guide - SparkFun Learn

It implies that one can indeed change the I2C pins:

Wire – The ESP8266 should work with any I2C sensor you can throw at it – just use the same Wire API calls you’re used to. There are a few differences:

Pin definition: The ESP2866 doesn’t actually have any hardware I2C pins – those labeled on the Thing are the default, but you can actually use any two pins as SDA and SCL. Calling Wire.begin() will assume pins 2 and 14 are SDA and SCL, but you can manually set them to any other pin by calling Wire.begin([SDA], [SCL]).

(deleted)

Yes, all pins on ESP8266 are capable of I2C (and interrupt and PWM) (except gpio16).

So Can I change esp8266 i2c pins by code, for example I want to use GPIO9 and GPIO10 as SDA and SCL?
Is below code true?
Wire.begin(9,10); //9 as SDA and 10 as SCL
Thanks.

leoncorleone:
So Can I change esp8266 i2c pins by code, for example I want to use GPIO9 and GPIO10 as SDA and SCL?
Is below code true?
Wire.begin(9,10); //9 as SDA and 10 as SCL
Thanks.

According to the available documentation, that would appear to be the case. As always, test it to make sure.

I think it's time to give this topic some new fresh air... When I searched for the same question, I got this link as first hit. And the first answer on this question was a short answer, "No".

Now I found a way to change the i2c by just adding <wire.begin(sda,scl)> at the beginning of the code. (without the <>).
So I hope the people that are searching for answers regarding the same question, they are not discouraged by the short No.

It is possible by just adding wire.begin(sda,scl) to your code and change the sda and scl to the pins you want to use.

1 Like

The Wire.begin(x, y); command has worked for me where ESP8266 is always Master. It does not respond as Slave in this Soft I2C protocol.

NodeMCU1.0 Codes:

#include<Wire.h>
#include<LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16, 2);

void setup() 
{
  Wire.begin(4, 5); //SDA, SCL
  Serial.begin(115200);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("OK!");
  
  Wire.beginTransmission(0x08);
  Wire.write(0x23);
  byte busStatus = Wire.endTransmission();
  Serial.println(busStatus);

  Wire.requestFrom(0x08, 1);
  byte x = Wire.read();
  Serial.println(x, HEX);
  lcd.print(x, HEX);

}

void loop() 
{
  

}

DUE Codes:

#include<Wire.h>
bool flag1 = LOW;
byte x;

void setup()
{
  Serial.begin(115200);
  Wire.begin(0x08);
  pinMode(13, OUTPUT);
  Wire.onReceive(receiveEvent);
  Wire.onRequest(sendEvent);
}

void loop()
{
  if (flag1 == HIGH)
  {

    Serial.println(x, HEX);
    flag1 = LOW;
  }
  digitalWrite(13, !digitalRead(13));
  delay(1000);
}

void receiveEvent(int howmany)
{
  x = Wire.read();
  flag1 = HIGH;
  //Serial.print(x, HEX);
}

void sendEvent(int howmany)
{
  Wire.write(0x45);
}