Skip to content

Commit

Permalink
refactor, add getAddress() (#25)
Browse files Browse the repository at this point in the history
- add **getAddress()** (e.g. debugging)
- improved **AD5241::write(rdac, ...)**
- improved **AD5280::write(rdac, ...)**
- update GitHub actions
- update keywords.txt
- minor edits examples
  • Loading branch information
RobTillaart authored Mar 16, 2024
1 parent b9eb399 commit be2bab8
Show file tree
Hide file tree
Showing 25 changed files with 71 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# These are supported funding model platforms

github: RobTillaart

custom: "https://www.paypal.me/robtillaart"
2 changes: 1 addition & 1 deletion .github/workflows/arduino-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/arduino_test_runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/jsoncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ 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
uses: limitusus/json-syntax-check@v2
with:
pattern: "\\.json$"

20 changes: 15 additions & 5 deletions AD524X.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FILE: AD524X.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.5.0
// VERSION: 0.5.1
// PURPOSE: I2C digital potentiometer AD5241 AD5242
// DATE: 2013-10-12
// URL: https://github.com/RobTillaart/AD524X
Expand Down Expand Up @@ -46,6 +46,12 @@ bool AD524X::isConnected()
}


uint8_t AD524X::getAddress()
{
return _address;
}


uint8_t AD524X::reset()
{
write(0, AD524X_MIDPOINT, LOW, LOW);
Expand Down Expand Up @@ -202,13 +208,15 @@ uint8_t AD5241::write(const uint8_t value, const uint8_t O1, const uint8_t O2)

uint8_t AD5241::write(const uint8_t rdac, const uint8_t value)
{
return AD524X::write(rdac, value);
if (rdac >= _pmCount) return AD524X_ERROR;
return AD5241::write(value);
}


uint8_t AD5241::write(const uint8_t rdac, const uint8_t value, const uint8_t O1, const uint8_t O2)
{
return AD524X::write(rdac, value, O1, O2);
if (rdac >= _pmCount) return AD524X_ERROR;
return AD5241::write(value, O1, O2);
}


Expand Down Expand Up @@ -251,13 +259,15 @@ uint8_t AD5280::write(const uint8_t value, const uint8_t O1, const uint8_t O2)

uint8_t AD5280::write(const uint8_t rdac, const uint8_t value)
{
return AD524X::write(rdac, value);
if (rdac >= _pmCount) return AD524X_ERROR;
return AD5280::write(value);
}


uint8_t AD5280::write(const uint8_t rdac, const uint8_t value, const uint8_t O1, const uint8_t O2)
{
return AD524X::write(rdac, value, O1, O2);
if (rdac >= _pmCount) return AD524X_ERROR;
return AD5280::write(value, O1, O2);
}


Expand Down
5 changes: 3 additions & 2 deletions AD524X.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// FILE: AD524X.h
// AUTHOR: Rob Tillaart
// VERSION: 0.5.0
// VERSION: 0.5.1
// PURPOSE: I2C digital PotentioMeter AD5241 AD5242
// DATE: 2013-10-12
// URL: https://github.com/RobTillaart/AD524X
Expand All @@ -12,7 +12,7 @@
#include "Wire.h"


#define AD524X_LIB_VERSION (F("0.5.0"))
#define AD524X_LIB_VERSION (F("0.5.1"))


#define AD524X_OK 0
Expand All @@ -29,6 +29,7 @@ class AD524X

bool begin();
bool isConnected();
uint8_t getAddress();

// RESET
uint8_t reset(); // reset both channels to AD524X_MIDPOINT and O1/O2 to LOW
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.5.1] - 2024-03-16
- add **getAddress()** (e.g. debugging)
- improved **AD5241::write(rdac, ...)**
- improved **AD5280::write(rdac, ...)**
- update GitHub actions
- update keywords.txt
- minor edits examples


## [0.5.0] - 2023-11-29
- remove ESP32 specific **begin()**
- add (experimental) support or AD5280 / AD5282.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2013-2023 Rob Tillaart
Copyright (c) 2013-2024 Rob Tillaart

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
35 changes: 15 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ The AD5241, AD5242, AD5280 and AD5282 are digital potentiometers.
The AD5241/80 has one, the AD5242/82 has two potentiometers.
Both types have two output lines O1 and O2.

The main difference in the AD524x and AD528x series is the resistance.
See the table below.

The AD5280/82 is compatible with AD5241/42 (based upon datasheet compare).
The library provides separate classes for the AD5280/82 however these are
not tested with actual hardware yet.
Please let me know if you get the AD5280/82 classes working.

| device | channels | steps | ranges KΩ |
|:--------:|:----------:|:------:|:---------------:|
| AD5241 | 1 | 256 | 10, 100, 1000 |
| AD5242 | 2 | 256 | 10, 100, 1000 |
| AD5280 | 1 | 256 | 20, 50, 200 |
| AD5282 | 2 | 256 | 20, 50, 200 |
| device | channels | steps | ranges KΩ |
|:--------:|:----------:|:-------:|:---------------:|
| AD5241 | 1 | 256 | 10, 100, 1000 |
| AD5242 | 2 | 256 | 10, 100, 1000 |
| AD5280 | 1 | 256 | 20, 50, 200 |
| AD5282 | 2 | 256 | 20, 50, 200 |


An important property of the devices is that they defaults
Expand All @@ -51,16 +54,14 @@ The user has to call **Wire.begin()** or equivalent himself before calling **beg
- https://github.com/RobTillaart/AD520x
- https://github.com/RobTillaart/AD524X
- https://github.com/RobTillaart/AD5245
- https://github.com/RobTillaart/AD5248 (also AD5243)
- https://github.com/RobTillaart/AD5144A
- https://github.com/RobTillaart/AD5263
- https://github.com/RobTillaart/X9C10X


#### Compatibles ?

The AD5243 (fixed address) and AD5248 (2 address pins) are very close but
not compatible with this library. See future.

If you find compatible devices please let me know.


Expand Down Expand Up @@ -103,6 +104,7 @@ The developer is responsible for handling this correctly.
- **bool begin()** initialization of the object.
Note the user must call **wire.begin()** or equivalent before calling **begin()**.
- **bool isConnected()** See if the address set in constructor is on the I2C bus.
- **uint8_t getAddress()** returns address set in constructor, convenience.


#### Basic IO
Expand All @@ -129,7 +131,7 @@ Note the user must call **wire.begin()** or equivalent before calling **begin()*
- **uint8_t shutDown()** check datasheet, not tested yet, use at own risk.


## Interface AD5421 specific
## Interface AD5421 + AD5280 specific

Since 0.4.1 the library supports writing explicit to port 0
as that is the only port.
Expand All @@ -138,13 +140,8 @@ as that is the only port.
- **uint8_t write(const uint8_t value, const uint8_t O1, const uint8_t O2)**
idem + set output lines O1 and O2 too.

Note that the **write(rdac, value)** can be called but behaviour is not defined.
(need to test behaviour or "block" this call).


## Operation

The examples show the basic working of the functions.
Note that **uint8_t write(rdac, value)** and **uint8_t write(rdac, value, O1, O2)**
can be called and return **AD524X_ERROR** if **rdac > 0**.


## Error codes
Expand All @@ -164,7 +161,6 @@ The examples show the basic working of the functions.
#### Should

- verify the working of AD5280 and AD5282.
- improve AD5241 handling of **write(rdac, value)** calls (block?)
- improve error handling.
- sync with AD520X library.

Expand All @@ -174,8 +170,7 @@ The examples show the basic working of the functions.
#### Wont

- make midpoint 128
- investigate AD5243 ==> separate library!)
- has no O1 and O2 lines.


## Support

Expand Down
3 changes: 1 addition & 2 deletions examples/AD5241_write/AD5241_write.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// AUTHOR: Rob Tillaart
// PURPOSE: AD5241 demo program - single channel!
// URL: https://github.com/RobTillaart/AD524X
//


#include "AD524X.h"
Expand All @@ -21,7 +20,7 @@ void setup()

Wire.begin();
Wire.setClock(400000);

bool b = AD01.begin();
Serial.println(b ? "true" : "false");
Serial.println(AD01.isConnected());
Expand Down
3 changes: 1 addition & 2 deletions examples/AD5242_write_RP2040/AD5242_write_RP2040.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// AUTHOR: Rob Tillaart
// PURPOSE: AD524X demo program
// URL: https://github.com/RobTillaart/AD524X
//


#include "AD524X.h"
Expand All @@ -23,7 +22,7 @@ void setup()
Wire.setSCL(13); // adjust if needed
Wire.begin();
Wire.setClock(400000);

bool b = AD01.begin();
Serial.println(b ? "true" : "false");
Serial.println(AD01.isConnected());
Expand Down
3 changes: 1 addition & 2 deletions examples/AD524X_followA0/AD524X_followA0.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// AUTHOR: Rob Tillaart
// PURPOSE: AD524X demo program
// URL: https://github.com/RobTillaart/AD524X
//


#include "AD524X.h"
Expand All @@ -21,7 +20,7 @@ void setup()

Wire.begin();
Wire.setClock(400000);

bool b = AD01.begin();
Serial.println(b ? "true" : "false");
Serial.println(AD01.isConnected());
Expand Down
3 changes: 1 addition & 2 deletions examples/AD524X_isConnected/AD524X_isConnected.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// AUTHOR: Rob Tillaart
// PURPOSE: AD524X demo program
// URL: https://github.com/RobTillaart/AD524X
//


#include "AD524X.h"
Expand All @@ -21,7 +20,7 @@ void setup()

Wire.begin();
Wire.setClock(400000);

bool b = AD01.begin();
Serial.println(b ? "true" : "false");
Serial.println(AD01.isConnected());
Expand Down
1 change: 0 additions & 1 deletion examples/AD524X_midScaleReset/AD524X_midScaleReset.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// AUTHOR: Rob Tillaart
// PURPOSE: AD524X demo program
// URL: https://github.com/RobTillaart/AD524X
//


#include "AD524X.h"
Expand Down
1 change: 0 additions & 1 deletion examples/AD524X_read/AD524X_read.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// AUTHOR: Rob Tillaart
// PURPOSE: AD524X demo program
// URL: https://github.com/RobTillaart/AD524X
//


#include "AD524X.h"
Expand Down
7 changes: 3 additions & 4 deletions examples/AD524X_readBackRegister/AD524X_readBackRegister.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
// AUTHOR: Rob Tillaart
// PURPOSE: AD524X demo program
// URL: https://github.com/RobTillaart/AD524X
//


#include "AD524X.h"

AD524X AD01(0x2C); // AD0 & AD1 == GND
AD524X AD01(0x2C); // AD0 & AD1 == GND


void setup()
Expand All @@ -21,7 +20,7 @@ void setup()

Wire.begin();
Wire.setClock(400000);

bool b = AD01.begin();
Serial.println(b ? "true" : "false");
Serial.println(AD01.isConnected());
Expand All @@ -45,7 +44,7 @@ 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');
Expand Down
3 changes: 1 addition & 2 deletions examples/AD524X_sawtooth/AD524X_sawtooth.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// AUTHOR: Rob Tillaart
// PURPOSE: AD524X demo program
// URL: https://github.com/RobTillaart/AD524X
//


#include "AD524X.h"
Expand All @@ -21,7 +20,7 @@ void setup()

Wire.begin();
Wire.setClock(400000);

bool b = AD01.begin();
Serial.println(b ? "true" : "false");
Serial.println(AD01.isConnected());
Expand Down
3 changes: 1 addition & 2 deletions examples/AD524X_setO/AD524X_setO.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// AUTHOR: Rob Tillaart
// PURPOSE: AD524X demo program
// URL: https://github.com/RobTillaart/AD524X
//


#include "AD524X.h"
Expand All @@ -21,7 +20,7 @@ void setup()

Wire.begin();
Wire.setClock(400000);

bool b = AD01.begin();
Serial.println(b ? "true" : "false");
Serial.println(AD01.isConnected());
Expand Down
Loading

0 comments on commit be2bab8

Please # to comment.