I see now, thanks. I took a look at the code. You will want to set the address of the sonar to 0xF0. This is where my code will look for the first sensor. The shield code ignores the register byte in i2c transactions so that is good in the sense my code tries to read register 2, the shield will return the sonar code anyway. The only issue I see is my code reads a 16bit value. So it will read from the sonar shield twice, You will want to reduce that read call to 8bit.
Note: The shield code specifies the i2c address as 0x09. This would be the 7bit address (i.e. not including r/w bit), So to my code this equals 0x12 address.
So, try this:
1. Do one of:
a. Recompile the shield code to change i2c address from 0x09 to Ox78, or (0x78 = 0xF0 in 8bit i2c addr format)
b. Change my code and redefine SRF08_SENSOR_FIRST parameter from 0xF0 to 0x12...my code will then look for sensors at 0x12, 0x014, 0x16, etc.
1. Uncomment the SONAR_MULTICAST_PING define.
2. Change i2c_readReg16 to i2creadReg8 in "case 3" within the sonar's state machine code. There are actually 2 locations, but with SONAR_MULTICAST_PING disabled only the bottom of the two matter. The full line is:
srf08_ctx.range[srf08_ctx.current] = i2c_readReg16(SRF08_SENSOR_FIRST+(srf08_ctx.current<<1), SRF08_ECHO_RANGE);
srf08_ctx.range[srf08_ctx.current] = i2c_readReg8(SRF08_SENSOR_FIRST+(srf08_ctx.current<<1), SRF08_ECHO_RANGE);
penpen77 wrote:i2c shield for SR04 in the beginning of the thread, page 2, wrap echo/trigger blocking call request into i2c stream non-blocking event. With this "shield/wrapper", you have a decent working i2c sonar for ~5€
Blocking event like echo/trigger will degrade loop execution time, especially if there is several call at each execution (to have a median value, SR04 returned values aren't always accurate). And you don't have to sacrify 2 I/Os
so, with your code, just need to change i2c address and tweak srf08 i2c response/request handler.