SRF08 Settings: writing registers

Hi all! First post on the forum for me, I’m not sure if this is the right section.

I’m trying to set up an SRF08 using the example that comes with the Wire Library, but I’m not getting reading above 1.5m distance.

According to the documentation in order to change the Range I have to write on the 3rd register.

I have a limited knowledge of I2C communication, so I assumed I had to give the command when beginning the Transmission, like this:

#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(0x7C); 
  Wire.write(byte(0x00));      // sets register pointer to the command register (0x00)
  Wire.write(bythe(0x8C));    // set range at 6 meters
  Wire.write(byte(0x51));      // 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(0x7C); // 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(0x7C, 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 :)
}

But it didn’t work. The sensor is basically stuck, the led on its back doesn’t light up to signal the ranging, and on the serial monitor I only get 111 readings.

Then I tried to set it at setup:

#include <Wire.h>

void setup() {
  Wire.begin();                // join i2c bus (address optional for master)
  Wire.beginTransmission(124);
  Wire.write(byte(0x8C));      // set range at 6 meters
  Wire.endTransmission();
  Serial.begin(9600);          // start serial communication at 9600bps
}

int reading = 0;

void loop() {
  
  
  // step 1: instruct sensor to read echoes
  Wire.beginTransmission(124); // 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(0x51));      // 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(124); // 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(0x7C, 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 :)
}

And and isnide the loop before the ranging:

#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() {
  
  Wire.beginTransmission(124);
  Wire.write(byte(0x8C));      // set range at 6 meters
  Wire.endTransmission();
  
  // step 1: instruct sensor to read echoes
  Wire.beginTransmission(124); // 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(0x51));      // 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(124); // 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(0x7C, 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 :)
}

But in both cases nothing changes and I still don’t get reading over 1.5 meters.

I even tried this library which seems to be completely broken. I don’t even get the “Sensor X not connected…” message on the Serial Monitor…

And I don’t have any clue what I could do next.

No one? I've bumped into at least 4 threads like this, with people having the same problem, and apparently all of them are still unsolved.

Would someone with a clear understanding of I2C and writing registers point me to some resources at least? Because I basically brute forced all the possible combinations of code to write on the 2nd and 3rd registers to change the sensor Gain and Range, and nothing has changed.