From 75fe0f1b7bd1fa0704afb38043b0e0d1ae58c488 Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Tue, 13 Jun 2023 13:11:17 +0200 Subject: [PATCH] fix NANO RP2040 (mbed) support (#54) - fix NANO RP2040 - update and add examples - minor edits --- ADS1X15.cpp | 6 +-- ADS1X15.h | 8 ++- CHANGELOG.md | 7 ++- examples/ADS_continuous/ADS_continuous.ino | 49 +++++++++++++------ examples/ADS_performance/ADS_performance.ino | 25 +++++++--- examples/ADS_performance/performance_0.3.9.md | 49 +++++++++++++++++++ examples/ADS_read/ADS_read.ino | 12 ++--- library.json | 2 +- library.properties | 2 +- 9 files changed, 122 insertions(+), 38 deletions(-) create mode 100644 examples/ADS_performance/performance_0.3.9.md diff --git a/ADS1X15.cpp b/ADS1X15.cpp index 3ead897..947422e 100644 --- a/ADS1X15.cpp +++ b/ADS1X15.cpp @@ -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 @@ -140,6 +140,7 @@ void ADS1X15::reset() #if defined (ESP8266) || defined(ESP32) + bool ADS1X15::begin(int sda, int scl) { _wire = &Wire; @@ -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) { diff --git a/ADS1X15.h b/ADS1X15.h index 3343770..30d8e41 100644 --- a/ADS1X15.h +++ b/ADS1X15.h @@ -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 @@ -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... @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 2541df9..a31c9b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/examples/ADS_continuous/ADS_continuous.ino b/examples/ADS_continuous/ADS_continuous.ino index ca96786..78a4b43 100644 --- a/examples/ADS_continuous/ADS_continuous.ino +++ b/examples/ADS_continuous/ADS_continuous.ino @@ -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" @@ -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 -- diff --git a/examples/ADS_performance/ADS_performance.ino b/examples/ADS_performance/ADS_performance.ino index e423672..b2d1a4c 100644 --- a/examples/ADS_performance/ADS_performance.ino +++ b/examples/ADS_performance/ADS_performance.ino @@ -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" @@ -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++) @@ -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); } @@ -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); } diff --git a/examples/ADS_performance/performance_0.3.9.md b/examples/ADS_performance/performance_0.3.9.md new file mode 100644 index 0000000..f1d6960 --- /dev/null +++ b/examples/ADS_performance/performance_0.3.9.md @@ -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. + diff --git a/examples/ADS_read/ADS_read.ino b/examples/ADS_read/ADS_read.ino index 2492cf0..249c68b 100644 --- a/examples/ADS_read/ADS_read.ino +++ b/examples/ADS_read/ADS_read.ino @@ -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" diff --git a/library.json b/library.json index a008e9a..529188c 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/ADS1X15" }, - "version": "0.3.9", + "version": "0.3.10", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/library.properties b/library.properties index 97749a8..8fe8615 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ADS1X15 -version=0.3.9 +version=0.3.10 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for ADS1015 - I2C 12 bit ADC and ADS1115 I2C 16 bit ADC