mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.4.2 ADS1x15
This commit is contained in:
parent
fbd91dd0b0
commit
df2a0509a6
@ -6,7 +6,7 @@ jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: arduino/arduino-lint-action@v1
|
||||
with:
|
||||
library-manager: update
|
||||
|
@ -8,7 +8,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
|
@ -10,7 +10,7 @@ jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- name: json-syntax-check
|
||||
uses: limitusus/json-syntax-check@v1
|
||||
with:
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: ADS1X15.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.4.1
|
||||
// VERSION: 0.4.2
|
||||
// DATE: 2013-03-24
|
||||
// PURPOSE: Arduino library for ADS1015 and ADS1115
|
||||
// URL: https://github.com/RobTillaart/ADS1X15
|
||||
@ -193,7 +193,7 @@ float ADS1X15::toVoltage(int16_t value)
|
||||
if (value == 0) return 0;
|
||||
|
||||
float volts = getMaxVoltage();
|
||||
if (volts < 0) return volts;
|
||||
if (volts < 0) return volts; // propagate error
|
||||
|
||||
volts *= value;
|
||||
if (_config & ADS_CONF_RES_16)
|
||||
@ -530,6 +530,22 @@ ADS1013::ADS1013(uint8_t address, TwoWire *wire)
|
||||
_conversionDelay = ADS1015_CONVERSION_DELAY;
|
||||
_bitShift = 4;
|
||||
_maxPorts = 1;
|
||||
_gain = ADS1X15_PGA_2_048V; // fixed value
|
||||
}
|
||||
|
||||
|
||||
// ADS1x13 has no gain so set default.
|
||||
// Table 8. Config Register Field Descriptions
|
||||
void ADS1013::setGain(uint8_t gain)
|
||||
{
|
||||
_gain = gain; // keep compiler happy.
|
||||
_gain = ADS1X15_PGA_2_048V; // fixed value
|
||||
}
|
||||
|
||||
|
||||
uint8_t ADS1013::getGain()
|
||||
{
|
||||
return 2; // fixed value
|
||||
}
|
||||
|
||||
|
||||
@ -623,6 +639,22 @@ ADS1113::ADS1113(uint8_t address, TwoWire *wire)
|
||||
_conversionDelay = ADS1115_CONVERSION_DELAY;
|
||||
_bitShift = 0;
|
||||
_maxPorts = 1;
|
||||
_gain = ADS1X15_PGA_2_048V; // fixed value
|
||||
}
|
||||
|
||||
|
||||
// ADS1x13 has no gain so set default.
|
||||
// Table 8. Config Register Field Descriptions
|
||||
void ADS1113::setGain(uint8_t gain)
|
||||
{
|
||||
_gain = gain; // keep compiler happy.
|
||||
_gain = ADS1X15_PGA_2_048V; // fixed value
|
||||
}
|
||||
|
||||
|
||||
uint8_t ADS1113::getGain()
|
||||
{
|
||||
return 2; // fixed value
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: ADS1X15.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.4.1
|
||||
// VERSION: 0.4.2
|
||||
// DATE: 2013-03-24
|
||||
// PURPOSE: Arduino library for ADS1015 and ADS1115
|
||||
// URL: https://github.com/RobTillaart/ADS1X15
|
||||
@ -12,7 +12,7 @@
|
||||
#include "Arduino.h"
|
||||
#include "Wire.h"
|
||||
|
||||
#define ADS1X15_LIB_VERSION (F("0.4.1"))
|
||||
#define ADS1X15_LIB_VERSION (F("0.4.2"))
|
||||
|
||||
// allow compile time default address
|
||||
// address in { 0x48, 0x49, 0x4A, 0x4B }, no test...
|
||||
@ -72,8 +72,8 @@ public:
|
||||
int16_t readADC_Differential_0_1();
|
||||
|
||||
// used by continuous mode and async mode.
|
||||
[[deprecated("Use getValue() instead")]]
|
||||
int16_t getLastValue() { return getValue(); }; // will be obsolete in the future 0.4.0
|
||||
// [[deprecated("Use getValue() instead")]]
|
||||
// int16_t getLastValue() { return getValue(); }; // will be obsolete in the future 0.4.0
|
||||
int16_t getValue();
|
||||
|
||||
|
||||
@ -86,7 +86,7 @@ public:
|
||||
bool isReady();
|
||||
|
||||
|
||||
// returns a pin 0x0[0..3] or
|
||||
// returns a pin 0x0[0..3] or
|
||||
// a differential "mode" 0x[pin second][pin first] or
|
||||
// 0xFF (no request / invalid request)
|
||||
uint8_t lastRequest();
|
||||
@ -164,7 +164,7 @@ protected:
|
||||
uint8_t _compLatch;
|
||||
uint8_t _compQueConvert;
|
||||
|
||||
// variable to track the last pin requested,
|
||||
// variable to track the last pin requested,
|
||||
// to allow for round robin query of
|
||||
// pins based on this state == if no last request then == 0xFFFF.
|
||||
uint16_t _lastRequest;
|
||||
@ -188,6 +188,8 @@ class ADS1013 : public ADS1X15
|
||||
{
|
||||
public:
|
||||
ADS1013(uint8_t Address = ADS1015_ADDRESS, TwoWire *wire = &Wire);
|
||||
void setGain(uint8_t gain);
|
||||
uint8_t getGain();
|
||||
};
|
||||
|
||||
|
||||
@ -217,6 +219,8 @@ class ADS1113 : public ADS1X15
|
||||
{
|
||||
public:
|
||||
ADS1113(uint8_t address = ADS1115_ADDRESS, TwoWire *wire = &Wire);
|
||||
void setGain(uint8_t gain);
|
||||
uint8_t getGain();
|
||||
};
|
||||
|
||||
|
||||
|
@ -5,11 +5,18 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.4.2] - 2024-03-04
|
||||
- fix #68, gain bugs ADS1x13
|
||||
- add unit test for ADS1x13
|
||||
- update GitHub/actions to v4
|
||||
- removed depreciated **getLastValue()**
|
||||
- add multiplexer section to readme.md
|
||||
|
||||
|
||||
## [0.4.1] - 2024-01-02
|
||||
- fix some typos
|
||||
- minor edits
|
||||
|
||||
|
||||
## [0.4.0] - 2023-12-06
|
||||
- refactor API, begin()
|
||||
- update readme.md
|
||||
|
@ -65,6 +65,24 @@ is connected to:
|
||||
| SCL | 0x4B | |
|
||||
|
||||
|
||||
#### I2C multiplexing
|
||||
|
||||
Sometimes you need to control more devices than possible with the default
|
||||
address range the device provides.
|
||||
This is possible with an I2C multiplexer e.g. TCA9548 which creates up
|
||||
to eight channels (think of it as I2C subnets) which can use the complete
|
||||
address range of the device.
|
||||
|
||||
Drawback of using a multiplexer is that it takes more administration in
|
||||
your code e.g. which device is on which channel.
|
||||
This will slow down the access, which must be taken into account when
|
||||
deciding which devices are on which channel.
|
||||
Also note that switching between channels will slow down other devices
|
||||
too if they are behind the multiplexer.
|
||||
|
||||
- https://github.com/RobTillaart/TCA9548
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
```cpp
|
||||
|
@ -0,0 +1,49 @@
|
||||
//
|
||||
// FILE: ADS1113_getMaxVoltage.ino
|
||||
// AUTHOR: Rob.Tillaart
|
||||
// PURPOSE: read analog inputs - straightforward.
|
||||
// URL: https://github.com/RobTillaart/ADS1X15
|
||||
|
||||
// test for issue #68 behaviour ADS1113 / ADS1013
|
||||
//
|
||||
// connect 1 potmeter per port.
|
||||
//
|
||||
// GND ---[ x ]------ 5V
|
||||
// |
|
||||
//
|
||||
// measure at x (connect to AIN0).
|
||||
|
||||
|
||||
#include "ADS1X15.h"
|
||||
|
||||
ADS1113 ADS(0x48);
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("ADS1X15_LIB_VERSION: ");
|
||||
Serial.println(ADS1X15_LIB_VERSION);
|
||||
|
||||
Wire.begin();
|
||||
ADS.begin();
|
||||
|
||||
for (int g = 0; g < 8; g++)
|
||||
{
|
||||
ADS.setGain(g);
|
||||
Serial.print(g);
|
||||
Serial.print('\t');
|
||||
Serial.print(ADS.getGain()); // should all print 2
|
||||
Serial.print('\t');
|
||||
Serial.println(ADS.getMaxVoltage(), 3); // should all print 2.048
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -1,7 +1,8 @@
|
||||
# Syntax Colouring Map For ADS1X15
|
||||
|
||||
# Data types (KEYWORD1)
|
||||
ADS1X13 KEYWORD1
|
||||
ADS1X15 KEYWORD1
|
||||
ADS1013 KEYWORD1
|
||||
ADS1014 KEYWORD1
|
||||
ADS1015 KEYWORD1
|
||||
ADS1015 KEYWORD1
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/ADS1X15"
|
||||
},
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.2",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=ADS1X15
|
||||
version=0.4.1
|
||||
version=0.4.2
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for ADS1015 - I2C 12 bit ADC and ADS1115 I2C 16 bit ADC
|
||||
|
@ -79,6 +79,30 @@ unittest(test_gain)
|
||||
}
|
||||
|
||||
|
||||
// For issue #68, #2
|
||||
unittest(test_gain_ADS1113)
|
||||
{
|
||||
ADS1113 ADS(0x48);
|
||||
|
||||
Wire.begin();
|
||||
|
||||
assertTrue(ADS.begin());
|
||||
|
||||
assertEqual(2, ADS.getGain());
|
||||
int gains[6] = { 0,1,2,4,8,16 };
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
ADS.setGain(gains[i]);
|
||||
assertEqual(2, ADS.getGain());
|
||||
assertEqualFloat(2.048, ADS.getMaxVoltage(), 0.001);
|
||||
}
|
||||
|
||||
ADS.setGain(42);
|
||||
assertEqual(2, ADS.getGain());
|
||||
assertEqualFloat(2.048, ADS.getMaxVoltage(), 0.001);
|
||||
}
|
||||
|
||||
|
||||
unittest(test_Voltage)
|
||||
{
|
||||
ADS1115 ADS(0x48);
|
||||
@ -93,6 +117,26 @@ unittest(test_Voltage)
|
||||
float delta = abs(6.144 - volts);
|
||||
assertMoreOrEqual(0.001, delta);
|
||||
|
||||
ADS.setGain(1);
|
||||
volts = ADS.getMaxVoltage();
|
||||
delta = abs(4.096 - volts);
|
||||
assertMoreOrEqual(0.001, delta);
|
||||
|
||||
ADS.setGain(2);
|
||||
volts = ADS.getMaxVoltage();
|
||||
delta = abs(2.048 - volts);
|
||||
assertMoreOrEqual(0.001, delta);
|
||||
|
||||
ADS.setGain(4);
|
||||
volts = ADS.getMaxVoltage();
|
||||
delta = abs(1.024 - volts);
|
||||
assertMoreOrEqual(0.001, delta);
|
||||
|
||||
ADS.setGain(8);
|
||||
volts = ADS.getMaxVoltage();
|
||||
delta = abs(0.512 - volts);
|
||||
assertMoreOrEqual(0.001, delta);
|
||||
|
||||
ADS.setGain(16);
|
||||
volts = ADS.getMaxVoltage();
|
||||
delta = abs(0.256 - volts);
|
||||
|
Loading…
Reference in New Issue
Block a user