SRF08 Ultrasonic Ranger

This is the page for the SRF08 Ultrasonic Ranger, with I2C interface.

It is available at a number of places including :

The datasheet can be found from the Rapid Electronics website, or there is a good resources at Robot Electronics

Hello World!

#include "mbed.h"
#include "SRF08.h"

SRF08 srf08(p9, p10, 0xE0);      // Define SDA, SCL pin and I2C address

int main() {

    while (1) {
       printf("Measured range : %.2f cm\n",srf08.read());
       wait(0.1);
    }

}

Library

» Import this program

Public Member Functions

  SRF08 (PinName sda, PinName scl, int addr)
  Creates an instance of the class.
  ~SRF08 ()
float  read ()
  Reads the current temperature.

Alternative Library

This library does not use a wait statement so the micro can do something else while ranging is in progress.

» Import this library into a program

Public Member Functions

  SRF08 (PinName SDA, PinName SCL, int i2cAddress)
  Create a SRF08 object connected to the specified I2C pins and address.
void  startRanging ()
  Send the "Start ranging in cm" command via I2C.
bool  rangingFinished ()
  Checks if the module has finished ranging.
int  getRange ()
  Gets the measured range from the module.
int  getLightIntensity ()
  Gets the measured light intensity from the module.
void  setRangeRegister (unsigned char rangeVal)
  Sets the range register of the SRF08 for faster ranging.
void  setMaxGainRegister (unsigned char gainVal)
  Sets the max gain register of the SRF08 .
void  setAddress (int i2cAddress)
  Changes the I2C address of the SRF08 .




6 comments:

02 Sep 2010

If you need a Sonar sensor, you might also consider the Maxbotix EZ series Sonar modules (www.maxbotix.com) . It is smaller and has an analog out, so a single analog in pin can read it. It will run off 3.3V. Phidgets and Robotics Connection also sells them.

/media/uploads/4180_1/maxsonar-ez1.jpg

23 Aug 2011

How you have connected the SRF08 to mbed? I have read the DS of SRF08 and it work at 5 Volts, but the I2C port of mbed are at 3.3 Volts? I know that there are special IC for the change in level from 5 to 3.3 volts for use on the I2C BUS, you used one of this?

23 Jan 2012

I am trying to compile the program but I get this error: " Undefined symbol main (referred from rtentry2.o)." in file "/", do not know how to solve it?

23 Jan 2012

user Danna Vila wrote:

I am trying to compile the program but I get this error: " Undefined symbol main (referred from rtentry2.o)." in file "/", do not know how to solve it?

First check if your code syntax is correct, I think you write something wrong in the "main" definition. If you don't resolve, post your code here.

24 Jan 2012

I manage to compile the program but It doesn't show the "prinf".

  1. include "mbed.h"
  2. include "SRF08.h"

SRF08 srf08(p9, p10, 0xE0); Define SDA, SCL pin and I2C address

int main() {

while (1) { printf("Measured range : %.2f cm\n",srf08.read()); wait(0.1); }

}

How can I see it?

Thank you so much for your help.

24 Jan 2012

user Danna Vila wrote:

I manage to compile the program but It doesn't show the "prinf".

Have you read this? http://mbed.org/handbook/SerialPC