SRF08 ultrasonic range sensor

Driver for the SRF08 ultrasonic range sensor.

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

enum srf08_mode_t
SRF08_MODE_INCH =          0x50
result in inches
SRF08_MODE_CM =            0x51
result in centimeters
SRF08_MODE_MICRO_SEC =     0x52
result in centimeters
SRF08_ANN_MODE_INCH =      0x53
synchronous measurement in inch
SRF08_ANN_MODE_CM =        0x54
synchronous measurement in cm
SRF08_ANN_MODE_MICRO_SEC = 0x55
synchronous measurement in us
int srf08_init(srf08_t * dev, i2c.h::i2c_t i2c, uint8_t addr)

Initialize the SRF08 ultrasonic sensor.

Parameters

dev:device descriptor of an SRF08 sensor
i2c:I2C device the sensor is connected to
addr:I2C address of the sensor

Return values

  • 0 on successful initialization
  • -3 on max. range error
  • -4 on max. gain error
int srf08_set_max_range(const srf08_t * dev, uint8_t max_range)

Set the maximum range of the SRF08.

Parameters

dev:device descriptor of an SRF08 sensor
max_range:the adjusted maximal range is: max_range = (max_range x 43mm) + 43mm. The hardware limit is 6m.

Return values

  • 1 on success
  • -1 on undefined device given
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

dev:device descriptor of an SRF08 sensor
max_gain:the maximal gain value.

Return values

  • 1 on success
  • -1 on undefined device given
int srf08_get_distances(const srf08_t * dev, uint16_t * range_array, int num_echos, srf08.h::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

dev:device descriptor of an SRF08 sensor
range_array:a pointer to a buffer holding the ranging results.
num_echos:number of stored measurements (echos)
ranging_mode:there 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.

Return values

  • 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_DEFAULT_ADDR

The sensors default I2C address.

1
112
SRF08_COMMAND_REG

The sensors command register (write)

1
0x0
SRF08_GAIN_REG

Max.

1
0x1

gain register (write)

SRF08_RANGE_REG

The sensors range register (write)

1
0x2
SRF08_RANGE_HIGH_BYTE

The upper measurement byte (read)

1
0x2
SRF08_RANGE_LOW_BYTE

The lower measurement byte (read)

1
0x3
SRF08_MAX_REGISTER_NUMBER

Number of highest register.

1
35
SRF08_MAX_ECHO_NUMBER

Maximum number of echos from more distant objects.

1
17
SRF08_MAX_RANGE_6M

Maximum range the sensor can measure (6m)

1
0x8C
SRF08_MAX_GAIN

Maximum gain of the sensor (1025)

1
0x1F
struct srf08_t

Device descriptor for SRF08 sensors.

i2c.h::i2c_t i2c

I2C device the sensor is connected to.

uint8_t addr

I2C bus address of the sensor.