Go Down

Topic: explanation of the SonarSRF08 library (Read 951 times) previous topic - next topic


I have gone through the code for the SonarSRF08 library and there is a lot of writing to the sonar sensor.

Why is there several registers being written and if I want to make my own custom library (for more Functionality), what order would I write these registers to the SonarSRF08.

also in the example SRF08.ino, why is the address offset in the setup() function?
New_Address += 4; ?


I found a mention that "The SRF08 behaves in the same way than series 24XX eeprom's, except that the adressing in I2C is handled differently."  This could explain some of the oddness in the interface.

Here's the technical specification: http://www.robot-electronics.co.uk/htm/srf08tech.shtml

The first three write locations are:
0: Command Register for setting modes 80=inches, 81=cm, 82=microseconds
1: Max Gain Register 0-31 (gains of 94 to 1025)
2: Max Range Register 0-255 (range of 43mm * (register+1))

The library seems to want to set all three whenever it sends a command.

The important read locations are:
0: Software Revision
1: Light sensor reading
2,3: 16-bit result

To set the I2C address you send commands 0xA0, 0xAA, 0xA5, NewAddress

I think the New_Address += 4; is in setup() because some idiot initialized New_Address to 248 (0xF8) and the actual address of their unit is 252 (0xFC).  Of course the default address is 0xE0 you you probably ought to use that.  It seems very odd that the library sets a new I2C address by sending the commands to address 0, regardless of the current address.

Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


The issue I am having with my SRF08's is that it seems the only address that works is the 0xF8 with New_address -4;
I'm unable to use the SonarSRF08::requestFrom() function to retreve data from any other address.

The SRF08 uses the address 0x00 as a general broadcasting address, in turn, if you change the address of 0x00, your change the address of your SRF08 sensor.


This website also uses an address that is unspecified(0x70): http://wiring.org.co/learning/libraries/ultrasonicsfr.html


Now things are making a little more sense.  The I2C address is 7 bits long.  When it is sent it is put in the top 7 bits of a byte and the bottom bit is used for a Read/Write flag.  Some documents specify the address as a 7-bit number and some as an 8-bit number with the bottom bit unused.

The SRF08 documentation uses the 8-bit form: E0, E2, E4...

The Wire library uses the 7-bit form. E0->70, E2->71, E4->72...

If you set the I2C address to 0xF8 the address you use in the Wire interface is 0x7C.  Since the top bit is thrown away you can also write this as 0xFC which happens to be 0xF8 + 4.  I'm guessing that this +4 trick doesn't work with any other address.

It looks like someone just threw together code until something worked, then released it as a library. :(
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

Go Up