How would I connect two MCUs via I2C

I currently am having a heap of trouble using Serial to connect an UNO and a ESP12E. I was wondering how connect via I2C.

You would need a level shifter, the Arduino UNO is a 5V board, and the ESP8266 is 3.3V.

Why doesn't Serial work? I've successfully used it between an UNO and an ESP8266 multiple times.

Pieter

I believe that the ESP8266 supports I2C in master mode only so your Uno would be the slave. Does that fit with what you are attempting to do?

Back to serial. If you can’t get this working then you have other problems. Are you using one of the software serial libraries on the uno and what baud rate are you using? If you are using hardware serial, this is likely to be more reliable but then the serial console (for debugging etc.) is more difficult to use.

mattlogue:
I currently am having a heap of trouble using Serial to connect an UNO and a ESP12E. I was wondering how connect via I2C.

1. Setup between ESP and DUE
espdue.png

2. Master-ESP 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() 
{
  

}

3. Slave-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);
}

espdue.png

As mentioned in the other thread, if the I2C scanner running on the ESP12E cannot find your I2C display, then you will have problems with I2C communications in general.

It can't find it - I'm assuming A4 and A5 have same physical connection to SDA and SCL. This is nuts. I even switched out for another ESP12E - they are labled "AMICA" and were shipped direct from China if that means anything. I'm sorry if I'm being a pest, but this is a thorn in my side.

I currently am having a heap of trouble using Serial to connect an UNO and a ESP12E. I was wondering how connect via I2C.

How are you handling the voltage level differences and the pullups?

What pins of the Node Mcu do you have connected to A4,A5 (sda,scl) of the UNO?

I'm assuming A4 and A5 have same physical connection to SDA and SCL.

No see reply #3, that tells you it has not.

Unfortunatley I am not using any means to handle the voltage differences. If this is the definite cause I'm sorry for wasting your time. I didn't eant extra clutter in my box from a logic level shifter or more resistors.

Unfortunatley I am not using any means to handle the voltage differences. If this is the definite cause I'm sorry for wasting your time. I didn't eant extra clutter in my box from a logic level shifter or more resistors.

Many people and tutorials appear to treat the esp8266 as 5v tolerant, and you appear to be in that camp. The pullups to 5v will be enabled on the Uno side with its use of the Wire library. I'm not certain of the Node Mcu engages its internal pullups with the wire library for the esp8266.

If you have connected D2 to SDA and D1 to SCL, then try

Wire.begin(D2,D1);

I currently am having a heap of trouble using Serial to connect an UNO and a ESP12E.

Certainly the Serial connection will only require two resisters as a divider circuit to make the RX robust.
This certainly seems like a more simple path than i2c.