Driver for the SRF02 ultrasonic range sensor.
More...
Driver for the SRF02 ultrasonic range sensor.
|
file | srf02.h |
| Driver definitions for the SRF02 ultrasonic ranger.
|
|
◆ SRF02_DEFAULT_ADDR
#define SRF02_DEFAULT_ADDR (0xe0) /* 224 decimal */ |
Default I2C address of SRF02 sensors.
Definition at line 38 of file srf02.h.
◆ SRF02_RANGE_DELAY
#define SRF02_RANGE_DELAY (70000U) |
The datasheet tells us, that ranging takes 70ms.
Definition at line 43 of file srf02.h.
◆ srf02_mode_t
Possible measurement modes of the SRF02 sensor.
Enumerator |
---|
SRF02_MODE_REAL_INCH | result in inches
|
SRF02_MODE_REAL_CM | result in centimeters
|
SRF02_MODE_REAL_MS | result in microseconds
|
SRF02_MODE_FAKE_INCH | result in inches (no pulse send)
|
SRF02_MODE_FAKE_CM | result in cm (no pulse send)
|
SRF02_MODE_FAKE_MS | result in ms (no pulse send)
|
Definition at line 56 of file srf02.h.
◆ srf02_get_distance()
Get the distance measured from the SRF02 ultrasonic sensor.
This function combines the srf02_trigger and the srf02_read functions for simplified usage in simple (single sensor) setups.
- Parameters
-
[in] | dev | device descriptor of an SRF02 sensor |
[in] | 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 |
- Returns
- the ranging result in inches, centimeters or microseconds
◆ srf02_init()
Initialize the SRF02 ultrasonic sensor.
- Parameters
-
[in] | dev | device descriptor of an SRF02 sensor |
[in] | i2c | I2C device the sensor is connected to |
[in] | addr | I2C address of the sensor |
- Returns
- 0 on successful initialization
-
-1 on error
◆ srf02_read()
uint16_t srf02_read |
( |
const srf02_t * |
dev | ) |
|
Read the results of the last ranging operation.
- Parameters
-
[in] | dev | device to read from |
- Returns
- result of the last ranging operation, meaning depends on the mode parameter given to the srf02_trigger function
◆ srf02_set_addr()
int srf02_set_addr |
( |
srf02_t * |
dev, |
|
|
uint8_t |
new_addr |
|
) |
| |
Program the given device with a new bus address.
- Parameters
-
[in] | dev | device to program |
[in] | new_addr | new address to program the given device to |
- Returns
- 0 On success, otherwise i2c_write error
◆ srf02_trigger()
Trigger a new measurement.
This function triggers a new ranging operation. After triggering this operation, you have to wait at least 70ms for the result to be ready.
The result of the ranging operation is returned in inches, centimeters or microseconds - depending on the given mode
parameter.
- Parameters
-
[in] | dev | device to trigger |
[in] | 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 |
- Returns
- 0 On success, otherwise i2c_write error