Uno r4 i2c communication

i have 2 arduino r4's. i want these 2 boards to communicate witch each other over i2c. I first connected the 2 boards with digital pins. I later found out that this is not possible because they dont have a pullup. So now i have connected the 2 boards with a qwiic connect cable. i am using the wire library to connect between the 2, but nothing happens. i am using the example code from the wire library, to make sure there's nothing wrong witht the code. I only eddited the Wire to Wire1. Nothing happens when i connect the boards and upload the code. Can anyone help me with this?

the master code:

#include <Wire.h>

const int SLAVE_ADDRESS = 4; 

// Set up the I2C bus
void setup() {
  Wire1.begin();
}

// Send a message to the slave Arduino
void loop() {
  Wire1.beginTransmission(SLAVE_ADDRESS);
  Wire1.write("Hello from the master!");
  Wire1.endTransmission();

  // Delay for 1 second
  delay(1000);
}

The slave code:

#include <Wire.h>

// Set up the I2C bus
void setup() {
  Wire1.begin(4);
  Wire1.onRequest(requestEvent);
}

// Receive a message from the master Arduino and print it to the serial monitor
void requestEvent() {
  int bytesReceived = Wire1.requestFrom(10, 255);
  while (bytesReceived > 0) {
    Serial.print(char(Wire1.read()));
    bytesReceived--;
  }
  Serial.println();
}

// Loop forever
void loop() {}

Please post a schematic or wiring diagram showing the connections between the boards.

Photos may also be helpful.

That code will never work.

You have the master blindly sending data over the I2C bus, but nothing in the slave is looking for data from the I2C bus.

On the slave, you have defined the interrupt handler for when a request is received, but the master is never requesting anything. Your function requestEvent() is what will be executed when the slave received an I2C request as a consequence of the master executing the requestFrom() function.

Have you looked at any of the examples for Wire?

this is the setup i have now,

This is the code i used earlier but nothing happened there either
master:


#include <Wire.h>

void setup() {
  Wire1.begin(8);                
  Wire1.onRequest(requestEvent); 
}

void loop() {
  delay(100);
}

void requestEvent() {
  Wire1.write("hello "); // respond with message of 6 bytes
 
}

slave:



#include <Wire.h>

void setup() {
  Wire1.begin();        
  Serial.begin(9600);  
}

void loop() {
  Wire1.requestFrom(8, 6);    

  while (Wire.available()) { 
    char c = Wire.read(); 
    Serial.print(c);         
  }

  delay(500);
}

The code looks ok, but you have the master and slave reversed, and in some places you are using Wire instead of Wire1. The master uses requestFrom() to request data to be send from the slave.

that worked thanks