| Devantech SRF04 to BrainStem Example Last Modified: 2009-01-13 | | |
| Acroname Robotics | PDF webpage version | ||
| ![]() Introduction In this example, a BrainStem GP microcontroller uses a SRF04 Ultrasonic Range Finder to measures distances to obstacles. The BrainStem GP tells the sonar module to emit a "ping" and measure the time it takes to receive an echo. It returns the distance as a raw time in increments of the timer's resolution, which is 1.6 uSec for the BrainStem GP 2.0. Circuit Schematic In the above schematic, two digital I/O pins of the BrainStem GP 2.0 are configured to handle the SRF04 ranging module's ECHO and INIT. The ECHO line must be wired into a digital pin that is capable of logic event timing. Please review the Digital Input/Output hardware documentation for the BrainStem board you are using. 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 steep command. Once compiled, the program can be loaded onto a BrainStem using the Console application. 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 as pre-processor macros. The program then sets up the digital pins using the aSRF04_Setup routine before taking multiple readings using the aSRF04_ReadInt command. Once the program running, it will return distance measurements (in usec) to the Console every second. Explore the sensor range (by aiming it down a hallway, for instance) and moving your hand toward the SRF04 to find the minimum range.
/* srf04_example.tea */
/* included for the display routines */
#include <aCore.tea>
#include <aPrint.tea>
/* Define which pins control the SRF04 */
/* The ECHO pin must be capable of pulse width timing measurement */
#define aSRF04_INIT 1
#define aSRF04_ECHO 2
/* now include the SRF04 driving routines */
#include <aSRF04.tea>
void main()
{
int num = 0;
int reading = 0;
/* Configure the digital pins to control the SRF04 */
aSRF04_Setup();
while (1) {
/* Take a reading */
reading = aSRF04_ReadInt();
/* Output the result to the Console */
aPrint_String("Reading ");
aPrint_IntDec(num++);
aPrint_String(" = ");
aPrint_IntDec(reading);
aPrint_Char('\n');
/* Delay for 1 second */
aCore_Sleep(10000);
}
}
Revision History:
| |||||||||
Related Links: Brainstem Software: Console Overview The Devantech Sonic Range Finders Comparison and Examples Related Examples: Devantech SRF05 Interface to BrainStem GP Example Devantech SRF04 Sonar Interface to a Handyboard Example Example code and schematic for Devantech SRF04 sensor interface to an OOPic | ||||||||||
| voice: 720-564-0373, email: sales@acroname.com, address: 4822 Sterling Dr., Boulder CO, 80301-2350, privacy © Copyright 1994-2009 Acroname, Inc., Boulder, Colorado. All rights reserved. |