Skip to content

Commit

Permalink
add default parameter readADC() requestADC, created changelog.MD, upd… (
Browse files Browse the repository at this point in the history
#41)

* add default parameter readADC() requestADC(),
* created changelog.MD,
* update readme.md
* add examples for the ADS1114
  • Loading branch information
RobTillaart authored Mar 15, 2022
1 parent dcb7bd8 commit ad88d90
Show file tree
Hide file tree
Showing 9 changed files with 384 additions and 32 deletions.
23 changes: 1 addition & 22 deletions ADS1X15.cpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
//
// FILE: ADS1X15.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.3.5
// VERSION: 0.3.6
// DATE: 2013-03-24
// PUPROSE: Arduino library for ADS1015 and ADS1115
// URL: https://github.com/RobTillaart/ADS1X15
//
// HISTORY:
// 0.0.0 2013-03-24 initial version
// 0.0.1 2013-03-24 first working version
// 0.1.0 2017-07-31 removed pre 1.0 support; added getVoltage
// 0.2.0 2020-04-08 initial release; refactor ad fundum;
// 0.2.1 2020-08-15 fix issue 2 gain; refactor
// 0.2.2 2020-08-18 add begin(sda, scl) for ESP32
// 0.2.3 2020-08-20 add comparator code + async mode
// 0.2.4 2020-08-26 check readme.md and minor fixes
// 0.2.5 2020-08-26 add missing readADC_Differential_X_X()
// 0.2.6 2020-09-01 fix #12 - fix getMaxVoltage + minor refactor
// 0.2.7 2020-09-27 redo readRegister() + getValue() + getError()
// 0.3.0 2021-03-29 add Wire parameter to constructors.
// 0.3.1 2021-04-25 #22, add get/setClock() for Wire speed + reset()
// 0.3.2 2021-10-07 fix build-CI; update readme + add new examples
// 0.3.3 2021-10-17 update build-CI (esp32), readme.md, keywords.txt
// 0.3.4 2021-12-11 update library.json, license, minor edits incl layout)
// add unit test constants.
// 0.3.5 2022-01-21 fix #36 support for Nano Every



#include "ADS1X15.h"
Expand Down
16 changes: 12 additions & 4 deletions ADS1X15.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// FILE: ADS1X15.H
// AUTHOR: Rob Tillaart
// VERSION: 0.3.5
// VERSION: 0.3.6
// DATE: 2013-03-24
// PUPROSE: Arduino library for ADS1015 and ADS1115
// URL: https://github.com/RobTillaart/ADS1X15
Expand All @@ -12,7 +12,7 @@
#include "Arduino.h"
#include "Wire.h"

#define ADS1X15_LIB_VERSION (F("0.3.5"))
#define ADS1X15_LIB_VERSION (F("0.3.6"))

// allow compile time default address
// address in { 0x48, 0x49, 0x4A, 0x4B }, no test...
Expand Down Expand Up @@ -67,7 +67,7 @@ class ADS1X15
void setDataRate(uint8_t dataRate = 4); // invalid values are mapped on 4 (default)
uint8_t getDataRate(); // actual speed depends on device

int16_t readADC(uint8_t pin);
int16_t readADC(uint8_t pin = 0);
int16_t readADC_Differential_0_1();

// used by continuous mode and async mode.
Expand All @@ -78,7 +78,7 @@ class ADS1X15
// ASYNC INTERFACE
// requestADC(pin) -> isBusy() or isReady() -> getValue();
// see examples
void requestADC(uint8_t pin);
void requestADC(uint8_t pin = 0);
void requestADC_Differential_0_1();
bool isBusy();
bool isReady();
Expand Down Expand Up @@ -163,6 +163,7 @@ class ADS1X15
uint32_t _clockSpeed = 0;
};


///////////////////////////////////////////////////////////////////////////
//
// Derived classes from ADS1X15
Expand All @@ -173,12 +174,14 @@ class ADS1013 : public ADS1X15
ADS1013(uint8_t Address = ADS1015_ADDRESS, TwoWire *wire = &Wire);
};


class ADS1014 : public ADS1X15
{
public:
ADS1014(uint8_t Address = ADS1015_ADDRESS, TwoWire *wire = &Wire);
};


class ADS1015 : public ADS1X15
{
public:
Expand All @@ -193,6 +196,7 @@ class ADS1015 : public ADS1X15
void requestADC_Differential_2_3();
};


///////////////////////////////////////////////////////////////////////////
//
// Derived classes from ADS1X15
Expand All @@ -203,12 +207,14 @@ class ADS1113 : public ADS1X15
ADS1113(uint8_t address = ADS1115_ADDRESS, TwoWire *wire = &Wire);
};


class ADS1114 : public ADS1X15
{
public:
ADS1114(uint8_t address = ADS1115_ADDRESS, TwoWire *wire = &Wire);
};


class ADS1115 : public ADS1X15
{
public:
Expand All @@ -223,4 +229,6 @@ class ADS1115 : public ADS1X15
void requestADC_Differential_2_3();
};


// --- END OF FILE ---

124 changes: 124 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Change Log
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.3.6] - 2022-03-10

### Added
- CHANGELOG.md: moved history in ADS1x15.cpp to this file.
- add default parameters for single channel devices.
- **readADC(uint8_t pin = 0);**
- **requestADC(uint8_t pin = 0);**
- two examples for the **ADS1114** (single channel devices)
- update readme.md.

### Changed

### Fixed

## [0.3.5] - 2022-01-21

### Added

### Changed

### Fixed
- fix #36 support for Nano Every

## [0.3.4] - 2021-12-11

### Added
- add unit test constants.

### Changed
- update library.json, license,
- minor edits incl layout

### Fixed

## [0.3.3] - 2021-10-17

### Added

### Changed
- update build-CI (esp32), readme.md, keywords.txt

### Fixed

## [0.3.2] - 2021-10-07

### Added
- added examples

### Changed
- update readme

### Fixed
- fix build-CI;

## [0.3.1] - 2021-04-25

### Added
- add get/setClock() for Wire speed
- reset()

### Changed

### Fixed
- issue #22

## [0.3.0] - 2021-03-29

### Added
- add Wire parameter to constructors.

### Changed

### Fixed


## OLDER versions

### 0.2.7 - 2020-09-27
- redo readRegister()
- getValue()
- getError()

### [0.2.6] - 2020-09-01
- fix #12
- fix getMaxVoltage
- refactor

### [0.2.5] - 2020-08-26
- add missing readADC_Differential_X_X()

### [0.2.4] - 2020-08-26
- check readme.md and minor fixes

### [0.2.3] - 2020-08-20
- add comparator code
- add async mode

### [0.2.2] - 2020-08-18
- add begin(sda, scl) for ESP32

### [0.2.1] - 2020-08-15
- fix issue #2 gain

### [0.2.0] - 2020-04-08
- initial release;
- refactor ad fundum;

### [0.1.0] - 2017-07-31
- removed pre 1.0 support; added getVoltage

### [0.0.1] - 2013-03-24
- first working version

### [0.0.0] - 2013-03-24
- initial version



14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/ADS1X15/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/ADS1X15.svg?maxAge=3600)](https://github.com/RobTillaart/ADS1X15/releases)


# ADS1X15

Arduino library for I2C ADC ADS1015, ADS1115, and similar.

For using I2C ADC with Raspberry pi or other SBC with Linux OS, you can check similar library [here](https://github.com/chandrawi/ADS1x15-ADC).


## Description

This library should work for the devices mentioned below,
Expand Down Expand Up @@ -172,18 +174,24 @@ Data rate in samples per second, based on datasheet is described on table below.

Reading the ADC is very straightforward, the **readADC()** function handles all in one call.
Under the hood it uses the asynchronous calls.
- **int16_t readADC(uint8_t pin)** normal ADC functionality, pin = 0..3.
- **int16_t readADC(uint8_t pin = 0)** normal ADC functionality, pin = 0..3.
If the pin number is out of range, this function will return 0.
Default pin = 0 as this is convenient for 1 channel devices.

```cpp
// read ADC in pin 0
// read ADC in pin 2
ADS.readADC(2);

// read ADC in pin 0 - two ways
ADS.readADC();
ADS.readADC(0);
```

See [examples](https://github.com/RobTillaart/ADS1X15/blob/master/examples/ADS_minimum/ADS_minimum.ino).

To read the ADC in an asynchronous way (e.g. to minimize blocking) you need call three functions:
- **void requestADC(uint8_t pin)** Start the conversion. pin = 0..3.
- **void requestADC(uint8_t pin = 0)** Start the conversion. pin = 0..3.
Default pin = 0 as this is convenient for 1 channel devices.
- **bool isBusy()** Is the conversion not ready yet? Works only in SINGLE mode!
- **bool isReady()** Is the conversion ready? Works only in SINGLE mode! (= wrapper around **isBusy()** )
- **int16_t getValue()** Read the result of the conversion.
Expand Down
Loading

0 comments on commit ad88d90

Please sign in to comment.