Connecting the SRF08 Sonar Module to the OOPic-R 

Introduction
The SRF08 modules use the I2C bus for communication. This example shows how to connect the SRF08 to the OOPic-R, however it is expandable to up 16 SRF08's on the I2C bus. The SCL (clock) and SDA (data) lines are connected to the OOPic LSCL and LSDA - the OOPic Local I2C bus. The OOPic is able to power two SRF08's. If you want to use more then you will need to use the separate 5v supply available on the OOPic-R Do not connect the SRF08 to the OOPic connectors labeled I2C, this is the OOPic network connector and is not used by the oI2C object.

Circuit Schematic for connecting the SRF08 Sonar Module to the OOPic-R

Changing the SRF08 I2C Address
You only need to do this if you want a different address from the default 0xE0 the unit is supplied with. If you are using more than one SRF08, then you will need to make sure they are all programmed to different addresses. The SRF08 to OOPic page shows how to connect two SRF08's to the original OOPic and reprogram their addresses. The principle is the same for the OOPic-R. The example below assumes you are using the default 0xE0 address.


Reading the Light Sensor and Range Registers
The following program shows how to read the version, light sensor and range registers. With the OOPic-R running, these can be viewed by double clicking the on-screen object symbols in the OOPic compiler debug window.
The sample code below can be downloaded here.


'***********************************************************
'**                                                       **
'**               I2C Routines for OOPic-R                **
'**        with the SRF08 Ultrasonic Ranger Modules       **
'**                                                       **
'**           Copyright 2003 - Devantech Ltd              **
'**     Commercial use of this software is prohibited     **
'**     Private and educational use only is permitted     **
'**                                                       **
'**       Written by Gerald Coe - January 2003            **
'**                                                       **
'***********************************************************
'**                                                       **
'**  To view the Version, Light Sensor or Range Values    **
'**    Double click the object in the Debug Panel         **
'**                                                       **
'***********************************************************

Dim SRF08 As New oI2C      ' Create the SRF08 object
Dim Ver as new oByte
Dim Light as new oByte
Dim Range as new oWord

Sub main()
  SRF08.Node = 112         ' Decimal of Hex address 0xE0 shifted right by 1
  SRF08.Mode = cv10bit     ' I2C mode is 10-Bit Addressing.
  SRF08.NoInc = 1          ' Don't increment
  Do
    SRF08.Location = 0     ' Command Register
    SRF08.Width = cv8bit   ' 1 byte wide transfer
    SRF08 = 81             ' Ranging Command - Result in cm
    Do                     ' Wait for ranging to complete
      Ver = SRF08          ' This will wait forever if your sonar
    Loop While Ver=255     ' becomes disconnected

    SRF08.Location = 1     ' Light Sensor Register
    Light = SRF08          ' Get Light Sensor value

    SRF08.Width = cv16bit  ' 2 byte wide transfer
    SRF08.Location = 2     ' 1st Range Register
    Range = SRF08          ' Get Range to 1st object
Loop
End Sub

You can find more information on the SRF08 here