初始化提交
This commit is contained in:
46
arduino-cli/libraries/Adafruit_ADS1X15/.github/ISSUE_TEMPLATE.md
vendored
Normal file
46
arduino-cli/libraries/Adafruit_ADS1X15/.github/ISSUE_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
Thank you for opening an issue on an Adafruit Arduino library repository. To
|
||||
improve the speed of resolution please review the following guidelines and
|
||||
common troubleshooting steps below before creating the issue:
|
||||
|
||||
- **Do not use GitHub issues for troubleshooting projects and issues.** Instead use
|
||||
the forums at http://forums.adafruit.com to ask questions and troubleshoot why
|
||||
something isn't working as expected. In many cases the problem is a common issue
|
||||
that you will more quickly receive help from the forum community. GitHub issues
|
||||
are meant for known defects in the code. If you don't know if there is a defect
|
||||
in the code then start with troubleshooting on the forum first.
|
||||
|
||||
- **If following a tutorial or guide be sure you didn't miss a step.** Carefully
|
||||
check all of the steps and commands to run have been followed. Consult the
|
||||
forum if you're unsure or have questions about steps in a guide/tutorial.
|
||||
|
||||
- **For Arduino projects check these very common issues to ensure they don't apply**:
|
||||
|
||||
- For uploading sketches or communicating with the board make sure you're using
|
||||
a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes
|
||||
very hard to tell the difference between a data and charge cable! Try using the
|
||||
cable with other devices or swapping to another cable to confirm it is not
|
||||
the problem.
|
||||
|
||||
- **Be sure you are supplying adequate power to the board.** Check the specs of
|
||||
your board and plug in an external power supply. In many cases just
|
||||
plugging a board into your computer is not enough to power it and other
|
||||
peripherals.
|
||||
|
||||
- **Double check all soldering joints and connections.** Flakey connections
|
||||
cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints.
|
||||
|
||||
- **Ensure you are using an official Arduino or Adafruit board.** We can't
|
||||
guarantee a clone board will have the same functionality and work as expected
|
||||
with this code and don't support them.
|
||||
|
||||
If you're sure this issue is a defect in the code and checked the steps above
|
||||
please fill in the following fields to provide enough troubleshooting information.
|
||||
You may delete the guideline and text above to just leave the following details:
|
||||
|
||||
- Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE**
|
||||
|
||||
- Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO
|
||||
VERSION HERE**
|
||||
|
||||
- List the steps to reproduce the problem below (if possible attach a sketch or
|
||||
copy the sketch code in too): **LIST REPRO STEPS BELOW**
|
||||
26
arduino-cli/libraries/Adafruit_ADS1X15/.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
26
arduino-cli/libraries/Adafruit_ADS1X15/.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
Thank you for creating a pull request to contribute to Adafruit's GitHub code!
|
||||
Before you open the request please review the following guidelines and tips to
|
||||
help it be more easily integrated:
|
||||
|
||||
- **Describe the scope of your change--i.e. what the change does and what parts
|
||||
of the code were modified.** This will help us understand any risks of integrating
|
||||
the code.
|
||||
|
||||
- **Describe any known limitations with your change.** For example if the change
|
||||
doesn't apply to a supported platform of the library please mention it.
|
||||
|
||||
- **Please run any tests or examples that can exercise your modified code.** We
|
||||
strive to not break users of the code and running tests/examples helps with this
|
||||
process.
|
||||
|
||||
Thank you again for contributing! We will try to test and integrate the change
|
||||
as soon as we can, but be aware we have many GitHub repositories to manage and
|
||||
can't immediately respond to every request. There is no need to bump or check in
|
||||
on a pull request (it will clutter the discussion of the request).
|
||||
|
||||
Also don't be worried if the request is closed or not integrated--sometimes the
|
||||
priorities of Adafruit's GitHub code (education, ease of use) might not match the
|
||||
priorities of the pull request. Don't fret, the open source community thrives on
|
||||
forks and GitHub makes it easy to keep your changes in a forked repo.
|
||||
|
||||
After reviewing the guidelines above you can delete this text from the pull request.
|
||||
32
arduino-cli/libraries/Adafruit_ADS1X15/.github/workflows/githubci.yml
vendored
Normal file
32
arduino-cli/libraries/Adafruit_ADS1X15/.github/workflows/githubci.yml
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
name: Arduino Library CI
|
||||
|
||||
on: [pull_request, push, repository_dispatch]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: '3.x'
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
repository: adafruit/ci-arduino
|
||||
path: ci
|
||||
|
||||
- name: pre-install
|
||||
run: bash ci/actions_install.sh
|
||||
|
||||
- name: test platforms
|
||||
run: python3 ci/build_platform.py main_platforms
|
||||
|
||||
- name: clang
|
||||
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .
|
||||
|
||||
- name: doxygen
|
||||
env:
|
||||
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
|
||||
PRETTYNAME : "Adafruit ADS1X15 ADC Driver Library"
|
||||
run: bash ci/doxy_gen_and_deploy.sh
|
||||
396
arduino-cli/libraries/Adafruit_ADS1X15/Adafruit_ADS1015.cpp
Normal file
396
arduino-cli/libraries/Adafruit_ADS1X15/Adafruit_ADS1015.cpp
Normal file
@@ -0,0 +1,396 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file Adafruit_ADS1015.cpp
|
||||
@author K.Townsend (Adafruit Industries)
|
||||
|
||||
@mainpage Adafruit ADS1X15 ADC Breakout Driver
|
||||
|
||||
@section intro_sec Introduction
|
||||
|
||||
This is a library for the Adafruit ADS1X15 ADC breakout boards.
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
@section author Author
|
||||
|
||||
Written by Kevin "KTOWN" Townsend for Adafruit Industries.
|
||||
|
||||
@section HISTORY
|
||||
|
||||
v1.0 - First release
|
||||
v1.1 - Added ADS1115 support - W. Earl
|
||||
|
||||
@section license License
|
||||
|
||||
BSD license, all text here must be included in any redistribution
|
||||
*/
|
||||
/**************************************************************************/
|
||||
#if ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
#include "Adafruit_ADS1015.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Abstract away platform differences in Arduino wire library
|
||||
|
||||
@return the byte read
|
||||
*/
|
||||
/**************************************************************************/
|
||||
static uint8_t i2cread(void) {
|
||||
#if ARDUINO >= 100
|
||||
return Wire.read();
|
||||
#else
|
||||
return Wire.receive();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Abstract away platform differences in Arduino wire library
|
||||
|
||||
@param x byte to write
|
||||
*/
|
||||
/**************************************************************************/
|
||||
static void i2cwrite(uint8_t x) {
|
||||
#if ARDUINO >= 100
|
||||
Wire.write((uint8_t)x);
|
||||
#else
|
||||
Wire.send(x);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Writes 16-bits to the specified destination register
|
||||
|
||||
@param i2cAddress I2C address of device
|
||||
@param reg register address to write to
|
||||
@param value value to write to register
|
||||
*/
|
||||
/**************************************************************************/
|
||||
static void writeRegister(uint8_t i2cAddress, uint8_t reg, uint16_t value) {
|
||||
Wire.beginTransmission(i2cAddress);
|
||||
i2cwrite((uint8_t)reg);
|
||||
i2cwrite((uint8_t)(value >> 8));
|
||||
i2cwrite((uint8_t)(value & 0xFF));
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Read 16-bits from the specified destination register
|
||||
|
||||
@param i2cAddress I2C address of device
|
||||
@param reg register address to read from
|
||||
|
||||
@return 16 bit register value read
|
||||
*/
|
||||
/**************************************************************************/
|
||||
static uint16_t readRegister(uint8_t i2cAddress, uint8_t reg) {
|
||||
Wire.beginTransmission(i2cAddress);
|
||||
i2cwrite(reg);
|
||||
Wire.endTransmission();
|
||||
Wire.requestFrom(i2cAddress, (uint8_t)2);
|
||||
return ((i2cread() << 8) | i2cread());
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Instantiates a new ADS1015 class w/appropriate properties
|
||||
|
||||
@param i2cAddress I2C address of device
|
||||
*/
|
||||
/**************************************************************************/
|
||||
Adafruit_ADS1015::Adafruit_ADS1015(uint8_t i2cAddress) {
|
||||
m_i2cAddress = i2cAddress;
|
||||
m_conversionDelay = ADS1015_CONVERSIONDELAY;
|
||||
m_bitShift = 4;
|
||||
m_gain = GAIN_TWOTHIRDS; /* +/- 6.144V range (limited to VDD +0.3V max!) */
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Instantiates a new ADS1115 class w/appropriate properties
|
||||
|
||||
@param i2cAddress I2C address of device
|
||||
*/
|
||||
/**************************************************************************/
|
||||
Adafruit_ADS1115::Adafruit_ADS1115(uint8_t i2cAddress) {
|
||||
m_i2cAddress = i2cAddress;
|
||||
m_conversionDelay = ADS1115_CONVERSIONDELAY;
|
||||
m_bitShift = 0;
|
||||
m_gain = GAIN_TWOTHIRDS; /* +/- 6.144V range (limited to VDD +0.3V max!) */
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets up the HW (reads coefficients values, etc.)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_ADS1015::begin() { Wire.begin(); }
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets the gain and input voltage range
|
||||
|
||||
@param gain gain setting to use
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_ADS1015::setGain(adsGain_t gain) { m_gain = gain; }
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Gets a gain and input voltage range
|
||||
|
||||
@return the gain setting
|
||||
*/
|
||||
/**************************************************************************/
|
||||
adsGain_t Adafruit_ADS1015::getGain() { return m_gain; }
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Gets a single-ended ADC reading from the specified channel
|
||||
|
||||
@param channel ADC channel to read
|
||||
|
||||
@return the ADC reading
|
||||
*/
|
||||
/**************************************************************************/
|
||||
uint16_t Adafruit_ADS1015::readADC_SingleEnded(uint8_t channel) {
|
||||
if (channel > 3) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Start with default values
|
||||
uint16_t config =
|
||||
ADS1015_REG_CONFIG_CQUE_NONE | // Disable the comparator (default val)
|
||||
ADS1015_REG_CONFIG_CLAT_NONLAT | // Non-latching (default val)
|
||||
ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val)
|
||||
ADS1015_REG_CONFIG_CMODE_TRAD | // Traditional comparator (default val)
|
||||
ADS1015_REG_CONFIG_DR_1600SPS | // 1600 samples per second (default)
|
||||
ADS1015_REG_CONFIG_MODE_SINGLE; // Single-shot mode (default)
|
||||
|
||||
// Set PGA/voltage range
|
||||
config |= m_gain;
|
||||
|
||||
// Set single-ended input channel
|
||||
switch (channel) {
|
||||
case (0):
|
||||
config |= ADS1015_REG_CONFIG_MUX_SINGLE_0;
|
||||
break;
|
||||
case (1):
|
||||
config |= ADS1015_REG_CONFIG_MUX_SINGLE_1;
|
||||
break;
|
||||
case (2):
|
||||
config |= ADS1015_REG_CONFIG_MUX_SINGLE_2;
|
||||
break;
|
||||
case (3):
|
||||
config |= ADS1015_REG_CONFIG_MUX_SINGLE_3;
|
||||
break;
|
||||
}
|
||||
|
||||
// Set 'start single-conversion' bit
|
||||
config |= ADS1015_REG_CONFIG_OS_SINGLE;
|
||||
|
||||
// Write config register to the ADC
|
||||
writeRegister(m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config);
|
||||
|
||||
// Wait for the conversion to complete
|
||||
delay(m_conversionDelay);
|
||||
|
||||
// Read the conversion results
|
||||
// Shift 12-bit results right 4 bits for the ADS1015
|
||||
return readRegister(m_i2cAddress, ADS1015_REG_POINTER_CONVERT) >> m_bitShift;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Reads the conversion results, measuring the voltage
|
||||
difference between the P (AIN0) and N (AIN1) input. Generates
|
||||
a signed value since the difference can be either
|
||||
positive or negative.
|
||||
|
||||
@return the ADC reading
|
||||
*/
|
||||
/**************************************************************************/
|
||||
int16_t Adafruit_ADS1015::readADC_Differential_0_1() {
|
||||
// Start with default values
|
||||
uint16_t config =
|
||||
ADS1015_REG_CONFIG_CQUE_NONE | // Disable the comparator (default val)
|
||||
ADS1015_REG_CONFIG_CLAT_NONLAT | // Non-latching (default val)
|
||||
ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val)
|
||||
ADS1015_REG_CONFIG_CMODE_TRAD | // Traditional comparator (default val)
|
||||
ADS1015_REG_CONFIG_DR_1600SPS | // 1600 samples per second (default)
|
||||
ADS1015_REG_CONFIG_MODE_SINGLE; // Single-shot mode (default)
|
||||
|
||||
// Set PGA/voltage range
|
||||
config |= m_gain;
|
||||
|
||||
// Set channels
|
||||
config |= ADS1015_REG_CONFIG_MUX_DIFF_0_1; // AIN0 = P, AIN1 = N
|
||||
|
||||
// Set 'start single-conversion' bit
|
||||
config |= ADS1015_REG_CONFIG_OS_SINGLE;
|
||||
|
||||
// Write config register to the ADC
|
||||
writeRegister(m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config);
|
||||
|
||||
// Wait for the conversion to complete
|
||||
delay(m_conversionDelay);
|
||||
|
||||
// Read the conversion results
|
||||
uint16_t res =
|
||||
readRegister(m_i2cAddress, ADS1015_REG_POINTER_CONVERT) >> m_bitShift;
|
||||
if (m_bitShift == 0) {
|
||||
return (int16_t)res;
|
||||
} else {
|
||||
// Shift 12-bit results right 4 bits for the ADS1015,
|
||||
// making sure we keep the sign bit intact
|
||||
if (res > 0x07FF) {
|
||||
// negative number - extend the sign to 16th bit
|
||||
res |= 0xF000;
|
||||
}
|
||||
return (int16_t)res;
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Reads the conversion results, measuring the voltage
|
||||
difference between the P (AIN2) and N (AIN3) input. Generates
|
||||
a signed value since the difference can be either
|
||||
positive or negative.
|
||||
|
||||
@return the ADC reading
|
||||
*/
|
||||
/**************************************************************************/
|
||||
int16_t Adafruit_ADS1015::readADC_Differential_2_3() {
|
||||
// Start with default values
|
||||
uint16_t config =
|
||||
ADS1015_REG_CONFIG_CQUE_NONE | // Disable the comparator (default val)
|
||||
ADS1015_REG_CONFIG_CLAT_NONLAT | // Non-latching (default val)
|
||||
ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val)
|
||||
ADS1015_REG_CONFIG_CMODE_TRAD | // Traditional comparator (default val)
|
||||
ADS1015_REG_CONFIG_DR_1600SPS | // 1600 samples per second (default)
|
||||
ADS1015_REG_CONFIG_MODE_SINGLE; // Single-shot mode (default)
|
||||
|
||||
// Set PGA/voltage range
|
||||
config |= m_gain;
|
||||
|
||||
// Set channels
|
||||
config |= ADS1015_REG_CONFIG_MUX_DIFF_2_3; // AIN2 = P, AIN3 = N
|
||||
|
||||
// Set 'start single-conversion' bit
|
||||
config |= ADS1015_REG_CONFIG_OS_SINGLE;
|
||||
|
||||
// Write config register to the ADC
|
||||
writeRegister(m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config);
|
||||
|
||||
// Wait for the conversion to complete
|
||||
delay(m_conversionDelay);
|
||||
|
||||
// Read the conversion results
|
||||
uint16_t res =
|
||||
readRegister(m_i2cAddress, ADS1015_REG_POINTER_CONVERT) >> m_bitShift;
|
||||
if (m_bitShift == 0) {
|
||||
return (int16_t)res;
|
||||
} else {
|
||||
// Shift 12-bit results right 4 bits for the ADS1015,
|
||||
// making sure we keep the sign bit intact
|
||||
if (res > 0x07FF) {
|
||||
// negative number - extend the sign to 16th bit
|
||||
res |= 0xF000;
|
||||
}
|
||||
return (int16_t)res;
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets up the comparator to operate in basic mode, causing the
|
||||
ALERT/RDY pin to assert (go from high to low) when the ADC
|
||||
value exceeds the specified threshold.
|
||||
|
||||
This will also set the ADC in continuous conversion mode.
|
||||
|
||||
@param channel ADC channel to use
|
||||
@param threshold comparator threshold
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_ADS1015::startComparator_SingleEnded(uint8_t channel,
|
||||
int16_t threshold) {
|
||||
// Start with default values
|
||||
uint16_t config =
|
||||
ADS1015_REG_CONFIG_CQUE_1CONV | // Comparator enabled and asserts on 1
|
||||
// match
|
||||
ADS1015_REG_CONFIG_CLAT_LATCH | // Latching mode
|
||||
ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val)
|
||||
ADS1015_REG_CONFIG_CMODE_TRAD | // Traditional comparator (default val)
|
||||
ADS1015_REG_CONFIG_DR_1600SPS | // 1600 samples per second (default)
|
||||
ADS1015_REG_CONFIG_MODE_CONTIN | // Continuous conversion mode
|
||||
ADS1015_REG_CONFIG_MODE_CONTIN; // Continuous conversion mode
|
||||
|
||||
// Set PGA/voltage range
|
||||
config |= m_gain;
|
||||
|
||||
// Set single-ended input channel
|
||||
switch (channel) {
|
||||
case (0):
|
||||
config |= ADS1015_REG_CONFIG_MUX_SINGLE_0;
|
||||
break;
|
||||
case (1):
|
||||
config |= ADS1015_REG_CONFIG_MUX_SINGLE_1;
|
||||
break;
|
||||
case (2):
|
||||
config |= ADS1015_REG_CONFIG_MUX_SINGLE_2;
|
||||
break;
|
||||
case (3):
|
||||
config |= ADS1015_REG_CONFIG_MUX_SINGLE_3;
|
||||
break;
|
||||
}
|
||||
|
||||
// Set the high threshold register
|
||||
// Shift 12-bit results left 4 bits for the ADS1015
|
||||
writeRegister(m_i2cAddress, ADS1015_REG_POINTER_HITHRESH,
|
||||
threshold << m_bitShift);
|
||||
|
||||
// Write config register to the ADC
|
||||
writeRegister(m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief In order to clear the comparator, we need to read the
|
||||
conversion results. This function reads the last conversion
|
||||
results without changing the config value.
|
||||
|
||||
@return the last ADC reading
|
||||
*/
|
||||
/**************************************************************************/
|
||||
int16_t Adafruit_ADS1015::getLastConversionResults() {
|
||||
// Wait for the conversion to complete
|
||||
delay(m_conversionDelay);
|
||||
|
||||
// Read the conversion results
|
||||
uint16_t res =
|
||||
readRegister(m_i2cAddress, ADS1015_REG_POINTER_CONVERT) >> m_bitShift;
|
||||
if (m_bitShift == 0) {
|
||||
return (int16_t)res;
|
||||
} else {
|
||||
// Shift 12-bit results right 4 bits for the ADS1015,
|
||||
// making sure we keep the sign bit intact
|
||||
if (res > 0x07FF) {
|
||||
// negative number - extend the sign to 16th bit
|
||||
res |= 0xF000;
|
||||
}
|
||||
return (int16_t)res;
|
||||
}
|
||||
}
|
||||
177
arduino-cli/libraries/Adafruit_ADS1X15/Adafruit_ADS1015.h
Normal file
177
arduino-cli/libraries/Adafruit_ADS1X15/Adafruit_ADS1015.h
Normal file
@@ -0,0 +1,177 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file Adafruit_ADS1015.h
|
||||
|
||||
This is a library for the Adafruit ADS1X15 ADC breakout boards.
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Kevin "KTOWN" Townsend for Adafruit Industries.
|
||||
|
||||
BSD license, all text here must be included in any redistribution
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef __ADS1015_H__
|
||||
#define __ADS1015_H__
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
/*=========================================================================
|
||||
I2C ADDRESS/BITS
|
||||
-----------------------------------------------------------------------*/
|
||||
#define ADS1015_ADDRESS (0x48) ///< 1001 000 (ADDR = GND)
|
||||
/*=========================================================================*/
|
||||
|
||||
/*=========================================================================
|
||||
CONVERSION DELAY (in mS)
|
||||
-----------------------------------------------------------------------*/
|
||||
#define ADS1015_CONVERSIONDELAY (1) ///< Conversion delay
|
||||
#define ADS1115_CONVERSIONDELAY (9) ///< Conversion delay
|
||||
/*=========================================================================*/
|
||||
|
||||
/*=========================================================================
|
||||
POINTER REGISTER
|
||||
-----------------------------------------------------------------------*/
|
||||
#define ADS1015_REG_POINTER_MASK (0x03) ///< Point mask
|
||||
#define ADS1015_REG_POINTER_CONVERT (0x00) ///< Conversion
|
||||
#define ADS1015_REG_POINTER_CONFIG (0x01) ///< Configuration
|
||||
#define ADS1015_REG_POINTER_LOWTHRESH (0x02) ///< Low threshold
|
||||
#define ADS1015_REG_POINTER_HITHRESH (0x03) ///< High threshold
|
||||
/*=========================================================================*/
|
||||
|
||||
/*=========================================================================
|
||||
CONFIG REGISTER
|
||||
-----------------------------------------------------------------------*/
|
||||
#define ADS1015_REG_CONFIG_OS_MASK (0x8000) ///< OS Mask
|
||||
#define ADS1015_REG_CONFIG_OS_SINGLE \
|
||||
(0x8000) ///< Write: Set to start a single-conversion
|
||||
#define ADS1015_REG_CONFIG_OS_BUSY \
|
||||
(0x0000) ///< Read: Bit = 0 when conversion is in progress
|
||||
#define ADS1015_REG_CONFIG_OS_NOTBUSY \
|
||||
(0x8000) ///< Read: Bit = 1 when device is not performing a conversion
|
||||
|
||||
#define ADS1015_REG_CONFIG_MUX_MASK (0x7000) ///< Mux Mask
|
||||
#define ADS1015_REG_CONFIG_MUX_DIFF_0_1 \
|
||||
(0x0000) ///< Differential P = AIN0, N = AIN1 (default)
|
||||
#define ADS1015_REG_CONFIG_MUX_DIFF_0_3 \
|
||||
(0x1000) ///< Differential P = AIN0, N = AIN3
|
||||
#define ADS1015_REG_CONFIG_MUX_DIFF_1_3 \
|
||||
(0x2000) ///< Differential P = AIN1, N = AIN3
|
||||
#define ADS1015_REG_CONFIG_MUX_DIFF_2_3 \
|
||||
(0x3000) ///< Differential P = AIN2, N = AIN3
|
||||
#define ADS1015_REG_CONFIG_MUX_SINGLE_0 (0x4000) ///< Single-ended AIN0
|
||||
#define ADS1015_REG_CONFIG_MUX_SINGLE_1 (0x5000) ///< Single-ended AIN1
|
||||
#define ADS1015_REG_CONFIG_MUX_SINGLE_2 (0x6000) ///< Single-ended AIN2
|
||||
#define ADS1015_REG_CONFIG_MUX_SINGLE_3 (0x7000) ///< Single-ended AIN3
|
||||
|
||||
#define ADS1015_REG_CONFIG_PGA_MASK (0x0E00) ///< PGA Mask
|
||||
#define ADS1015_REG_CONFIG_PGA_6_144V (0x0000) ///< +/-6.144V range = Gain 2/3
|
||||
#define ADS1015_REG_CONFIG_PGA_4_096V (0x0200) ///< +/-4.096V range = Gain 1
|
||||
#define ADS1015_REG_CONFIG_PGA_2_048V \
|
||||
(0x0400) ///< +/-2.048V range = Gain 2 (default)
|
||||
#define ADS1015_REG_CONFIG_PGA_1_024V (0x0600) ///< +/-1.024V range = Gain 4
|
||||
#define ADS1015_REG_CONFIG_PGA_0_512V (0x0800) ///< +/-0.512V range = Gain 8
|
||||
#define ADS1015_REG_CONFIG_PGA_0_256V (0x0A00) ///< +/-0.256V range = Gain 16
|
||||
|
||||
#define ADS1015_REG_CONFIG_MODE_MASK (0x0100) ///< Mode Mask
|
||||
#define ADS1015_REG_CONFIG_MODE_CONTIN (0x0000) ///< Continuous conversion mode
|
||||
#define ADS1015_REG_CONFIG_MODE_SINGLE \
|
||||
(0x0100) ///< Power-down single-shot mode (default)
|
||||
|
||||
#define ADS1015_REG_CONFIG_DR_MASK (0x00E0) ///< Data Rate Mask
|
||||
#define ADS1015_REG_CONFIG_DR_128SPS (0x0000) ///< 128 samples per second
|
||||
#define ADS1015_REG_CONFIG_DR_250SPS (0x0020) ///< 250 samples per second
|
||||
#define ADS1015_REG_CONFIG_DR_490SPS (0x0040) ///< 490 samples per second
|
||||
#define ADS1015_REG_CONFIG_DR_920SPS (0x0060) ///< 920 samples per second
|
||||
#define ADS1015_REG_CONFIG_DR_1600SPS \
|
||||
(0x0080) ///< 1600 samples per second (default)
|
||||
#define ADS1015_REG_CONFIG_DR_2400SPS (0x00A0) ///< 2400 samples per second
|
||||
#define ADS1015_REG_CONFIG_DR_3300SPS (0x00C0) ///< 3300 samples per second
|
||||
|
||||
#define ADS1015_REG_CONFIG_CMODE_MASK (0x0010) ///< CMode Mask
|
||||
#define ADS1015_REG_CONFIG_CMODE_TRAD \
|
||||
(0x0000) ///< Traditional comparator with hysteresis (default)
|
||||
#define ADS1015_REG_CONFIG_CMODE_WINDOW (0x0010) ///< Window comparator
|
||||
|
||||
#define ADS1015_REG_CONFIG_CPOL_MASK (0x0008) ///< CPol Mask
|
||||
#define ADS1015_REG_CONFIG_CPOL_ACTVLOW \
|
||||
(0x0000) ///< ALERT/RDY pin is low when active (default)
|
||||
#define ADS1015_REG_CONFIG_CPOL_ACTVHI \
|
||||
(0x0008) ///< ALERT/RDY pin is high when active
|
||||
|
||||
#define ADS1015_REG_CONFIG_CLAT_MASK \
|
||||
(0x0004) ///< Determines if ALERT/RDY pin latches once asserted
|
||||
#define ADS1015_REG_CONFIG_CLAT_NONLAT \
|
||||
(0x0000) ///< Non-latching comparator (default)
|
||||
#define ADS1015_REG_CONFIG_CLAT_LATCH (0x0004) ///< Latching comparator
|
||||
|
||||
#define ADS1015_REG_CONFIG_CQUE_MASK (0x0003) ///< CQue Mask
|
||||
#define ADS1015_REG_CONFIG_CQUE_1CONV \
|
||||
(0x0000) ///< Assert ALERT/RDY after one conversions
|
||||
#define ADS1015_REG_CONFIG_CQUE_2CONV \
|
||||
(0x0001) ///< Assert ALERT/RDY after two conversions
|
||||
#define ADS1015_REG_CONFIG_CQUE_4CONV \
|
||||
(0x0002) ///< Assert ALERT/RDY after four conversions
|
||||
#define ADS1015_REG_CONFIG_CQUE_NONE \
|
||||
(0x0003) ///< Disable the comparator and put ALERT/RDY in high state (default)
|
||||
/*=========================================================================*/
|
||||
|
||||
/** Gain settings */
|
||||
typedef enum {
|
||||
GAIN_TWOTHIRDS = ADS1015_REG_CONFIG_PGA_6_144V,
|
||||
GAIN_ONE = ADS1015_REG_CONFIG_PGA_4_096V,
|
||||
GAIN_TWO = ADS1015_REG_CONFIG_PGA_2_048V,
|
||||
GAIN_FOUR = ADS1015_REG_CONFIG_PGA_1_024V,
|
||||
GAIN_EIGHT = ADS1015_REG_CONFIG_PGA_0_512V,
|
||||
GAIN_SIXTEEN = ADS1015_REG_CONFIG_PGA_0_256V
|
||||
} adsGain_t;
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sensor driver for the Adafruit ADS1015 ADC breakout.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class Adafruit_ADS1015 {
|
||||
protected:
|
||||
// Instance-specific properties
|
||||
uint8_t m_i2cAddress; ///< the I2C address
|
||||
uint8_t m_conversionDelay; ///< conversion deay
|
||||
uint8_t m_bitShift; ///< bit shift amount
|
||||
adsGain_t m_gain; ///< ADC gain
|
||||
|
||||
public:
|
||||
Adafruit_ADS1015(uint8_t i2cAddress = ADS1015_ADDRESS);
|
||||
void begin(void);
|
||||
uint16_t readADC_SingleEnded(uint8_t channel);
|
||||
int16_t readADC_Differential_0_1(void);
|
||||
int16_t readADC_Differential_2_3(void);
|
||||
void startComparator_SingleEnded(uint8_t channel, int16_t threshold);
|
||||
int16_t getLastConversionResults();
|
||||
void setGain(adsGain_t gain);
|
||||
adsGain_t getGain(void);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sensor driver for the Adafruit ADS1115 ADC breakout.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class Adafruit_ADS1115 : public Adafruit_ADS1015 {
|
||||
public:
|
||||
Adafruit_ADS1115(uint8_t i2cAddress = ADS1015_ADDRESS);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
23
arduino-cli/libraries/Adafruit_ADS1X15/README.md
Normal file
23
arduino-cli/libraries/Adafruit_ADS1X15/README.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# Adafruit_ADS1015 [](http://adafruit.github.io/Adafruit_ADS1X15/html/index.html)
|
||||
|
||||
|
||||
Driver for TI's ADS1X15: 12 and 16-bit Differential or Single-Ended ADC with PGA and Comparator
|
||||
|
||||
## Info
|
||||
|
||||
This family of ADCs provide 4 single-ended or 2 differential channels.
|
||||
Each has a programmable gain amplifier from 2/3 up to 16x. Available
|
||||
in 12 or 16 bit versions:
|
||||
|
||||
* [ADS1015 12-bit ADC](https://www.adafruit.com/product/1083)
|
||||
* [ADS1115 16-bit ADC](https://www.adafruit.com/product/1085)
|
||||
|
||||
The chip's fairly small so it comes on a breakout board with ferrites to keep the AVDD and AGND quiet. Interfacing is done via I2C. The address can be changed to one of four options (see the datasheet table 5) so you can have up to 4 ADS1x15's connected on a single 2-wire I2C bus for 16 single ended inputs.
|
||||
|
||||
Adafruit invests time and resources providing this open source code, please
|
||||
support Adafruit and open-source hardware by purchasing products from
|
||||
[Adafruit](https://www.adafruit.com)!
|
||||
|
||||
## License
|
||||
|
||||
BSD license, all text above must be included in any redistribution.
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_ADS1015.h>
|
||||
|
||||
// Adafruit_ADS1115 ads; /* Use this for the 16-bit version */
|
||||
Adafruit_ADS1015 ads; /* Use thi for the 12-bit version */
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println("Hello!");
|
||||
|
||||
Serial.println("Single-ended readings from AIN0 with >3.0V comparator");
|
||||
Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
|
||||
Serial.println("Comparator Threshold: 1000 (3.000V)");
|
||||
|
||||
// The ADC input range (or gain) can be changed via the following
|
||||
// functions, but be careful never to exceed VDD +0.3V max, or to
|
||||
// exceed the upper and lower limits if you adjust the input range!
|
||||
// Setting these values incorrectly may destroy your ADC!
|
||||
// ADS1015 ADS1115
|
||||
// ------- -------
|
||||
// ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default)
|
||||
// ads.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV
|
||||
// ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV 0.0625mV
|
||||
// ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV 0.03125mV
|
||||
// ads.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.25mV 0.015625mV
|
||||
// ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV
|
||||
|
||||
ads.begin();
|
||||
|
||||
// Setup 3V comparator on channel 0
|
||||
ads.startComparator_SingleEnded(0, 1000);
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
int16_t adc0;
|
||||
|
||||
// Comparator will only de-assert after a read
|
||||
adc0 = ads.getLastConversionResults();
|
||||
Serial.print("AIN0: "); Serial.println(adc0);
|
||||
|
||||
delay(100);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_ADS1015.h>
|
||||
|
||||
// Adafruit_ADS1115 ads; /* Use this for the 16-bit version */
|
||||
Adafruit_ADS1015 ads; /* Use thi for the 12-bit version */
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println("Hello!");
|
||||
|
||||
Serial.println("Getting differential reading from AIN0 (P) and AIN1 (N)");
|
||||
Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
|
||||
|
||||
// The ADC input range (or gain) can be changed via the following
|
||||
// functions, but be careful never to exceed VDD +0.3V max, or to
|
||||
// exceed the upper and lower limits if you adjust the input range!
|
||||
// Setting these values incorrectly may destroy your ADC!
|
||||
// ADS1015 ADS1115
|
||||
// ------- -------
|
||||
// ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default)
|
||||
// ads.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV
|
||||
// ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV 0.0625mV
|
||||
// ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV 0.03125mV
|
||||
// ads.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.25mV 0.015625mV
|
||||
// ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV
|
||||
|
||||
ads.begin();
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
int16_t results;
|
||||
|
||||
/* Be sure to update this value based on the IC and the gain settings! */
|
||||
float multiplier = 3.0F; /* ADS1015 @ +/- 6.144V gain (12-bit results) */
|
||||
//float multiplier = 0.1875F; /* ADS1115 @ +/- 6.144V gain (16-bit results) */
|
||||
|
||||
results = ads.readADC_Differential_0_1();
|
||||
|
||||
Serial.print("Differential: "); Serial.print(results); Serial.print("("); Serial.print(results * multiplier); Serial.println("mV)");
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_ADS1015.h>
|
||||
|
||||
// Adafruit_ADS1115 ads; /* Use this for the 16-bit version */
|
||||
Adafruit_ADS1015 ads; /* Use thi for the 12-bit version */
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println("Hello!");
|
||||
|
||||
Serial.println("Getting single-ended readings from AIN0..3");
|
||||
Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
|
||||
|
||||
// The ADC input range (or gain) can be changed via the following
|
||||
// functions, but be careful never to exceed VDD +0.3V max, or to
|
||||
// exceed the upper and lower limits if you adjust the input range!
|
||||
// Setting these values incorrectly may destroy your ADC!
|
||||
// ADS1015 ADS1115
|
||||
// ------- -------
|
||||
// ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default)
|
||||
// ads.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV
|
||||
// ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV 0.0625mV
|
||||
// ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV 0.03125mV
|
||||
// ads.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.25mV 0.015625mV
|
||||
// ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV
|
||||
|
||||
ads.begin();
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
int16_t adc0, adc1, adc2, adc3;
|
||||
|
||||
adc0 = ads.readADC_SingleEnded(0);
|
||||
adc1 = ads.readADC_SingleEnded(1);
|
||||
adc2 = ads.readADC_SingleEnded(2);
|
||||
adc3 = ads.readADC_SingleEnded(3);
|
||||
Serial.print("AIN0: "); Serial.println(adc0);
|
||||
Serial.print("AIN1: "); Serial.println(adc1);
|
||||
Serial.print("AIN2: "); Serial.println(adc2);
|
||||
Serial.print("AIN3: "); Serial.println(adc3);
|
||||
Serial.println(" ");
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
13
arduino-cli/libraries/Adafruit_ADS1X15/keywords.txt
Normal file
13
arduino-cli/libraries/Adafruit_ADS1X15/keywords.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
Adafruit_ADS1015 KEYWORD1
|
||||
Adafruit_ADS1115 KEYWORD1
|
||||
begin KEYWORD2
|
||||
readADC_SingleEnded KEYWORD2
|
||||
readADC_Differential_0_1 KEYWORD2
|
||||
readADC_Differential_2_3 KEYWORD2
|
||||
startComparator_SingleEnded KEYWORD2
|
||||
getLastConversionResults KEYWORD2
|
||||
computeVolts KEYWORD2
|
||||
setGain KEYWORD2
|
||||
getGain KEYWORD2
|
||||
setDataRate KEYWORD2
|
||||
getDataRate KEYWORD2
|
||||
@@ -0,0 +1,9 @@
|
||||
name=Adafruit ADS1X15
|
||||
version=1.1.1
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Arduino library for ADS1015/1115 ADCs.
|
||||
paragraph=Arduino library for ADS1015/1115 12/16-bit Differential or Single-Ended ADCs with PGA and Comparator
|
||||
category=Signal Input/Output
|
||||
url=https://github.com/adafruit/Adafruit_ADS1X15
|
||||
architectures=*
|
||||
26
arduino-cli/libraries/Adafruit_ADS1X15/license.txt
Normal file
26
arduino-cli/libraries/Adafruit_ADS1X15/license.txt
Normal file
@@ -0,0 +1,26 @@
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2012, Adafruit Industries
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
Reference in New Issue
Block a user