|
1 |
| -SparkFun Qwiic Ultrasonic Arduino Library |
2 |
| -======================================== |
3 |
| - |
4 |
| -<table class="table table-hover table-striped table-bordered"> |
5 |
| - <tr> |
6 |
| - <th class="text-center"> |
7 |
| - </th> |
8 |
| - </tr> |
9 |
| - <tr align="center"> |
10 |
| - <td><a href="https://www.sparkfun.com/products/24805"><img src="https://cdn.sparkfun.com/assets/parts/2/5/0/9/7/SEN-24805-Ultrasonic-Distance-Sensor-Feature.jpg" alt=""></a></td> |
11 |
| - </tr> |
12 |
| - <tr align="center"> |
13 |
| - <td><a href="https://www.sparkfun.com/products/24805">SparkFun Ultrasonic Distance Sensor - TCT40 (Qwiic)</a></td> |
14 |
| - </tr> |
15 |
| -</table> |
16 |
| - |
17 |
| -The SparkFun Qwiic Ultrasonic Distance Sensor, a user-friendly upgrade to the popular HC-SR04 sensor, offers non-contact distance measurement from 2cm to 400cm with an accuracy of 3mm. This sensor is designed to seamlessly integrate with the Qwiic ecosystem for I<sup>2</sup>C communication, making it a breeze to add to your existing projects and daisy-chain with other Qwiic components. |
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | +# SparkFun Ultrasonic Distance Sensor - TCT40 |
| 5 | + |
| 6 | +Arduino Library for the SparkFun SparkFun Ultrasonic Distance Sensor |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +The [SparkFun Ultrasonic Distance Sensor - TCT40 (sen-24805)](https://www.sparkfun.com/sparkfun-ultrasonic-distance-sensor-tct40-qwiic.html) a user-friendly upgrade to the popular HC-SR04 sensor, offers non-contact distance measurement from 2cm to 400cm with an accuracy of 3mm. This sensor is designed to seamlessly integrate with the Qwiic ecosystem for I2C communication, making it a breeze to add to your existing projects and daisy-chain with other Qwiic components. |
| 17 | + |
| 18 | +If you prefer to bypass the Qwiic connector and I2C, you can also access the VCC, Trigger, Echo, and Ground pins broken out on the board's edge. Please be aware that this ultrasonic sensor comes uncalibrated, and you will need to manipulate the raw output for your specific application. |
18 | 19 |
|
19 | 20 | With its wide range of applications, the SparkFun Qwiic Ultrasonic Distance Sensor is a versatile tool for robotics projects, obstacle avoidance systems, and any application that requires accurate distance measurement without physical contact. Its adaptability makes it a valuable addition to your toolkit.
|
20 | 21 |
|
21 |
| -Repository Contents |
22 |
| -------------------- |
| 22 | +Looking for the board that matches this library - pick up a [SparkFun Ultrasonic Distance Sensor - TCT40 (Qwiic)](https://www.sparkfun.com/sparkfun-ultrasonic-distance-sensor-tct40-qwiic.html) at www.sparkfun.com. |
| 23 | + |
| 24 | +## Functionality |
| 25 | + |
| 26 | +This library provides a simple interface that enables the following functionality when using the SparkFun Qwiic Ultrasonic Distance Sensor: |
| 27 | + |
| 28 | +* Read the distance detected by the sensor |
| 29 | +* Change the I2C address of the sensor - if you want to avoid a conflict, or used multiple moisture sensors together. |
| 30 | + |
| 31 | +## General Use |
| 32 | + |
| 33 | +The following outlines the general use of the library in an Arduino Sketch. |
| 34 | + |
| 35 | +### Declaration |
| 36 | + |
| 37 | +At the start of your sketch, the library header file is included using the following statement: |
| 38 | + |
| 39 | +~~~cpp |
| 40 | +#include "SparkFun_Qwiic_Ultrasonic_Arduino_Library.h" |
| 41 | +~~~ |
| 42 | + |
| 43 | +Before the arduino ```setup()``` function, create a Ultrasonic Distance Sensor object in your file with the following declaration: |
| 44 | + |
| 45 | +~~~c |
| 46 | +QwiicUltrasonic myUltrasonic; // Create an instance of the sensor class |
| 47 | +~~~ |
| 48 | + |
| 49 | +### Initialization |
| 50 | + |
| 51 | +In the Arduino ```setup()``` function, initialize the sensor by calling the begin method. This method is called after the Arduino `Wire` (I2C) library is initialized. |
| 52 | + |
| 53 | +~~~cpp |
| 54 | +// Attempt to begin the sensor |
| 55 | +while (myUltrasonic.begin(deviceAddress) == false) |
| 56 | +{ |
| 57 | + Serial.println("Ultrasonic sensor not connected, check your wiring and I2C address!"); |
| 58 | + delay(2000); |
| 59 | +} |
| 60 | +~~~ |
| 61 | + |
| 62 | +The begin method returns true if the sensor is connected and available, and false if it is not. |
| 63 | + |
| 64 | +### Usage |
| 65 | + |
| 66 | +#### Read Value |
| 67 | + |
| 68 | +To read the value from the sensor, the *triggerAndRead()* method is called on the sensor object. |
| 69 | + |
| 70 | +~~~cpp |
| 71 | +uint16_t distance = 0; |
| 72 | +myUltrasonic.triggerAndRead(distance); |
| 73 | +~~~ |
| 74 | + |
| 75 | +The value returned is a distance value measured in millimeters |
| 76 | + |
| 77 | +## Examples |
23 | 78 |
|
24 |
| -* **/documents** - Data sheets, additional product information |
25 |
| -* **/examples** - Example code |
26 |
| -* **/src** - Source code |
| 79 | +The following examples are provided with the library |
27 | 80 |
|
28 |
| -Documentation |
29 |
| --------------- |
30 |
| -* **[Hookup Guide](https://docs.sparkfun.com/SparkFun_Ultrasonic_Distance_Sensor-Qwiic/)** - Basic hookup guide for the SparkFun Ultrasonic Distance Sensor - TCT40 (Qwiic). |
31 |
| -* **[Product Repo](https://github.com/sparkfun/SparkFun_Ultrasonic_Distance_Sensor-Qwiic)** - GitHub repo for the SparkFun Ultrasonic Distance Sensor - TCT40 (Qwiic) GitHub Pages and hardware files. |
| 81 | +- [Basic Readings](examples/Example1_BasicReadings/Example1_BasicReadings.ino) - Setup and read the detected distance value |
| 82 | +- [OLED Distance](examples/Example2_OLED_Distance/Example2_OLED_Distance.ino) - Read the sensed distance and display on an OLED display |
| 83 | +- [Trigger Echo](examples/Example3_Trigger_Echo/Example3_Trigger_Echo.ino) - Control the sensor and get values manually |
| 84 | +- [Change Address](examples/Example4_ChangeAddress/Example4_ChangeAddress.ino) - Change the I2C address of the Ultrasonic Distance sensor device |
32 | 85 |
|
33 |
| -License Information |
34 |
| -------------------- |
| 86 | +## Documentation |
35 | 87 |
|
36 |
| -This product is _**open source**_! |
| 88 | +The full API and use documentation for this library is provided [here](http://docs.sparkfun.com/SparkFun_Qwiic_Ultrasonic_Arduino_Library/). For a quick reference, the main methods available in the library are listed [here](https://docs.sparkfun.com/SparkFun_Qwiic_Ultrasonic_Arduino_Library/functions.html). |
37 | 89 |
|
38 |
| -Please review the LICENSE.md file for license information. |
| 90 | +Curious about the hardware this board works with - visit the SparkFun Qwiic Ultrasonic Distance Sensor [hardware repository](https://github.com/sparkfun/SparkFun_Ultrasonic_Distance_Sensor-Qwiic). |
39 | 91 |
|
40 |
| -If you have any questions or concerns on licensing, please contact technical support on our [SparkFun forums](https://forum.sparkfun.com/viewforum.php?f=152). |
| 92 | +The Hookup Guide for the SparkFun Qwiic Ultrasonic Distance Sensor is available [here](https://docs.sparkfun.com/SparkFun_Ultrasonic_Distance_Sensor-Qwiic/introduction/). |
41 | 93 |
|
42 |
| -Distributed as-is; no warranty is given. |
| 94 | +## License Information |
43 | 95 |
|
44 |
| -- Your friends at SparkFun. |
| 96 | +This product is ***open source***! |
45 | 97 |
|
46 |
| -_<COLLABORATION CREDIT>_ |
| 98 | +This product is licensed using the [MIT Open Source License](https://opensource.org/license/mit). |
0 commit comments