Changing the I2C address of a SRF02 sensor
Unlike most other devices does the SRF02 not allow you to set it's address with jumpers on the hardware side. You need to send a specific sequence of values to it's register to set the new address.I wrote a simple piece of C code to make this task easy for anyone with a Raspberry Pi. All you need is a C compiler and the wiringPi library.
Just compile the single C file, or use the CMake setup to get the tool and some sample utility and you are set to go.
The set_address application lets you change the i2c address of the sensor.
set_address <old address> <new address>
Where old address is the current I2C address of the sensor and new address is the desired address. Use 7-bit notation for both addresses. For example:
$ ./set_address 0x74 0x70
*** Changing SRF02' I2C address from 0x74 to 0x70
Writing 0xa0 to register 0x00
Writing 0xaa to register 0x00
Writing 0xa5 to register 0x00
Writing 0xe0 to register 0x00
*** Address change sequence complete
Check if device reacts to new address 0x00
-> The new device address is working
*** Address change was successfulThe tool will
- check if the sensor is accessible at the old address
- reprogramm the address setting
- check if the new address is reachable
Before you run the tool, make sure that the SRF02 is the only device on the I2C bus. THe reprogramming may fail otherwise.