SparkFun Qwiic Ultrasonic Distance Sensor  v1.1.2-13-g96f7fa8
SparkFun Qwiic Ultrasonic Distance Sensor
Loading...
Searching...
No Matches
sfDevUltrasonicDist.h
Go to the documentation of this file.
1
15#pragma once
16
17#include <stdint.h>
18
19// include the sparkfun toolkit headers
20#include <sfTk/sfToolkit.h>
21
22// Bus interfaces
23#include <sfTk/sfTkII2C.h>
24
25// Available I2C addresses of the Qwiic Ultrasonic
26const uint8_t kQwiicUltrasonicDefaultAddress = 0x2F;
27
28// Firmware versions. The later hardware version is v10 and so the "latest" here
29// refers to that. The previous version is randomly given the value v01.
30const uint8_t kQwiicUltrasonicFWLatest = 0x10;
31const uint8_t kQwiicUltrasonicFWOld = 0x01;
32
33// These addresses are the min and max (respectively) of valid I2C addresses that can
34// be used for the newest revision of the Qwiic Ultrasonic sensor.
35const uint8_t kQwiicUltrasonicI2CAddressMin = 0x08;
36const uint8_t kQwiicUltrasonicI2CAddressMax = 0x77;
37
38// Available I2C addresses of the older SparkFun Qwiic Ultrasonic Sensor.
39const uint8_t kQwiicUltrasonicMinAddress = 0x20;
40const uint8_t kQwiicUltrasonicMaxAddress = 0x2F;
41;
42// I2C commands
43const uint8_t kUltrasonicDistanceReadCommand = 0x01;
45
47{
48 public:
52 {
53 }
54
58 sfDevUltrasonicDist(const uint8_t fwVersion) : _theBus(nullptr), _fwVersion(fwVersion)
59 {
60 }
61
65 sfTkError_t begin(sfTkII2C *theBus = nullptr);
66
69 sfTkError_t isConnected();
70
74 sfTkError_t triggerAndRead(uint16_t &distance);
75
79 sfTkError_t changeAddress(uint8_t &address);
80
83 uint8_t getAddress();
84
85 protected:
86 sfTkII2C *_theBus;
87
88 private:
89 uint8_t _fwVersion = 0x00;
90};
Definition: sfDevUltrasonicDist.h:47
sfTkError_t changeAddress(uint8_t &address)
Changes the I2C address of older Qwiic Ultrasonic sensors.
Definition: sfDevUltrasonicDist.cpp:72
sfTkError_t isConnected()
Checks if the Qwiic Ultrasonic sensor is connected.
Definition: sfDevUltrasonicDist.cpp:44
sfTkII2C * _theBus
Definition: sfDevUltrasonicDist.h:86
sfDevUltrasonicDist()
Default constructor.
Definition: sfDevUltrasonicDist.h:51
sfTkError_t triggerAndRead(uint16_t &distance)
Triggers a new measurement and reads the previous one.
Definition: sfDevUltrasonicDist.cpp:51
sfTkError_t begin(sfTkII2C *theBus=nullptr)
Begins the Qwiic Ultrasonic sensor.
Definition: sfDevUltrasonicDist.cpp:18
uint8_t getAddress()
Gets the current I2C address being used by the library for the Qwiic Ultrasonic sensor.
Definition: sfDevUltrasonicDist.cpp:115
sfDevUltrasonicDist(const uint8_t fwVersion)
Alternate constructor.
Definition: sfDevUltrasonicDist.h:58
const uint8_t kQwiicUltrasonicI2CAddressMin
Definition: sfDevUltrasonicDist.h:35
const uint8_t kQwiicUltrasonicMinAddress
Definition: sfDevUltrasonicDist.h:39
const uint8_t kUltrasonicDistanceReadCommand
Definition: sfDevUltrasonicDist.h:43
const uint8_t kQwiicUltrasonicDefaultAddress
Definition: sfDevUltrasonicDist.h:26
const uint8_t kQwiicUltrasonicFWOld
Definition: sfDevUltrasonicDist.h:31
const uint8_t kQwiicUltrasonicI2CAddressMax
Definition: sfDevUltrasonicDist.h:36
const uint8_t kQwiicUltrasonicFWLatest
Definition: sfDevUltrasonicDist.h:30
const uint8_t kQwiicUltrasonicMaxAddress
Definition: sfDevUltrasonicDist.h:40
const uint8_t kUltrasonicAddressChangeCommand
Definition: sfDevUltrasonicDist.h:44