Connecting Multiple SRF08 Sonar Modules to the Basic Atom

Introduction
The SRF08 modules use the I2C bus for
communication. This example shows how to connect two SRF08's to the Basic
Atom. It is expandable to up 16 SRF08's on the I2C bus. The SDA (data) and SCL (clock) lines are connected to
pins 13 and 14 on the Basic Atom. The Basic Atom's I2CIN and I2COUT commands are
used for communication with the SRF08's.
The Basic Atom's internal 5v regulator is not suitable for powering much external circuitry. I therefore recommend you use a separate 5v regulator as shown below..
Circuit Schematic for connecting two SRF08 Sonar Modules to the Basic Atom
The schematic above shows a 4k7 pull-up resistor on the SDA line to Vdd. For better noise immunity, this can be reduced to 1k8.
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 program below will do this. Make sure you only have one SRF08 connected when you
do this. You only have to change the SRF08_NEW_ADDRESS constant in the program below to the address you want. For
example if you want the SRF08 to be at hex address 0xF2, then change
SRF08_NEW_ADDRESS to
read;
SRF08_NEW_ADDRESS Con
0xF2 ' Sonar I2C Address
Now download the program to the Basic Atom, you will see rapid brief flashes on the
Red Led on the SRF08 indicating that the change of address was successful. To
see the results on screen, select terminal 1, set the baud rate to 9600, select
the COM port your using and click "connect". You will see the LDR and first range
displayed on screen. It is
wise to make a note of the new address on the SRF08 itself. It is easy to
forget which is which otherwise.
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.
| '*********************************************************** '** ** '** SRF08 Demonstration Software for the Basic Atom ** '** To change the SRF08 I2C address ** '** ** '** Copyright 2002 - Devantech Ltd ** '** Commercial use of this software is prohibited ** '** Private and educational use only is permitted ** '** ** '** Written by Gerald Coe - April 2002 ** '** ** '*********************************************************** SRF08_NEW_ADDRESS Con
0xe2 ' Sonar I2C Address Light Var Byte Main
|
Displaying Light Sensor and Range readings in a PC Terminal window
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 range reading, for each SRF08 in a terminal window on the PC
.
The sample code below can be downloaded here.
| '*********************************************************** '** ** '** SRF08 Demonstration Software for the Basic Atom ** '** ** '** Copyright 2002 - Devantech Ltd ** '** Commercial use of this software is prohibited ** '** Private and educational use only is permitted ** '** ** '** Written by Gerald Coe - April 2002 ** '** ** '*********************************************************** SDA Con
P8 ' Define Data pin Light Var Byte '
Light sensor Main i2cout SDA, SCL, SRF08b,
CmdReg, [81]
|
You can find more information on the SRF08 here