|
1 | 1 | # ads101x
|
2 |
| -A cross-platform driver for the TI ADS101x family of analog-to-digital converters. |
| 2 | + |
| 3 | +A C++ driver for the Texas Instruments [ADS101x](https://www.ti.com/lit/ds/symlink/ads1015.pdf) family of analog-to-digital converters. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The ads101x library provides a driver that allows you to easily interface with the Texas Instruments ADS101x (ADS1013, ADS1014, ADS1015) series of analog-to-digital (ADC) converters. It offers a flexible and extensible way to communicate with the ADS101x devices, abstracting away the low-level details of I2C communication and providing a clean API for your applications. Features include: |
| 8 | + |
| 9 | +- Abstracts I2C communication with the ADS101x devices. |
| 10 | +- Provides a consistent API for configuration, conversion, thresholds, and alerts. |
| 11 | +- Supports different platform-specific variants to suit your needs. |
| 12 | + |
| 13 | +**License:** [MIT Open Source](LICENSE) |
| 14 | + |
| 15 | +## Table of Contents |
| 16 | + |
| 17 | +1. [Multi-Platform Support](#1-multi-platform-support) |
| 18 | +2. [Getting Started](#2-getting-started) |
| 19 | +3. [Usage](#3-usage) |
| 20 | +4. [API Documentation](#4-api-documentation) |
| 21 | +5. [Contributing](#5-contributing) |
| 22 | + |
| 23 | +## 1: Multi-Platform Support |
| 24 | + |
| 25 | +The ADS101x library provides multi-platform support, allowing you to use the driver on different hardware platforms with ease. The library includes multiple variants for platforms such as the Raspberry Pi, and includes a base driver class that can be overidden to support other platforms. |
| 26 | + |
| 27 | +### 1.1: Base Driver: |
| 28 | + |
| 29 | +The base driver offers a platform-agnostic implementation of the ADS101x driver. It serves as the foundation for the other variants and can be used with any I2C library or environment. Create a class derived from the base driver, and override the necessary platform-specific functions. If you need to do so in a separate project, compile the ads101x library using the ```-DADS101X_BASE=ON``` option when configuring with cmake to generate a static library containing the base driver functionality. |
| 30 | + |
| 31 | +### 1.2: Raspberry Pi Drivers: |
| 32 | + |
| 33 | +1. **pigpio**: This platform variant is based on the [pigpio](http://abyz.me.uk/rpi/pigpio/index.html) library, and uses the standard single-process implementation of pigpio. To build the library for this platform, use the ```-DADS101X_PIGPIO=ON``` option when configuring with cmake. Make sure to install pigpio beforehand as it is a dependency. |
| 34 | + |
| 35 | +2. **pigpiod**: This platform variant is based on the [pigpio](http://abyz.me.uk/rpi/pigpio/index.html) library, and uses the daemon implementation of pigpio. To build the library for this platform, use the ```-DADS101X_PIGPIOD=ON``` option when configuring with cmake. Make sure to install pigpio beforehand as it is a dependency. |
| 36 | + |
| 37 | +## 2: Getting Started |
| 38 | + |
| 39 | +To use the ads101x library in your project, clone the repository and follow these steps: |
| 40 | + |
| 41 | +```bash |
| 42 | +# Create a build directory and change into it. |
| 43 | +mkdir build && cd build |
| 44 | +# Configure the project using cmake (see build options below). |
| 45 | +cmake <options> .. |
| 46 | +# Build the project. |
| 47 | +make |
| 48 | +``` |
| 49 | + |
| 50 | +### 2.1: Build Options |
| 51 | + |
| 52 | +The following options can be used with cmake to configure which libraries and functionalities are built: |
| 53 | + |
| 54 | +- ```-DADS101X_BASE=ON```: Builds the base driver library. |
| 55 | +- ```-DADS101X_PIGPIO=ON```: Builds the [pigpio](#12-raspberry-pi-drivers) platform library. |
| 56 | +- ```-DADS101X_PIGPIOD=ON```: Builds the [pigpiod](#12-raspberry-pi-drivers) platform library. |
| 57 | +- ```-DADS101X_TESTS=ON```: Builds unit test executables for all enabled platforms. |
| 58 | + |
| 59 | +## 3: Usage |
| 60 | + |
| 61 | +To use the library in your code, include the necessary headers and link against the appropriate ads101x static library. See the [API Documentation](#4-api-documentation) section for instructions on how to generate and view the library's API documentation files. |
| 62 | + |
| 63 | +**Code Example:** |
| 64 | + |
| 65 | +```cpp |
| 66 | +#include <ads101x/pigpio/driver.hpp> |
| 67 | + |
| 68 | +// Create a driver instance |
| 69 | +ads101x::pigpio::driver driver; |
| 70 | + |
| 71 | +// Initialize the pigpio library if not done elsewhere. |
| 72 | +driver.pigpio_initialize(); |
| 73 | + |
| 74 | +// Start the driver using default I2C bus and slave address. |
| 75 | +driver.start(); |
| 76 | + |
| 77 | +// Create a configuration to write to the ADS101x. |
| 78 | +ads101x::configuration config; |
| 79 | +config.set_operation(ads101x::configuration::operation::CONVERT); |
| 80 | +config.set_multiplexer(ads101x::configuration::multiplexer::AIN0_GND); |
| 81 | +config.set_data_rate(ads101x::configuration::data_rate::SPS_3300); |
| 82 | +config.set_fsr(ads101x::configuration::fsr::FSR_6_114); |
| 83 | + |
| 84 | +// Write configuration to begin conversion. |
| 85 | +driver.write_config(config); |
| 86 | + |
| 87 | +// Wait for conversion to complete. |
| 88 | +usleep(10000); |
| 89 | + |
| 90 | +// Read a conversion value. |
| 91 | +uint16_t conversion = driver.read_conversion(); |
| 92 | + |
| 93 | +// Stop the driver |
| 94 | +driver.stop(); |
| 95 | + |
| 96 | +// Terminate the pigpio library if not done elsewhere. |
| 97 | +driver.pigpio_terminate(); |
| 98 | +``` |
| 99 | +
|
| 100 | +## 4: API Documentation |
| 101 | +
|
| 102 | +The library uses ```doxygen``` for API documentation. To generate and view the documentation: |
| 103 | +
|
| 104 | +```bash |
| 105 | +# Start from the repository root directory. |
| 106 | +
|
| 107 | +# Generate the documentation files. |
| 108 | +doxygen doxyfile |
| 109 | +
|
| 110 | +# Open the documentation using your default html application. |
| 111 | +xdg-open doc/html/index.html |
| 112 | +``` |
| 113 | + |
| 114 | +## 5: Contributing |
| 115 | + |
| 116 | +Contributions to the ads101x library are welcome! If you encounter issues, have suggestions, or want to contribute enhancements, feel free to open an issue or submit a pull request. |
0 commit comments