Connecting the SRF08 Sonar Module to the PICAXE-28x  

Introduction
The SRF08 modules uses the I2C bus for communication. This example shows how to connect the SRF08 to the PICAXE-28x. The SDA (data) and SCL (clock) lines are connected to pins Input4 (pin15) and Input3 (pin14) on the PICAXE chip. These are the pins used by the PICAXE-28x for the I2CIN and I2COUT commands. The photograph above shows the SRF08 wired up on the PICAXE Experimenter Board.

Circuit Schematic for connecting the SRF08 Sonar Module to the PICAXE-28x

The schematic above shows 4k7 pull-up resistors on the SCL and SDA lines to Vdd. For greater noise immunity, I recommend pulling up using 1k8 resistors.

Changing the SRF08 I2C Address
Before you can use the multiple SRF08's you will need to re-program at least one of the 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 NEW_ADDRESS constant in the program below to the address you want. For example if you want the SRF08 to be at hex address 0xEC, then change NEW_ADDRESS to read;

symbol NEW_ADDRESS = $EC          ' Place new address for SRF08 here

Now download the program to the PICAXE, you will see rapid brief flashes on the Red Led on the SRF08 indicating that the change of address was successful and the range displayed on the debug screen. It is wise to make a note of the new address on the SRF08 itself. The following program can be downloaded here.


'***********************************************************
'**                                                       **
'**   SRF08 Demonstration Software for the PICAXE-28x     **
'**     showing how to change the SRF08 I2C address       **
'**                                                       **
'**          Copyright 2003 - Devantech Ltd               **
'**    Commercial use of this software is prohibited      **
'**    Private and educational use only is permitted      **
'**                                                       **
'**         Written by Gerald Coe - May 2003              **
'**                                                       **
'***********************************************************

' NEW_ADDRESS can be set to any of E0, E2, E4, E6, E8, EA, EC, EE
'                                  F0, F2, F4, F6, F8, FA, FC, FE
symbol NEW_ADDRESS = $EC

main:
   i2cslave $00,i2cfast,i2cbyte     ' Define General Broadcast i2c address for the SRF08
   writei2c 0,($A0)                 ' 1st command in address change sequence
   writei2c 0,($AA)                 ' 2nd
   writei2c 0,($A5)                 ' 3rd
   writei2c 0,(NEW_ADDRESS)         ' The new address for the SRF08

' now show range reading to prove address change is OK
   i2cslave NEW_ADDRESS,i2cfast,i2cbyte ' use new i2c address for the SRF08
loop:
   writei2c 0,(81)                  ' Send Ranging command to get range in cm
   pause 100                        ' Wait for ranging to complete
   readi2c 2,(b5, b4)               ' Read the Range
   debug w2                         ' Display Range, Note b5-b4 are w2 high-low bytes
   goto loop

 

Displaying Light Sensor and Range readings on a PC Debug window
The following sample code will display the software revision, light sensor reading and the 1st range reading for the SRF08 in a Debug window on the PC. The code below can be downloaded here.


'***********************************************************
'**                                                       **
'**    SRF08 Demonstration Software for the PICAXE-28x    **
'**                                                       **
'**            Copyright 2003 - Devantech Ltd             **
'**     Commercial use of this software is prohibited     **
'**     Private and educational use only is permitted     **
'**                                                       **
'**          Written by Gerald Coe - May 2003             **
'**                                                       **
'***********************************************************

main:
   i2cslave $E0,i2cfast,i2cbyte     ' Define i2c slave address for the SRF08

loop:
   writei2c 0,(81)                  ' Send Ranging command to get range in cm
   pause 100                        ' Wait for ranging to complete
   readi2c 0,(b0)                   ' Read SRF08 Software Revision
   readi2c 1,(b2)                   ' Read the Light Sensor
   readi2c 2,(b5, b4)               ' Read the Range, Note b5-b4 are w2 high-low bytes

   debug w0                         ' Display Software Revision
   debug w1                         ' Display Light Sensor Value
   debug w2                         ' Display Range, Note b5-b4 are w2 high-low bytes

   goto loop

You can find more information on the SRF08 here and the PICAXE here