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

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() {
  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

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


  if(x > 3) x = 0;

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()

void loop()


void receiveEvent(int byteCount)
  regReq =;
  rtnPtr = &array[regReq*2];    

void requestEvent()