Skip to content

Commit

Permalink
fix #36 Support NANO Every (#37)
Browse files Browse the repository at this point in the history
* fix #36 Support NANO Every
  • Loading branch information
RobTillaart authored Jan 21, 2022
1 parent 18ec9a1 commit a05e819
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .arduino-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ compile:
- m4
- esp32
# - esp8266
# - mega2560
# - mega2560
18 changes: 13 additions & 5 deletions ADS1X15.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FILE: ADS1X15.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.3.4
// VERSION: 0.3.5
// DATE: 2013-03-24
// PUPROSE: Arduino library for ADS1015 and ADS1115
// URL: https://github.com/RobTillaart/ADS1X15
Expand All @@ -24,6 +24,8 @@
// 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 Expand Up @@ -380,11 +382,17 @@ void ADS1X15::setWireClock(uint32_t clockSpeed)
}


//////////////////////////////////////////////////////
//
// EXPERIMENTAL
//
// see https://github.com/RobTillaart/ADS1X15/issues/22
// https://github.com/arduino/Arduino/issues/11457
// TODO: get the real clock speed from the I2C interface if possible.
// ESP ==> ??
uint32_t ADS1X15::getWireClock()
{
#if defined(__AVR__)
// UNO 328 and
#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
uint32_t speed = F_CPU / ((TWBR * 2) + 16);
return speed;

Expand All @@ -396,7 +404,7 @@ uint32_t ADS1X15::getWireClock()
// not supported.
// return -1;

#else // best effort ...
#else // best effort is remembering it
return _clockSpeed;
#endif
}
Expand Down Expand Up @@ -456,7 +464,7 @@ uint16_t ADS1X15::_readRegister(uint8_t address, uint8_t reg)
_wire->write(reg);
_wire->endTransmission();

int rv = _wire->requestFrom(address, (uint8_t) 2);
int rv = _wire->requestFrom((int) address, (int) 2);
if (rv == 2)
{
uint16_t value = _wire->read() << 8;
Expand Down
24 changes: 13 additions & 11 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.4
// VERSION: 0.3.5
// DATE: 2013-03-24
// PUPROSE: Arduino library for ADS1015 and ADS1115
// URL: https://github.com/RobTillaart/ADS1X15
Expand All @@ -12,23 +12,23 @@
#include "Arduino.h"
#include "Wire.h"

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

// allow compile time default address
// address in { 0x48, 0x49, 0x4A, 0x4B }, no test...
#ifndef ADS1015_ADDRESS
#define ADS1015_ADDRESS 0x48
#define ADS1015_ADDRESS 0x48
#endif

#ifndef ADS1115_ADDRESS
#define ADS1115_ADDRESS 0x48
#define ADS1115_ADDRESS 0x48
#endif


#define ADS1X15_OK 0
#define ADS1X15_INVALID_VOLTAGE -100
#define ADS1X15_INVALID_GAIN 0xFF
#define ADS1X15_INVALID_MODE 0xFE
#define ADS1X15_OK 0
#define ADS1X15_INVALID_VOLTAGE -100
#define ADS1X15_INVALID_GAIN 0xFF
#define ADS1X15_INVALID_MODE 0xFE


class ADS1X15
Expand Down Expand Up @@ -76,7 +76,7 @@ class ADS1X15


// ASYNC INTERFACE
// requestADC(pin) -> isBusy() or isReady() -> getValue();
// requestADC(pin) -> isBusy() or isReady() -> getValue();
// see examples
void requestADC(uint8_t pin);
void requestADC_Differential_0_1();
Expand Down Expand Up @@ -115,7 +115,9 @@ class ADS1X15

int8_t getError();

void setWireClock(uint32_t clockSpeed);
// EXPERIMENTAL
// see https://github.com/RobTillaart/ADS1X15/issues/22
void setWireClock(uint32_t clockSpeed = 100000);
// proto - getWireClock returns the value set by setWireClock not necessary the actual value
uint32_t getWireClock();

Expand Down Expand Up @@ -144,7 +146,7 @@ class ADS1X15
// COMPARATOR variables
// TODO merge these into one COMPARATOR MASK? (low priority)
// would speed up code in _requestADC() and save 3 bytes RAM.
// TODO boolean flags for first three, or make it mask value that
// TODO boolean flags for first three, or make it mask value that
// can be or-ed. (low priority)
uint8_t _compMode;
uint8_t _compPol;
Expand Down
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,18 @@ and optional the Wire interface as parameter.
- **ADS1115(address, TwoWire \*wire = &Wire)** Constructor with device address,
and optional the Wire interface as parameter.

The function **void setWireClock(uint32_t speed)** is used to set the clock speed
of the used I2C interface.

After construction the **ADS.begin()** need to be called. This will return false
if an invalid address is used.
The function **bool isConnected()** can be used to verify the reading of the ADS.
The function **void reset()** is sets the parameters to their initial value as
in the constructor.


#### I2C clock speed

The function **void setWireClock(uint32_t speed = 100000)** is used to set the clock speed
in Hz of the used I2C interface. typical value is 100 KHz.

The function **uint32_t getWireClock()** is a prototype.
It returns the value set by setWireClock().
Expand All @@ -66,11 +76,9 @@ When no value is set **getWireClock()** returns 0.
Need to implement a read / calculate from low level I2C code (e.g. TWBR on AVR),
better the Arduino Wire lib should support this call (ESP32 does).

After construction the **ADS.begin()** need to be called. This will return false
if an invalid address is used.
The function **bool isConnected()** can be used to verify the reading of the ADS.
The function **void reset()** is sets the parameters to their initial value as
in the constructor.
See - https://github.com/arduino/Arduino/issues/11457

Question: should this functionality be in this library?


#### Programmable Gain
Expand Down Expand Up @@ -321,6 +329,7 @@ mean something different see - Comparator Mode above or datasheet.
- SMB alert command (00011001) on I2C bus?
## Operation
See examples
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/ADS1X15"
},
"version": "0.3.4",
"version": "0.3.5",
"license": "MIT",
"frameworks": "*",
"platforms": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ADS1X15
version=0.3.4
version=0.3.5
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
Expand Down

0 comments on commit a05e819

Please sign in to comment.