I2C Connection between different Arduino boards

Hello,

I2C onnection works on:
UNO with UNO
Leonardo with Leonardo

But UNO with Leonardo did not work.
Please help me understand why it does not work, and what need to do.

Thanks

  1. Post your schematic how the two boards are connected.
  2. Is anything connected to other pins? Post your code.
    To post code, use edit -> copy for forum in the IDE and next paste it here in a reply.

1.
UNO is Slave / Leonardo is Master

2.
Anything else not connected to Arduino.
The target is: Leonardo sending a Value UNO receiving a value and turning on Arduino led.

Master (Leonardo)

#include<Wire.h>
int LED = 13;
int x = 0;

void setup() {
  Serial.begin(9600);
  pinMode(LED, OUTPUT);
  Wire.begin(); 
}

void loop() {
  Serial.println(x);
  digitalWrite(LED, HIGH);
  delay(500);
  x = 3;
  Wire.beginTransmission(9);
  Wire.write(x);
  Wire.endTransmission();
 
  digitalWrite(LED, HIGH);
  delay(200);
  digitalWrite(LED, LOW);
  delay(200);
}

Slave (UNO)

#include<Wire.h>
int LED = 13;
int x = 0;

void setup() {
  Serial.begin(9600);
  pinMode (LED, OUTPUT);
  Wire.begin(9); 
  Wire.onReceive(receiveEvent);
}

void loop() {
  Serial.println(x);
  if (x == 3) {
    Serial.print("Hello - 1\n");
    digitalWrite(LED, HIGH);
    delay(200);
    digitalWrite(LED, LOW);
    delay(200);
    
    digitalWrite(LED, HIGH);
    delay(200);
    digitalWrite(LED, LOW);
    delay(200);
    
    digitalWrite(LED, HIGH);
    delay(200);
    digitalWrite(LED, LOW);
    delay(5000);
  }
  if (x == 0) {
    Serial.print("Hello - 2\n");
    digitalWrite(LED, HIGH);
    delay(400);
  }
}

void receiveEvent(int bytes) {
  x = Wire.read();
}

Resolved, was a bad connection :frowning: