Skip to content

Commit

Permalink
fix NANO RP2040 (mbed) support (#54)
Browse files Browse the repository at this point in the history
- fix NANO RP2040
- update and add examples
- minor edits
  • Loading branch information
RobTillaart authored Jun 13, 2023
1 parent 1d53197 commit 75fe0f1
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 38 deletions.
6 changes: 3 additions & 3 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.9
// VERSION: 0.3.10
// DATE: 2013-03-24
// PUPROSE: Arduino library for ADS1015 and ADS1115
// URL: https://github.com/RobTillaart/ADS1X15
Expand Down Expand Up @@ -140,6 +140,7 @@ void ADS1X15::reset()


#if defined (ESP8266) || defined(ESP32)

bool ADS1X15::begin(int sda, int scl)
{
_wire = &Wire;
Expand All @@ -148,9 +149,8 @@ bool ADS1X15::begin(int sda, int scl)
if (! isConnected()) return false;
return true;
}
#endif

#if defined (ARDUINO_ARCH_RP2040)
#elif defined (ARDUINO_ARCH_RP2040) && !defined(__MBED__)

bool ADS1X15::begin(int sda, int scl)
{
Expand Down
8 changes: 3 additions & 5 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.9
// VERSION: 0.3.10
// 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.9"))
#define ADS1X15_LIB_VERSION (F("0.3.10"))

// allow compile time default address
// address in { 0x48, 0x49, 0x4A, 0x4B }, no test...
Expand All @@ -38,9 +38,7 @@ class ADS1X15

#if defined (ESP8266) || defined(ESP32)
bool begin(int sda, int scl);
#endif

#if defined (ARDUINO_ARCH_RP2040)
#elif defined (ARDUINO_ARCH_RP2040) && !defined(__MBED__)
bool begin(int sda, int scl);
#endif

Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- update and add examples


## [0.3.10] - 2023-06-07
- fix NANO RP2040
- update and add examples
- minor edits


## [0.3.9] - 2023-01-21
- update GitHub actions
- update license 2023
- update readme.md
- minor edits


## [0.3.8] - 2022-10-17
- add RP2040 support (kudos to intubun)
- simplified changelog.md
Expand Down
49 changes: 35 additions & 14 deletions examples/ADS_continuous/ADS_continuous.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
// PURPOSE: read analog input
// URL: https://github.com/RobTillaart/ADS1X15

// test
// connect 1 potmeter
// test
// connect 1 potmeter
//
// GND ---[ x ]------ 5V
// |
// GND ---[ x ]------ 5V
// |
//
// measure at x (connect to AIN0).
//
// See https://github.com/RobTillaart/ADS1X15/issues/49
//
// measure at x (connect to AIN0).


#include "ADS1X15.h"

Expand All @@ -24,28 +26,47 @@
// ADS1114 ADS(0x48);
ADS1115 ADS(0x48);

uint16_t count = 0;
uint16_t value = 0;
uint16_t prev = 0;
uint32_t lastTime = 0;
uint32_t lastSample = 0;


void setup()
{
Serial.begin(115200);
Serial.begin(500000);
Serial.println(__FILE__);
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);

ADS.begin();
ADS.setGain(0); // 6.144 volt
ADS.setDataRate(7); // 0 = slow 4 = medium 7 = fast
ADS.setMode(0); // continuous mode
ADS.readADC(0); // first read to trigger
ADS.setGain(0); // 6.144 volt
ADS.setDataRate(7); // 0 = slow 4 = medium 7 = fast
ADS.setMode(0); // continuous mode
ADS.readADC(0); // first read to trigger
}


void loop()
{
Serial.println(ADS.getValue());
// optional other code here
uint32_t now = micros();
if (now - lastSample >= 1160) // almost exact 860 SPS
{
lastSample = now;
value = ADS.getValue();
count++;
Serial.print(count);
Serial.print("\t");
Serial.println(value);
}
if (now - 1000000 >= lastTime)
{
lastTime = now;
count = 0;
}
}


// -- END OF FILE --
// -- END OF FILE --

25 changes: 18 additions & 7 deletions examples/ADS_performance/ADS_performance.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
// PURPOSE: read analog input
// URL: https://github.com/RobTillaart/ADS1X15

// test
// connect 1 potmeter
// test
// connect 1 potmeter
//
// GND ---[ x ]------ 5V
// |
// GND ---[ x ]------ 5V
// |
//
// measure at x (connect to AIN0).
// measure at x (connect to AIN0).
//
// https://github.com/RobTillaart/ADS1X15/issues/53


#include "ADS1X15.h"
Expand All @@ -37,6 +39,9 @@ void setup()
Serial.println(ADS1X15_LIB_VERSION);

ADS.begin();

Wire.setClock(100000);

ADS.setGain(0); // 6.144 volt

for (int dr = 0; dr < 8; dr++)
Expand Down Expand Up @@ -75,7 +80,10 @@ void test_single_shot()
}
d1 = micros() - start;
Serial.print("\t");
Serial.println(d1);
Serial.print(d1); // TIME (us)
Serial.print("\t\t");
Serial.println(100000000.0 / d1); // SPS
delay(100);
}


Expand All @@ -92,7 +100,10 @@ void test_continuous()
}
d2 = micros() - start;
Serial.print("\t\t");
Serial.println(d2);
Serial.print(d2); // TIME (us)
Serial.print("\t\t");
Serial.println(100000000.0 / d2); // SPS
delay(100);
}


Expand Down
49 changes: 49 additions & 0 deletions examples/ADS_performance/performance_0.3.9.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Based upon output of **ADS_performance.ino**
UNO 16 MHz.
IDE 1.8.19


Synchronous calls I2C **100 KHz**

| DataRate | Time 100 calls | SPS |
|:----------:|:----------------:|:------:|
| 0 | 12861340 | 7.78 |
| 1 | 6481396 | 15.4 |
| 2 | 3347512 | 29.9 |
| 3 | 1724380 | 58.0 |
| 4 | 941032 | 106 |
| 5 | 549204 | 182 |
| 6 | 381340 | 262 |
| 7 | 269448 | 371 |


Synchronous calls I2C **400 KHz**

| DataRate | Time 100 calls | SPS |
|:----------:|:----------------:|:------:|
| 0 | 12872804 | 7.77 |
| 1 | 6402848 | 15.6 |
| 2 | 3234156 | 30.9 |
| 3 | 1649272 | 60.6 |
| 4 | 862188 | 116 |
| 5 | 468652 | 213 |
| 6 | 271552 | 368 |
| 7 | 173412 | 577 |


Synchronous calls I2C **600 KHz**

| DataRate | Time 100 calls | SPS |
|:----------:|:----------------:|:------:|
| 0 | 12736788 | 7.85 |
| 1 | 6390104 | 15.7 |
| 2 | 3223568 | 31.0 |
| 3 | 1645768 | 60.8 |
| 4 | 852300 | 117 |
| 5 | 448520 | 223 |
| 6 | 261216 | 383 |
| 7 | 167660 | 596 |

These are maxima of the SPS feasible, they do not include further processing.
At least this test shows the effect of the I2C bus speed.

12 changes: 6 additions & 6 deletions examples/ADS_read/ADS_read.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
// PURPOSE: read analog inputs - straightforward.
// URL: https://github.com/RobTillaart/ADS1X15

// test
// connect 1 potmeter per port.
// test
// connect 1 potmeter per port.
//
// GND ---[ x ]------ 5V
// |
//
// measure at x (connect to AIN0).
// GND ---[ x ]------ 5V
// |
//
// measure at x (connect to AIN0).



#include "ADS1X15.h"
Expand Down
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.9",
"version": "0.3.10",
"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.9
version=0.3.10
author=Rob Tillaart <[email protected]>
maintainer=Rob Tillaart <[email protected]>
sentence=Arduino library for ADS1015 - I2C 12 bit ADC and ADS1115 I2C 16 bit ADC
Expand Down

0 comments on commit 75fe0f1

Please sign in to comment.