Change address on the srf08

I have been using an Arduino mega 2560 to control an SRF08 range finder
without any problems,however I can’t change its address on the I2C bus.
I tried the example code changeAddress function below with no succes.
The example code transmitted each of the 4 command bytes with beginTransmission,
0x00 byte, command byte, and endTransmission for each ofm the 4 command bytes.
Since the SRF08 document said the 4 bytes should be sent without interruption, I
tried sending only the 4 command bytes which also did not work.

What am I missing ?

#include <Wire.h>

/*
Generic example for the SRF modules 02, 08, 10 and 235.
Only the SRF08 uses the light saensor so when any other
range finder is used with this code the light reading will
be a constant value.
*/

#include <SoftwareSerial.h>
#define OLD_ADDRESS 0x70
#define NEW_ADDRESS 0x73 // New Address of the SRF08 0xE2 -> 0x71 for 7 bit addresses

void setup(){

Wire.begin();
delay(100);
// Waits to make sure everything is powered up before sending or receiving data

// change address from 0XE0 to 0XE2 7 bit address shifts adresses 1 bit right 0xE0 -> 0x70, 0xE2 -> 0x71
// change address from 0XE0 to 0XE4 7 bit address shifts adresses 1 bit right 0xE0 -> 0x70, 0xE4 -> 0x72
// change address from 0XE0 to 0XE6 7 bit address shifts adresses 1 bit right 0xE0 -> 0x70, 0xE6 -> 0x73

changeAddress(OLD_ADDRESS, NEW_ADDRESS);

delay(1000); // Wait for change to be complete

Serial.begin(9600);

}

void loop(){

Serial.print("new SRF08 address = ");
Serial.println(NEW_ADDRESS, HEX); // Display new address

delay(1000); // Wait before looping
}

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

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

Hey @RonS!

Have you tried something like this?

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

Also make sure that you only have 1 device on your I2C bus

Let me know how that went!

Thanks for the reply,
I have only one srf08 on the I2C bus.
I tried writing only the 4 bytes as you suggested on each of two srf08 devices but could not change their address.

I also tried adding a Wire.write(0x00); after the begin transmission command with no luck.

Hi @RonS

Did you put a pull up resistor on both SCL and SDA? Also the old base address of the sonar is 0xE0, not 0x70

Source: https://www.robotshop.com/media/files/pdf/devantech-srf08-ultrasonic-range-finder-specifications.pdf

@devantech: any ideas on why the address does not seem to be changing?

The Arduino requires 7-bit addresses. (right aligned)
The SRF08 requires 8-bit addresses (left aligned)
The old address is being used by the Arduino, so 7-bit 0x70
The new address is being given to the SRF08, so 8-bit 0xE2
After the address change the SRF08 should be available at 0x71

#define OLD_ADDRESS 0x70
#define NEW_ADDRESS 0xE2 // New Address of the SRF08 0xE2 - Aduino will see it at 0x71

1 Like