SRF08 ultrasonic range sensor

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

Detailed Description

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


file  srf08.h
 Driver definitions for the SRF02 ultrasonic ranger.

Data Structures

struct  srf08_t
 Device descriptor for SRF08 sensors. More...


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


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


int srf08_init (srf08_t *dev, i2c_t i2c, uint8_t addr, i2c_speed_t speed)
 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


#define SRF08_GAIN_REG   0x1

gain register (write)

Definition at line 44 of file srf08.h.

Enumeration Type Documentation

◆ srf08_mode_t


result in inches


result in centimeters


result in centimeters


synchronous measurement in inches


synchronous measurement in centimeters


synchronous measurement in microseconds

Definition at line 78 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 

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

[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.
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,
i2c_t  i2c,
uint8_t  addr,
i2c_speed_t  speed 
[in]devdevice descriptor of an SRF08 sensor
[in]i2cI2C device the sensor is connected to
[in]addrI2C address of the sensor
[in]speedI2C speed mode
0 on successful initialization
-1 on undefined device given
-2 on unsupported speed value
-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 

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

[in]devdevice descriptor of an SRF08 sensor
[in]max_gainthe maximal gain value.
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 
[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.
1 on success
-1 on undefined device given