Pages: [1]   Go Down
Author Topic: explanation of the SonarSRF08 library  (Read 683 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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; ?
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8974
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8974
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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. smiley-sad
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Pages: [1]   Go Up
Jump to: