SRF08 ultrasonic range sensor

Driver for the SRF08 ultrasonic range sensor. More...

Detailed Description

Driver for the SRF08 ultrasonic range sensor.

The connection between the MCU and the SRF08 is based on the i2c-interface.

Files

file  srf08.h
 Driver definitions for the SRF02 ultrasonic ranger.
 
file  srf08_params.h
 Default configuration for srf08 devices.
 

Data Structures

struct  srf08_params_t
 Device initialization parameters. More...
 
struct  srf08_t
 Device descriptor for SRF08 sensors. More...
 

Macros

#define SRF08_COMMAND_REG   0x0
 The sensors command register (write) More...
 
#define SRF08_GAIN_REG   0x1
 Max. More...
 
#define SRF08_RANGE_REG   0x2
 The sensors range register (write) More...
 
#define SRF08_RANGE_HIGH_BYTE   0x2
 The upper measurement byte (read) More...
 
#define SRF08_RANGE_LOW_BYTE   0x3
 The lower measurement byte (read) More...
 
#define SRF08_MAX_REGISTER_NUMBER   35
 Number of highest register. More...
 
#define SRF08_MAX_ECHO_NUMBER   17
 Maximum number of echos from more distant objects. More...
 
#define SRF08_MAX_RANGE_6M   0x8C
 Maximum range the sensor can measure (6m) More...
 
#define SRF08_MAX_GAIN   0x1F
 Maximum gain of the sensor (1025) More...
 

Enumerations

enum  srf08_mode_t {
  SRF08_MODE_INCH = 0x50 , SRF08_MODE_CM = 0x51 , SRF08_MODE_MICRO_SEC = 0x52 , SRF08_ANN_MODE_INCH = 0x53 ,
  SRF08_ANN_MODE_CM = 0x54 , SRF08_ANN_MODE_MICRO_SEC = 0x55
}
 Possible measurement modes for the SRF08 sensor. More...
 

Functions

int srf08_init (srf08_t *dev, const srf08_params_t *params)
 Initialize the SRF08 ultrasonic sensor. More...
 
int srf08_set_max_range (const srf08_t *dev, uint8_t max_range)
 Set the maximum range of the SRF08. More...
 
int srf08_set_max_gain (const srf08_t *dev, uint8_t max_gain)
 Set the maximum of the analog stages. More...
 
int srf08_get_distances (const srf08_t *dev, uint16_t *range_array, int num_echos, srf08_mode_t ranging_mode)
 Get all distances measured from the SRF08 ultrasonic sensor. More...
 

Macro Definition Documentation

◆ SRF08_COMMAND_REG

#define SRF08_COMMAND_REG   0x0

The sensors command register (write)

Definition at line 39 of file srf08.h.

◆ SRF08_GAIN_REG

#define SRF08_GAIN_REG   0x1

Max.

gain register (write)

Definition at line 42 of file srf08.h.

◆ SRF08_MAX_ECHO_NUMBER

#define SRF08_MAX_ECHO_NUMBER   17

Maximum number of echos from more distant objects.

Definition at line 57 of file srf08.h.

◆ SRF08_MAX_GAIN

#define SRF08_MAX_GAIN   0x1F

Maximum gain of the sensor (1025)

Definition at line 63 of file srf08.h.

◆ SRF08_MAX_RANGE_6M

#define SRF08_MAX_RANGE_6M   0x8C

Maximum range the sensor can measure (6m)

Definition at line 60 of file srf08.h.

◆ SRF08_MAX_REGISTER_NUMBER

#define SRF08_MAX_REGISTER_NUMBER   35

Number of highest register.

Definition at line 54 of file srf08.h.

◆ SRF08_RANGE_HIGH_BYTE

#define SRF08_RANGE_HIGH_BYTE   0x2

The upper measurement byte (read)

Definition at line 48 of file srf08.h.

◆ SRF08_RANGE_LOW_BYTE

#define SRF08_RANGE_LOW_BYTE   0x3

The lower measurement byte (read)

Definition at line 51 of file srf08.h.

◆ SRF08_RANGE_REG

#define SRF08_RANGE_REG   0x2

The sensors range register (write)

Definition at line 45 of file srf08.h.

Enumeration Type Documentation

◆ srf08_mode_t

Possible measurement modes for the SRF08 sensor.

Enumerator
SRF08_MODE_INCH 

result in inches

SRF08_MODE_CM 

result in centimeters

SRF08_MODE_MICRO_SEC 

result in centimeters

SRF08_ANN_MODE_INCH 

synchronous measurement in inch

SRF08_ANN_MODE_CM 

synchronous measurement in cm

SRF08_ANN_MODE_MICRO_SEC 

synchronous measurement in us

Definition at line 83 of file srf08.h.

Function Documentation

◆ srf08_get_distances()

int srf08_get_distances ( const srf08_t dev,
uint16_t *  range_array,
int  num_echos,
srf08_mode_t  ranging_mode 
)

Get all distances measured from the SRF08 ultrasonic sensor.

The results of a ranging can be returned in inches, centimeters or microseconds. The SRF08 can detect up to 17 targets.

Parameters
[in]devdevice descriptor of an SRF08 sensor
[in]range_arraya pointer to a buffer holding the ranging results.
[in]num_echosnumber of stored measurements (echos)
[in]ranging_modethere are three real ranging modes, which return the result in inches, centimeters or microseconds. Another set of three fake ranging modes do the same but without transmitting the burst.
Returns
number of measured echos on success
-1 on ranging mode errors
-2 if num_echos exceeds the max. number of possible measurements
-3 if i2c read high byte failed
-4 if i2c read low byte failed

◆ srf08_init()

int srf08_init ( srf08_t dev,
const srf08_params_t params 
)

Initialize the SRF08 ultrasonic sensor.

Parameters
[in]devdevice descriptor of an SRF08 sensor
[in]paramsinitialization parameters
Returns
0 on successful initialization
-3 on max. range error
-4 on max. gain error

◆ srf08_set_max_gain()

int srf08_set_max_gain ( const srf08_t dev,
uint8_t  max_gain 
)

Set the maximum of the analog stages.

@ note This value is just a limitation of the maximum amplification and not the actual. While measuring, this value starts at its minimum and increases approx. each 75 us until the maximum value is reached.

Parameters
[in]devdevice descriptor of an SRF08 sensor
[in]max_gainthe maximal gain value.
Returns
1 on success
-1 on undefined device given

◆ srf08_set_max_range()

int srf08_set_max_range ( const srf08_t dev,
uint8_t  max_range 
)

Set the maximum range of the SRF08.

Parameters
[in]devdevice descriptor of an SRF08 sensor
[in]max_rangethe adjusted maximal range is: max_range = (max_range x 43mm) + 43mm. The hardware limit is 6m.
Returns
1 on success
-1 on undefined device given