Devantech SRF04 to BrainStem Example
Last Modified: 2007-09-25
find:

basket

Acroname Robotics PDF webpage version Devantech SRF04 to BrainStem Example PDF

Related
Products

Product image for Brainstem GP 1.0 Module
Brainstem GP 1.0 Module
Product image for 2600mAh AA NiMH Battery
2600mAh AA NiMH Battery
Product image for Devantech SRF04 Ranger
Devantech SRF04 Ranger
Product image for 3 Conductor Cable w/ Connector
3 Conductor Cable w/ Connector
Product image for 4X AA Battery Pack w/Connector
4X AA Battery Pack w/Connector

Contents

Photo of interface between BrainStem GP 1.0 and Devantech SRF04 ranging module

Introduction

In this example, a BrainStem GP 1.0 microcontroller uses a SRF04 Ultrasonic Range Finder to measures distances to obstacles.  The BrainStem GP 1.0 tells the sonar module to emit a "ping" and measure the time it takes to receive an echo.  It reveals the distance as a raw time in increments of the timer's resolution, which is 1.6 uSec. 

This example shows a Palm Pilot running the Console to display the sonar readings, but the Console may be used with any supported Platform. 

Circuit Schematic

Schematic Diagram of connections between BrainStem GP 1.0 and Devantech SRF04

In the above schematic, two digital I/O pins of the BrainStem GP 1.0 are configured to handle the ECHO and INIT lines of the SRF04 ranging module.  The circuit is powered by 4 NiMH AA batteries . 

Source Code

This code uses the TEA language, which is very similar to ANSI C. It is compiled using the BrainStem Console with the steep command. More information on the TEA language and compiling with the Console can be found at:

http://www.acroname.com/brainstem/TEA/tea1.html

/* SRF04_Example.tea */ /* included for the display routines */ #include <aCore.tea> #include <aPrint.tea> /* set which pins control the SRF04 */ #define aSRF04_INIT 4 #define aSRF04_ECHO 3 /* now include the SRF04 driving routines */ #include <aSRF04.tea> void main() { int num = 0; int reading; aSRF04_Setup(); while (1) { reading = aSRF04_ReadInt(); aPrint_String("Reading "); aPrint_IntDec(num++); aPrint_String(" = "); aPrint_IntDec(reading); aPrint_Char('\n'); aCore_Sleep(10000); } }

This program utilizes the built-in library for handling Devantech SRF04 Rangers and specifies which BrainStem digital I/O lines are being used before including the library for the SRF04 drivers.  The program then sets up the module using the aSRF04_Setup routine before taking multiple readings using the aSRF04_ReadInt command. 

Running the Program

Before you can start taking measurements from the sensor, you need to compile and load the TEA program to the Brainstem.  Follow the link under Source Code, above, to learn more about compiling and loading TEA programs. 

When you have the program running correctly, it will return distance measurements (in usec) to the console every second.  Try maxing out the range of the sensor (by aiming it down a hallway, for instance) and moving your hand toward the sensor to find the minimum range. 

Revision History:

  • 2001-07-13: Example Created
 

Related Links:

Brainstem Software: Console Overview

The Devantech Sonic Range Finders Comparison and Examples

voice: 720-564-0373, email: sales@acroname.com, address: 4822 Sterling Dr., Boulder CO, 80301-2350, privacy
© Copyright 1994-2008 Acroname, Inc., Boulder, Colorado. All rights reserved.