Library for interfacing the SRF08 ultrasonic range sensor. Most functions of the SRF08 are covered, including interrupt-based waiting for the ranging process to finish

Dependents:   DISCO-F746NG_LCDTS_demo Srf08Test

Embed: (wiki syntax)

« Back to documentation index

SRF08 Class Reference

SRF08 Class Reference

The SRF08 is an ultrasonic range finder with an I2C interface that allows the measurement to be read directly in centimetres. More...

#include <SRF08.h>

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.

Detailed Description

The SRF08 is an ultrasonic range finder with an I2C interface that allows the measurement to be read directly in centimetres.

More information can be found on this website: http://www.robot-electronics.co.uk/htm/srf08tech.shtml

Definition at line 33 of file SRF08.h.


Constructor & Destructor Documentation

SRF08 ( PinName  SDA,
PinName  SCL,
int  i2cAddress 
)

Create a SRF08 object connected to the specified I2C pins and address.

Parameters:
SDAI2C SDA pin to connect to
SCLI2C SCL pin to connect to
i2cAddressAddress of WSRF08 on I2C bus

Definition at line 31 of file SRF08.cpp.


Member Function Documentation

int getLightIntensity (  )

Gets the measured light intensity from the module.

Parameters:
returnsA normalised number 0-255 representing dark to light

Definition at line 90 of file SRF08.cpp.

int getRange (  )

Gets the measured range from the module.

Parameters:
returnsInteger range in centimetre

Definition at line 72 of file SRF08.cpp.

bool rangingFinished (  )

Checks if the module has finished ranging.

Parameters:
returnsBoolean stating module is finished or not

Definition at line 61 of file SRF08.cpp.

void setAddress ( int  i2cAddress )

Changes the I2C address of the SRF08.

The factory default address is 0x0E (224) The address can have the following values: E0 | E2 | E4 | E6 ... FC | FE

Parameters:
i2cAddressThe new I2C address for the SRF08.

Definition at line 129 of file SRF08.cpp.

void setMaxGainRegister ( unsigned char  gainVal )

Sets the max gain register of the SRF08.

Parameters:
gainValThe value written to the max gain register of the SRF08

Definition at line 115 of file SRF08.cpp.

void setRangeRegister ( unsigned char  rangeVal )

Sets the range register of the SRF08 for faster ranging.

The max range is ((rangeVal x 43mm) + 43mm). The sensors maximum range is about six metres

Parameters:
rangeValThe value written to the range register of the SRF08

Definition at line 107 of file SRF08.cpp.

void startRanging (  )

Send the "Start ranging in cm" command via I2C.

Definition at line 45 of file SRF08.cpp.