Loading...
Searching...
No Matches
srf02.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2013 Zakaria Kasmi <zkasmi@inf.fu-berlin.de>
3 * SPDX-FileCopyrightText: 2015 Freie Universität Berlin
4 * SPDX-License-Identifier: LGPL-2.1-only
5 */
6
7#pragma once
8
23
24#include <stdint.h>
25#include "periph/i2c.h"
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
34#define SRF02_DEFAULT_ADDR (0xe0) /* 224 decimal */
35
39#define SRF02_RANGE_DELAY (70000U)
40
44typedef struct {
46 uint8_t addr;
47} srf02_t;
48
60
71int srf02_init(srf02_t *dev, i2c_t i2c, uint8_t addr);
72
91int srf02_trigger(const srf02_t *dev, srf02_mode_t mode);
92
101uint16_t srf02_read(const srf02_t *dev);
102
118uint16_t srf02_get_distance(const srf02_t *dev, srf02_mode_t mode);
119
129int srf02_set_addr(srf02_t *dev, uint8_t new_addr);
130
131#ifdef __cplusplus
132}
133#endif
134
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition i2c.h:155
srf02_mode_t
Possible measurement modes of the SRF02 sensor.
Definition srf02.h:52
uint16_t srf02_read(const srf02_t *dev)
Read the results of the last ranging operation.
int srf02_trigger(const srf02_t *dev, srf02_mode_t mode)
Trigger a new measurement.
int srf02_init(srf02_t *dev, i2c_t i2c, uint8_t addr)
Initialize the SRF02 ultrasonic sensor.
int srf02_set_addr(srf02_t *dev, uint8_t new_addr)
Program the given device with a new bus address.
uint16_t srf02_get_distance(const srf02_t *dev, srf02_mode_t mode)
Get the distance measured from the SRF02 ultrasonic sensor.
@ SRF02_MODE_REAL_INCH
result in inches
Definition srf02.h:53
@ SRF02_MODE_REAL_MS
result in microseconds
Definition srf02.h:55
@ SRF02_MODE_REAL_CM
result in centimeters
Definition srf02.h:54
@ SRF02_MODE_FAKE_CM
result in cm (no pulse send)
Definition srf02.h:57
@ SRF02_MODE_FAKE_MS
result in ms (no pulse send)
Definition srf02.h:58
@ SRF02_MODE_FAKE_INCH
result in inches (no pulse send)
Definition srf02.h:56
Low-level I2C peripheral driver interface definition.
Device descriptor for SRF02 sensors.
Definition srf02.h:44
uint8_t addr
I2C bus address of the sensor.
Definition srf02.h:46
i2c_t i2c
I2C device the sensor is connected to.
Definition srf02.h:45