| SRF08 to BrainStem Example Last Modified: 2007-11-06 | | |
| Acroname Robotics | |||
| ![]() Introduction In this example, a BrainStem GP 1.0 module uses a Devantech SRF08 Ranger to measures distances to obstacles. The BrainStem GP 1.0 uses its built in high speed IIC bus to communicate with the ranger and display the readings on the Console application. A BrainStem Moto 1.0 could also be used to run the example program since it has identical IIC capabilities. Circuit Schematic In the following schematic, one of the 2 IIC headers on the BrainStem is used to interface to the IIC port on the SRF08 ranger. Power and ground are also connected using the BrainStem GP's built-in power regulation. Additionally, this circuit uses the 4 AA battery pack to power the circuit. ![]() Source Code - SRF08 Range Reading This program utilizes the built-in library for handling Devantech SRF08 Rangers and specifies which IIC address is used for the ranger. Different constants could be used to specify the readings in centimeters or milliseconds. Additional SRF08's could be added along the IIC bus and given different addresses. These other addresses would then be sent as parameters to the aSRF08_RangeInt command. This code uses the TEA language which is very similar to ANSI C. It is compiled using the BrainStem Console with the steep command. /* filename: srf08-1a.tea */
#include <aSRF08.tea>
#include <aPrint.tea>
#include <aCore.tea>
void main() {
int val;
while(1) {
/* take inch reading from address 0xE0 */
val = aSRF08_RangeInt((char)0xE0, aSRF08_INCH);
/* display on console */
aPrint_IntDec(val);
aPrint_String(" inches\n");
/* sleep for 1 second */
aCore_Sleep(10000);
} /* while */
} /* main */
Source Code - SRF08 Multiple Echos and Light Readings This second program utilizes the built-in library for handling Devantech SRF08 Rangers and specifies which IIC address is used for the ranger. Different constants could be used to specify the readings in centimeters or milliseconds. Additional SRF08's could be added along the IIC bus and given different addresses. These other addresses would then be sent as parameters to the aSRF08_RangeInt command. Notice that this example inserts the proper delay in the code to allow the SRF08 to take its reading. This was not incorporated into the library function to allow other processing to occur while waiting for the detector within the TEA process. /* filename: srf08-1b.tea */
#include <aSRF08.tea>
#include <aPrint.tea>
#include <aCore.tea>
#define SRF08_ADDR 0xE0
void main() {
char light;
int echo1;
int echo2;
while(1) {
/* initiate the reading with ranger at 0xE0 */
aSRF08_Range((char)SRF08_ADDR, aSRF08_INCH);
/* stall for 70ms */
aCore_Sleep(700);
/* get the light reading */
light = aSRF08_LightChar((char)SRF08_ADDR);
/* get the first couple of echo readings */
echo1 = aSRF08_NextEchoInt((char)SRF08_ADDR);
echo2 = aSRF08_NextEchoInt((char)SRF08_ADDR);
/* display on console */
aPrint_CharHex(light);
aPrint_String(": ");
aPrint_IntDec(echo1);
aPrint_String(", ");
aPrint_IntDec(echo2);
aPrint_String(" inches\n");
/* sleep for 2 seconds */
aCore_Sleep(20000);
} /* while */
} /* main */
Changing SRF08 I2C Address The IIC address of an SRF08 sensor can be changed by entering some commands at the Console prompt. Before trying to change the address, set the IIC baud rate to 100kbps. This will ensure reliable communication with the sensor. To change the baud rate on a BrainStem with an address of 2, enter the following command at the Console prompt: 2 18 3 0
That issues the cmdVAL_SET command (18) to change the IIC baud rate (parameter 3) to 100Kbps (code 0). The commands in the table below will change the address from 0xE0 (224) to 0xE2 (226). When entering data in the Console, it is acceptable to use hexadecimal text, decimal text, or a mixture of both. The last number in the last command is the new address: 0xE0 0 0xA0 /* 1st in sequence */
0xE0 0 0xAA /* 2nd in sequence */
0xE0 0 0xA5 /* 3rd in sequence */
0xE0 0 0xE2 /* New address value */
After changing the address, the red LED on the SRF08 will remain lit and the unit must be turned off. When powered up again, it will have the new address. Complete details of SRF08 operation may be found at the Denvantech website . Additional Notes The first example uses Build 6 or later of the BrainStem Console. The second example uses Build 8 or later of the BrainStem Console. Revision History:
| |||
Related Links: | ||||
| voice: 720-564-0373, email: sales@acroname.com, address: 4822 Sterling Dr., Boulder CO, 80301-2350, privacy © Copyright 1994-2012 Acroname, Inc., Boulder, Colorado. All rights reserved. |