From c5860b1584369bc981cc91d8940d8cafaec3c568 Mon Sep 17 00:00:00 2001 From: rob tillaart Date: Sat, 13 Aug 2022 19:31:52 +0200 Subject: [PATCH] 0.3.4 AD524X --- libraries/AD524X/AD524X.cpp | 11 +++-- libraries/AD524X/AD524X.h | 9 ++-- libraries/AD524X/README.md | 8 +++- .../AD524X_followA0/AD524X_followA0.ino | 12 +++-- .../AD524X_isConnected/AD524X_isConnected.ino | 12 +++-- .../AD524X_midScaleReset.ino | 19 ++++++-- .../examples/AD524X_read/AD524X_read.ino | 15 ++++-- .../AD524X_readBackRegister.ino | 48 +++++++++++-------- .../AD524X_sawtooth/AD524X_sawtooth.ino | 15 ++++-- .../examples/AD524X_setO/AD524X_setO.ino | 19 ++++++-- .../examples/AD524X_write/AD524X_write.ino | 15 ++++-- .../AD524X_write_AD5241.ino | 25 ++++++---- .../AD524X_write_AD5242.ino | 26 ++++++---- libraries/AD524X/keywords.txt | 2 +- libraries/AD524X/library.json | 2 +- libraries/AD524X/library.properties | 2 +- libraries/AD524X/test/unit_test_001.cpp | 1 + 17 files changed, 167 insertions(+), 74 deletions(-) diff --git a/libraries/AD524X/AD524X.cpp b/libraries/AD524X/AD524X.cpp index eb9c17bc..4345c120 100644 --- a/libraries/AD524X/AD524X.cpp +++ b/libraries/AD524X/AD524X.cpp @@ -1,7 +1,7 @@ // // FILE: AD524X.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.3.3 +// VERSION: 0.3.4 // PURPOSE: I2C digital potentiometer AD5241 AD5242 // DATE: 2013-10-12 // URL: https://github.com/RobTillaart/AD524X @@ -9,7 +9,8 @@ // HISTORY // 2021-10-16 0.3.2 fix build-CI, update readme.md // 2021-12-10 0.3.3 update constants, library.json, license - +// 2022-08-13 0.3.4 fix AD524X_LIB_VERSION +// minor edits, #include "AD524X.h" @@ -161,7 +162,7 @@ uint8_t AD524X::midScaleReset(const uint8_t rdac) } -// read datasheet P.15 +// read datasheet P.15 uint8_t AD524X::shutDown() { uint8_t cmd = AD524X_SHUTDOWN; // TODO TEST & VERIFY @@ -185,7 +186,7 @@ uint8_t AD524X::send(const uint8_t cmd, const uint8_t value) ////////////////////////////////////////////////////////////// // // DERIVED CLASSES -// +// AD5241::AD5241(const uint8_t address, TwoWire *wire) : AD524X(address, wire) { _pmCount = 1; @@ -197,4 +198,6 @@ AD5242::AD5242(const uint8_t address, TwoWire *wire) : AD524X(address, wire) _pmCount = 2; }; + // -- END OF FILE -- + diff --git a/libraries/AD524X/AD524X.h b/libraries/AD524X/AD524X.h index 6aaa56ae..ff6a52d6 100644 --- a/libraries/AD524X/AD524X.h +++ b/libraries/AD524X/AD524X.h @@ -2,7 +2,7 @@ // // FILE: AD524X.h // AUTHOR: Rob Tillaart -// VERSION: 0.3.3 +// VERSION: 0.3.4 // PURPOSE: I2C digital PotentioMeter AD5241 AD5242 // DATE: 2013-10-12 // URL: https://github.com/RobTillaart/AD524X @@ -12,7 +12,7 @@ #include "Wire.h" -#define AD524X_VERSION (F("0.3.3")) +#define AD524X_LIB_VERSION (F("0.3.4")) #define AD524X_OK 0 @@ -29,7 +29,7 @@ public: #endif bool begin(); bool isConnected(); - + uint8_t reset(); // reset both channels to 127 and O1/O2 to LOW uint8_t zeroAll(); // set both channels to 0 and O1/O2 to LOW @@ -69,7 +69,7 @@ private: ////////////////////////////////////////////////////////////// // // DERIVED CLASSES -// +// class AD5241 : public AD524X { public: @@ -85,3 +85,4 @@ public: // -- END OF FILE -- + diff --git a/libraries/AD524X/README.md b/libraries/AD524X/README.md index 1570ca55..e0032d52 100644 --- a/libraries/AD524X/README.md +++ b/libraries/AD524X/README.md @@ -24,6 +24,12 @@ An important property of the devices is that they defaults to their mid position at startup. +#### Related libraries + +This library is related to - https://github.com/RobTillaart/AD5245 +The AD5245 is a single port digital potentiometer. + + ## I2C address The AD524X has two address lines to configure the I2C address. 0x2C - 0x2F @@ -91,5 +97,5 @@ The examples show the basic working of the functions. ## Future - improve error handling. -- sync with AD520X library? +- sync with AD520X library diff --git a/libraries/AD524X/examples/AD524X_followA0/AD524X_followA0.ino b/libraries/AD524X/examples/AD524X_followA0/AD524X_followA0.ino index ed1b8277..f5efaf77 100644 --- a/libraries/AD524X/examples/AD524X_followA0/AD524X_followA0.ino +++ b/libraries/AD524X/examples/AD524X_followA0/AD524X_followA0.ino @@ -1,12 +1,11 @@ // // FILE: AD524X_followA0.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.2 // PURPOSE: AD524X demo program -// DATE: 2013-10-12 // URL: https://github.com/RobTillaart/AD524X // + #include "AD524X.h" AD524X AD01(0x2C); // AD0 & AD1 == GND @@ -15,11 +14,17 @@ AD524X AD01(0x2C); // AD0 & AD1 == GND void setup() { Serial.begin(115200); + Serial.println(); Serial.println(__FILE__); - Serial.println(AD524X_VERSION); + Serial.println(); + Serial.println(AD524X_LIB_VERSION); Wire.begin(); Wire.setClock(400000); + + bool b = AD01.begin(); + Serial.println(b ? "true" : "false"); + Serial.println(AD01.isConnected()); } @@ -43,3 +48,4 @@ void loop() // -- END OF FILE -- + diff --git a/libraries/AD524X/examples/AD524X_isConnected/AD524X_isConnected.ino b/libraries/AD524X/examples/AD524X_isConnected/AD524X_isConnected.ino index fb3b5485..a2e44c0e 100644 --- a/libraries/AD524X/examples/AD524X_isConnected/AD524X_isConnected.ino +++ b/libraries/AD524X/examples/AD524X_isConnected/AD524X_isConnected.ino @@ -1,9 +1,7 @@ // // FILE: AD524X_isConnected.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.0 // PURPOSE: AD524X demo program -// DATE: 2021-01-27 // URL: https://github.com/RobTillaart/AD524X // @@ -16,14 +14,16 @@ AD524X AD01(0x2C); // AD0 & AD1 == GND void setup() { Serial.begin(115200); + Serial.println(); Serial.println(__FILE__); - Serial.println(AD524X_VERSION); + Serial.println(); + Serial.println(AD524X_LIB_VERSION); Wire.begin(); Wire.setClock(400000); - + bool b = AD01.begin(); - Serial.println(b?"true":"false"); + Serial.println(b ? "true" : "false"); Serial.println(AD01.isConnected()); Serial.println("\nDone..."); @@ -34,4 +34,6 @@ void loop() { } + // -- END OF FILE -- + diff --git a/libraries/AD524X/examples/AD524X_midScaleReset/AD524X_midScaleReset.ino b/libraries/AD524X/examples/AD524X_midScaleReset/AD524X_midScaleReset.ino index 2fcdcfdd..923a33a7 100644 --- a/libraries/AD524X/examples/AD524X_midScaleReset/AD524X_midScaleReset.ino +++ b/libraries/AD524X/examples/AD524X_midScaleReset/AD524X_midScaleReset.ino @@ -1,33 +1,40 @@ // // FILE: AD524X_midScaleReset.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.2 // PURPOSE: AD524X demo program -// DATE: 2013-10-12 // URL: https://github.com/RobTillaart/AD524X // + #include "AD524X.h" AD524X AD01(0x2C); // AD0 & AD1 == GND + void setup() { Serial.begin(115200); + Serial.println(); Serial.println(__FILE__); - Serial.println(AD524X_VERSION); + Serial.println(); + Serial.println(AD524X_LIB_VERSION); Wire.begin(); Wire.setClock(400000); + + bool b = AD01.begin(); + Serial.println(b ? "true" : "false"); + Serial.println(AD01.isConnected()); } + void loop() { Serial.println(255); AD01.write(1, 255); delay(1000); - Serial.println("reset"); + Serial.println("midScaleReset(1)"); AD01.midScaleReset(1); delay(1000); @@ -35,9 +42,11 @@ void loop() AD01.write(1, 0); delay(1000); - Serial.println("reset"); + Serial.println("midScaleReset(1)"); AD01.midScaleReset(1); delay(1000); } + // -- END OF FILE -- + diff --git a/libraries/AD524X/examples/AD524X_read/AD524X_read.ino b/libraries/AD524X/examples/AD524X_read/AD524X_read.ino index 02e9a86b..3b0f409b 100644 --- a/libraries/AD524X/examples/AD524X_read/AD524X_read.ino +++ b/libraries/AD524X/examples/AD524X_read/AD524X_read.ino @@ -1,26 +1,33 @@ // // FILE: AD524X_read.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.2 // PURPOSE: AD524X demo program -// DATE: 2013-10-12 // URL: https://github.com/RobTillaart/AD524X // + #include "AD524X.h" AD524X AD01(0x2C); // AD0 & AD1 == GND + void setup() { Serial.begin(115200); + Serial.println(); Serial.println(__FILE__); - Serial.println(AD524X_VERSION); + Serial.println(); + Serial.println(AD524X_LIB_VERSION); Wire.begin(); Wire.setClock(400000); + + bool b = AD01.begin(); + Serial.println(b ? "true" : "false"); + Serial.println(AD01.isConnected()); } + void loop() { for (int val = 0; val < 255; val++) @@ -28,6 +35,7 @@ void loop() Serial.print(val); AD01.write(1, val); delay(100); + int x = AD01.read(1); Serial.print('\t'); Serial.println(x); @@ -36,4 +44,5 @@ void loop() delay(1000); } + // -- END OF FILE -- diff --git a/libraries/AD524X/examples/AD524X_readBackRegister/AD524X_readBackRegister.ino b/libraries/AD524X/examples/AD524X_readBackRegister/AD524X_readBackRegister.ino index 018bb163..073e38af 100644 --- a/libraries/AD524X/examples/AD524X_readBackRegister/AD524X_readBackRegister.ino +++ b/libraries/AD524X/examples/AD524X_readBackRegister/AD524X_readBackRegister.ino @@ -1,50 +1,60 @@ // // FILE: AD524X_readBackRegister.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.1 // PURPOSE: AD524X demo program -// DATE: 2016-04-10 // URL: https://github.com/RobTillaart/AD524X // + #include "AD524X.h" AD524X AD01(0x2C); // AD0 & AD1 == GND + void setup() { Serial.begin(115200); + Serial.println(); Serial.println(__FILE__); - Serial.println(AD524X_VERSION); + Serial.println(); + Serial.println(AD524X_LIB_VERSION); Wire.begin(); Wire.setClock(400000); + + bool b = AD01.begin(); + Serial.println(b ? "true" : "false"); + Serial.println(AD01.isConnected()); } + void loop() { - for (int rdac = 0; rdac < 2; rdac++) + for (int rdac = 0; rdac < 2; rdac++) + { + for (int val = 0; val < 255; val++) { - for (int val = 0; val < 255; val++) - { - test(rdac, val); - } + test(rdac, val); } - delay(1000); + } + delay(1000); } void test(uint8_t rdac, uint8_t val) { - Serial.print(val); - AD01.write(rdac, val); - delay(100); - int x = AD01.read(rdac); - int y = AD01.readBackRegister(); - Serial.print('\t'); - Serial.print(x); - Serial.print('\t'); - Serial.println(y); - delay(100); + Serial.print(val); + AD01.write(rdac, val); + delay(100); + + int x = AD01.read(rdac); + int y = AD01.readBackRegister(); + Serial.print('\t'); + Serial.print(x); + Serial.print('\t'); + Serial.println(y); + delay(100); } + // -- END OF FILE -- + diff --git a/libraries/AD524X/examples/AD524X_sawtooth/AD524X_sawtooth.ino b/libraries/AD524X/examples/AD524X_sawtooth/AD524X_sawtooth.ino index b4a8e91a..72eaf1c6 100644 --- a/libraries/AD524X/examples/AD524X_sawtooth/AD524X_sawtooth.ino +++ b/libraries/AD524X/examples/AD524X_sawtooth/AD524X_sawtooth.ino @@ -1,26 +1,33 @@ // // FILE: AD524X_sawtooth.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.2 // PURPOSE: AD524X demo program -// DATE: 2013-10-12 // URL: https://github.com/RobTillaart/AD524X // + #include "AD524X.h" AD524X AD01(0x2C); // AD0 & AD1 == GND + void setup() { Serial.begin(115200); + Serial.println(); Serial.println(__FILE__); - Serial.println(AD524X_VERSION); + Serial.println(); + Serial.println(AD524X_LIB_VERSION); Wire.begin(); Wire.setClock(400000); + + bool b = AD01.begin(); + Serial.println(b ? "true" : "false"); + Serial.println(AD01.isConnected()); } + void loop() { for (int val = 0; val < 255; val++) @@ -31,4 +38,6 @@ void loop() } } + // -- END OF FILE -- + diff --git a/libraries/AD524X/examples/AD524X_setO/AD524X_setO.ino b/libraries/AD524X/examples/AD524X_setO/AD524X_setO.ino index 1c430128..8dfb61ec 100644 --- a/libraries/AD524X/examples/AD524X_setO/AD524X_setO.ino +++ b/libraries/AD524X/examples/AD524X_setO/AD524X_setO.ino @@ -1,29 +1,36 @@ // // FILE: AD524X_setO.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.2 // PURPOSE: AD524X demo program -// DATE: 2013-10-12 // URL: https://github.com/RobTillaart/AD524X // + #include "AD524X.h" AD524X AD01(0x2C); // AD0 & AD1 == GND + void setup() { Serial.begin(115200); + Serial.println(); Serial.println(__FILE__); - Serial.println(AD524X_VERSION); + Serial.println(); + Serial.println(AD524X_LIB_VERSION); Wire.begin(); Wire.setClock(400000); + + bool b = AD01.begin(); + Serial.println(b ? "true" : "false"); + Serial.println(AD01.isConnected()); } + void loop() { - int x = 10+analogRead(A0); + int x = 10 + analogRead(A0); AD01.setO1(LOW); AD01.setO2(HIGH); Serial.print(AD01.getO1()); @@ -31,7 +38,7 @@ void loop() Serial.println(AD01.getO2()); delay(x); - x = 10+analogRead(A0); + x = 10 + analogRead(A0); AD01.setO1(HIGH); AD01.setO2(LOW); Serial.print(AD01.getO1()); @@ -40,4 +47,6 @@ void loop() delay(x); } + // -- END OF FILE -- + diff --git a/libraries/AD524X/examples/AD524X_write/AD524X_write.ino b/libraries/AD524X/examples/AD524X_write/AD524X_write.ino index 7f0fb345..f1d79903 100644 --- a/libraries/AD524X/examples/AD524X_write/AD524X_write.ino +++ b/libraries/AD524X/examples/AD524X_write/AD524X_write.ino @@ -1,26 +1,33 @@ // // FILE: AD524X_write.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.2 // PURPOSE: AD524X demo program -// DATE: 2013-10-12 // URL: https://github.com/RobTillaart/AD524X // + #include "AD524X.h" AD524X AD01(0x2C); // AD0 & AD1 == GND + void setup() { Serial.begin(115200); + Serial.println(); Serial.println(__FILE__); - Serial.println(AD524X_VERSION); + Serial.println(); + Serial.println(AD524X_LIB_VERSION); Wire.begin(); Wire.setClock(400000); + + bool b = AD01.begin(); + Serial.println(b ? "true" : "false"); + Serial.println(AD01.isConnected()); } + void loop() { for (int val = 0; val < 255; val++) @@ -39,4 +46,6 @@ void loop() } } + // -- END OF FILE -- + diff --git a/libraries/AD524X/examples/AD524X_write_AD5241/AD524X_write_AD5241.ino b/libraries/AD524X/examples/AD524X_write_AD5241/AD524X_write_AD5241.ino index f92d0714..506fe1a5 100644 --- a/libraries/AD524X/examples/AD524X_write_AD5241/AD524X_write_AD5241.ino +++ b/libraries/AD524X/examples/AD524X_write_AD5241/AD524X_write_AD5241.ino @@ -1,44 +1,53 @@ // // FILE: AD524X_write_AD5241ino.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.0 // PURPOSE: AD524X demo program -// DATE: 2020-12-08 // URL: https://github.com/RobTillaart/AD524X // + #include "AD524X.h" -AD5241 AD(0x2C); // AD0 & AD1 == GND +AD5241 AD01(0x2C); // AD0 & AD1 == GND + void setup() { Serial.begin(115200); + Serial.println(); Serial.println(__FILE__); - Serial.println(AD524X_VERSION); + Serial.println(); + Serial.println(AD524X_LIB_VERSION); Wire.begin(); Wire.setClock(400000); + + bool b = AD01.begin(); + Serial.println(b ? "true" : "false"); + Serial.println(AD01.isConnected()); - Serial.println(AD.pmCount()); + Serial.println(AD01.pmCount()); } + void loop() { for (int val = 0; val < 255; val++) { - AD.write(0, val); + AD01.write(0, val); if (val == 200) { - AD.write(1, val, HIGH, LOW); + AD01.write(1, val, HIGH, LOW); } if (val == 0) { - AD.write(0, val, LOW, LOW); + AD01.write(0, val, LOW, LOW); } Serial.println(val); delay(20); } } + // -- END OF FILE -- + diff --git a/libraries/AD524X/examples/AD524X_write_AD5242/AD524X_write_AD5242.ino b/libraries/AD524X/examples/AD524X_write_AD5242/AD524X_write_AD5242.ino index 0a5a27e8..141ac8f0 100644 --- a/libraries/AD524X/examples/AD524X_write_AD5242/AD524X_write_AD5242.ino +++ b/libraries/AD524X/examples/AD524X_write_AD5242/AD524X_write_AD5242.ino @@ -1,44 +1,54 @@ // // FILE: AD524X_write_AD5242.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.0 // PURPOSE: AD524X demo program -// DATE: 2020-12-08 // URL: https://github.com/RobTillaart/AD524X // + #include "AD524X.h" -AD5242 AD(0x2C); // AD0 & AD1 == GND +AD5242 AD01(0x2C); // AD0 & AD1 == GND + void setup() { Serial.begin(115200); + Serial.begin(115200); + Serial.println(); Serial.println(__FILE__); - Serial.println(AD524X_VERSION); + Serial.println(); + Serial.println(AD524X_LIB_VERSION); Wire.begin(); Wire.setClock(400000); + + bool b = AD01.begin(); + Serial.println(b ? "true" : "false"); + Serial.println(AD01.isConnected()); - Serial.println(AD.pmCount()); + Serial.println(AD01.pmCount()); } + void loop() { for (int val = 0; val < 255; val++) { - AD.write(1, val); + AD01.write(1, val); if (val == 200) { - AD.write(1, val, HIGH, LOW); + AD01.write(1, val, HIGH, LOW); } if (val == 0) { - AD.write(1, val, LOW, LOW); + AD01.write(1, val, LOW, LOW); } Serial.println(val); delay(20); } } + // -- END OF FILE -- + diff --git a/libraries/AD524X/keywords.txt b/libraries/AD524X/keywords.txt index c3b39342..f9aa2573 100644 --- a/libraries/AD524X/keywords.txt +++ b/libraries/AD524X/keywords.txt @@ -25,7 +25,7 @@ shutDown KEYWORD2 # Constants (LITERAL1) -AD524X_VERSION LITERAL1 +AD524X_LIB_VERSION LITERAL1 AS524X_OK LITERAL1 AS524X_ERROR LITERAL1 diff --git a/libraries/AD524X/library.json b/libraries/AD524X/library.json index 84538b09..5ab598d5 100644 --- a/libraries/AD524X/library.json +++ b/libraries/AD524X/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/AD524X" }, - "version": "0.3.3", + "version": "0.3.4", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/libraries/AD524X/library.properties b/libraries/AD524X/library.properties index d4535a7d..0dab7182 100644 --- a/libraries/AD524X/library.properties +++ b/libraries/AD524X/library.properties @@ -1,5 +1,5 @@ name=AD524X -version=0.3.3 +version=0.3.4 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino Library for AD524X diff --git a/libraries/AD524X/test/unit_test_001.cpp b/libraries/AD524X/test/unit_test_001.cpp index 95d63541..b486354f 100644 --- a/libraries/AD524X/test/unit_test_001.cpp +++ b/libraries/AD524X/test/unit_test_001.cpp @@ -27,6 +27,7 @@ unittest_setup() { + fprintf(stderr, "\nAD524X_LIB_VERSION: %s\n", (char *) AD524X_LIB_VERSION); }