Multiple SRF02 Ultrasonic Sensors using 12C!

I have 4 SRF02 Ultrasonic sensors, that I want to use within MaxMSP (i.e. send the values through serial). I uploaded this sketch:

#include <Wire.h>

void setup()
{
  Wire.begin();                // join i2c bus (address optional for master)
  Serial.begin(9600);          // start serial communication at 9600bps
}

int reading = 0;

void loop()
{
  // step 1: instruct sensor to read echoes
  Wire.beginTransmission(112); // transmit to device #112 (0x70)
                               // the address specified in the datasheet is 224 (0xE0)
                               // but i2c adressing uses the high 7 bits so it's 112
  Wire.write(byte(0x00));      // sets register pointer to the command register (0x00)  
  Wire.write(byte(0x50));      // command sensor to measure in "inches" (0x50) 
                               // use 0x51 for centimeters
                               // use 0x52 for ping microseconds
  Wire.endTransmission();      // stop transmitting

  // step 2: wait for readings to happen
  delay(70);                   // datasheet suggests at least 65 milliseconds

  // step 3: instruct sensor to return a particular echo reading
  Wire.beginTransmission(112); // transmit to device #112
  Wire.write(byte(0x02));      // sets register pointer to echo #1 register (0x02)
  Wire.endTransmission();      // stop transmitting

  // step 4: request reading from sensor
  Wire.requestFrom(112, 2);    // request 2 bytes from slave device #112

  // step 5: receive reading from sensor
  if(2 <= Wire.available())    // if two bytes were received
  {
    reading = Wire.read();  // receive high byte (overwrites previous reading)
    reading = reading << 8;    // shift high byte to be high 8 bits
    reading |= Wire.read(); // receive low byte as lower 8 bits
    Serial.println(reading);   // print the reading
  }

  delay(250);                  // wait a bit since people have to read the output :)
}


/*

// The following code changes the address of a Devantech Ultrasonic Range Finder (SRF10 or SRF08)
// usage: changeAddress(0x70, 0xE6);

void changeAddress(byte oldAddress, byte newAddress)
{
  Wire.beginTransmission(oldAddress);
  Wire.write(byte(0x00));
  Wire.write(byte(0xA0));
  Wire.endTransmission();

  Wire.beginTransmission(oldAddress);
  Wire.write(byte(0x00));
  Wire.write(byte(0xAA));
  Wire.endTransmission();

  Wire.beginTransmission(oldAddress);
  Wire.write(byte(0x00));
  Wire.write(byte(0xA5));
  Wire.endTransmission();

  Wire.beginTransmission(oldAddress);
  Wire.write(byte(0x00));
  Wire.write(newAddress);
  Wire.endTransmission();
}

*/

I first tested it with only 2 sensors, and I could get readings from both, but they were very inconsistent with the timing of the reading. Obviously I want to be able to separate these readings so that I can use the sensors individually, but i am struggling to get these values separated in a list.

Any adivce?

Obviously I want to be able to separate these readings so that I can use the sensors individually, but i am struggling to get these values separated in a list.

What does that mean, please?

Sorry I didn't explain very well. I want to be able to separate the sensor value reading in the serial. This is so I can receive these messages in MaxMSP and use the sensors to control various parameters. But at the moment, I am getting a mix of sensor values, I tried to put a comma between the values, but because the values crossover, that didn't help. Ideally I would like to have both sensors reading at an equal delay time, displaying one after the other.

Does this help any understanding?

I don't understand; the values should be printed on separate lines - what do you mean by "a mix of sensor values"?

They print on a separate line yes, but there is no way for me to identify which value is for what sensor when reading the serial messages in MaxMSP. This is because all I'm getting is a constant stream of number with nothing to identify or separate them.

Well, you know which sensor produced which reading, so why not print that too?

Do you mean print the sensor address with it? or just something to indicate which one it is?

Whichever makes sense for your MaxMSP code

How would I incorporate that within the Arduino sketch? apologies my arduino coding isn't great, still learning tbh.

Your code above only addresses a single sensor, so it's hard to say

O ok, well I know that I need to change the 12C address of the ‘slaves’. I attempted this before, but wasn’t very successful, so I suppose the next question is how to change the address and include that in this sketch to read both sensors?

Although at the moment I am getting readings from both sensors :s

Apologies, I have now sorted it now, thanks