Connecting Multiple SRF08 Sonar Modules to the OOPic

Introduction
The SRF08 modules use the I2C bus for
communication. This example shows how to connect two SRF08's to the OOPic,
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 a separate 5v supply or replace the 5v regulator on
the OOPic with a higher current one. There are Instructions
on the OOPic website to do this. Do not connect the SRF08's to the OOPic
connectors labeled I2C, these are the OOPic network connectors and are not used
by the oI2C object.
Circuit Schematic for connecting two SRF08 Sonar Modules to the OOPic
Changing the SRF08 I2C Address
Before you can use the SRF08's you will need to re-program their I2C
addresses from the default address of 0xE0 they are supplied with. The simple
program below will do this. Make sure you only have one SRF08 connected when you
do this. You only have to change the 1st line of the program below to the address you want. For
example if you want the SRF08 to be at address 0xF2, then change the 1st line to
read;
Const NewAddress = 242
Now download the program to the OOPic, you will see rapid brief flashes on the
Red Led on the SRF08 indicating that the change of address was successful. It is
wise to make a note of the new address on the SRF08 itself.
To use the example
code described later on this page, set one SRF08 to address 0xE0 and the other
to 0xE2. The following program can be downloaded here.
| Const NewAddress =
224 '
CHANGE THIS NUMBER FOR THE REQUIRED ADDRESS ' See table below. ' This program can be used to set the I2C address of the SRF08 Sonar
Module Dim Srf08 As New
oI2C
'Create the SRF08 object Sub main() ' Because of the way the OOPIC works, it requires addresses to be right Do Do Ver = SRF08 Loop While Ver=255 ' Wait for ranging to complete Loop ' Keep pinging forever End Sub |
Displaying Light Sensor and Range readings on the LCD
Now that you have your SRF08's re-programmed to their new I2C addresses
(0xE0 and 0xE2) the following sample code will display the light sensor
reading and the 1st and 2nd ranges, for each SRF08 on a 20x4 line LCD display.
The sample code below can be downloaded here.
| Dim D As
New oDio4
' Initializes a new object called D as a nibble I/O Dim E As New oDio1 ' Initializes a new object called E as a single bit I/O Dim RS As New oDio1 ' Initializes a new object called RS as a single bit I/O Dim LCD as New oDataStrobe ' Initializes a new object called LCD as a Data Strobe Dim Srf08 As New oI2C ' Create the SRF08 object Dim Ver as new oByte Dim Light as new oByte Dim Range1 as new oWord Dim Range2 as new oWord Dim S As New oBuffer(5) Dim Sw1 As New oDio1 Dim Sw2 As New oDio1 Sub main()
Do ReadSonar(113)
' 113 is decimal of 0xE2 shifted right by 1 Sub ReadSonar(Addr As oByte) ' Use these three lines ' or this one SRF08.Location = 1
' Light Sensor Register Sub LocateRow1() Sub LocateRow2() Sub LocateRow3() Sub LocateRow4() Sub ClearLCD() Sub IOSetup() Sub LCDSetup() Sub Srf08SetUp() |
You can find more information on the SRF08 here