Communicating with I2C from Arduino to Ardunio

Hi there

I am new to this forum and new to Ardunio. I am currently working on a project at uni that feeds information from strain gauges into an Ardunio Mega and relays it to the computer. The Ardunio will also control the speed of an external pump and take readings over a given period. For example, the speed will change and then in 20 minutes the Arduino will record the readings to an SD card for a further 10 before stopping and repeating the process.

As I have a lot of inputs, I have decided that it would be best to use 2 Arduino Mega controllers as this will provide me with the desired sample rate.

My question is, what line of code can I use to initiate the second Arduino to begin writing to the SD card when the first one does? And what would be the best way to stop it?

I assume that the two sets of code will be similar, only the slave will have a couple lines in it telling it to begin writing when a signal is received then to stop when it gets another?

Thanks for any help
Matt

P.S sorry for posting what is probably a very basic question

Here are a couple test programs you might want to try to see how the I2C bus works. You could modify this to do what you want.

The master sends a byte (the ‘x’ variable) to the slave to set which “register” it wants to read from.

#include <Wire.h>

void setup() {
  Serial.begin(115200);
  Wire.begin(); // join i2c bus (address optional for master)
}

byte x = 0;

void loop() {
  Wire.beginTransmission(13); // transmit to device #13
  Wire.write(x);              // sends one byte
  Wire.endTransmission();    // stop transmitting

  delayMicroseconds(100);
  
  if(Wire.requestFrom(13, 2) > 0) {    // request 2 bytes from slave device #13
    while(Wire.available())    // slave may send less than requested
    { 
      char c = Wire.read(); // receive a byte as character
      Serial.print(c,DEC);         // print the character
      Serial.print(" ");
    }
    Serial.println();
  }
  else {
    Serial.println(F("Fail"));
  }

  x++;

  if(x > 3) x = 0;
  delay(500);
}

The slave receives the “register” request and sends that register when requested.

#include <Wire.h>

// the "register" values
byte array[8] = {2,4,6,8,10,12,14,16};

volatile byte regReq = 0;
volatile byte* rtnPtr;
 
void setup()
{
  Wire.begin(13);
  Wire.onReceive(receiveEvent);
  Wire.onRequest(requestEvent);
}

void loop()
{

}

void receiveEvent(int byteCount)
{
  regReq = Wire.read();
  rtnPtr = &array[regReq*2];    
}

void requestEvent()
{
  Wire.write((byte*)rtnPtr,2);
}