Skip to content

Commit 1ea4f6d

Browse files
committed
0.5.2 AD524X
1 parent 4ffb889 commit 1ea4f6d

File tree

10 files changed

+246
-16
lines changed

10 files changed

+246
-16
lines changed

libraries/AD524X/AD524X.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: AD524X.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.5.1
4+
// VERSION: 0.5.2
55
// PURPOSE: I2C digital potentiometer AD5241 AD5242
66
// DATE: 2013-10-12
77
// URL: https://github.com/RobTillaart/AD524X

libraries/AD524X/AD524X.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: AD524X.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.5.1
5+
// VERSION: 0.5.2
66
// PURPOSE: I2C digital PotentioMeter AD5241 AD5242
77
// DATE: 2013-10-12
88
// URL: https://github.com/RobTillaart/AD524X
@@ -12,7 +12,7 @@
1212
#include "Wire.h"
1313

1414

15-
#define AD524X_LIB_VERSION (F("0.5.1"))
15+
#define AD524X_LIB_VERSION (F("0.5.2"))
1616

1717

1818
#define AD524X_OK 0

libraries/AD524X/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.5.2] - 2025-06-20
10+
- fix #30, typo in keywords.txt
11+
- add example cascading_potmeters.ino
12+
- add CascadingPotmeters.md
13+
- minor edits
14+
915
## [0.5.1] - 2024-03-16
1016
- add **getAddress()** (e.g. debugging)
1117
- improved **AD5241::write(rdac, ...)**
@@ -14,7 +20,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1420
- update keywords.txt
1521
- minor edits examples
1622

17-
1823
## [0.5.0] - 2023-11-29
1924
- remove ESP32 specific **begin()**
2025
- add (experimental) support or AD5280 / AD5282.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
2+
## Cascading Potentiometers
3+
4+
Some notes on cascading potentiometers to have a large range with higher precision.
5+
6+
Based upon - https://github.com/RobTillaart/AD524X/issues/26
7+
8+
9+
10+
### Cascaded voltage divider
11+
12+
Basic cascade to vary voltage connects:
13+
14+
- all B's to GND
15+
- A of top level to 5V (or 3V3 whatever)
16+
- wiper W of one level to the A of next leve;
17+
- last wiper W is final output
18+
19+
20+
```
21+
5V ----A[ 1000 K ]B----- GND
22+
W
23+
|
24+
+---------+ V1
25+
|
26+
+----A[ 100 K ]B----- GND
27+
W
28+
|
29+
+---------+ V2
30+
|
31+
+----A[ 10 K ]B----- GND
32+
W
33+
|
34+
|
35+
o 256 steps between GND and V2
36+
37+
```
38+
39+
Some math for a two potentiometer system see **cascading_voltage_divider.ino** example.
40+
41+
42+
### Range voltage divider
43+
44+
The following setup has two potmeters, left and right, to define a range.
45+
- X can be set between 0.0 and 5.0 Volt and
46+
- Y can be set between 0.0 and 5.0 volt.
47+
48+
The third range potentiometer has 256 positions within the defined range range.
49+
E.g if left is set to 2.3 Volt and right is set to 2.5 Volt,
50+
the range potentiometer divides this 0.2 volt in 256 steps of about a single millivolt (in theory).
51+
52+
53+
```
54+
left limit pot right limit pot
55+
56+
GND ----A[ 100K ]B---- 5V ----A[ 100K ]B---- GND
57+
W W
58+
| |
59+
| range pot |
60+
| |
61+
X +------A[ 100 K ]B------+ Y
62+
W
63+
|
64+
|
65+
o voltage between (0..Vcc)
66+
67+
```
68+
69+
70+
### Cascaded resistor
71+
72+
No dangling connectors give less noise as even a bad wiper will not break
73+
the resistance chain completely. (Preferred imho)
74+
75+
76+
```
77+
----A[ 1000K ]B----+----A[ 100 K ]B----+----A[ 10 K ]B----+---o
78+
W | W | W |
79+
| | | | | |
80+
+----------+ +-----------+ +----------+
81+
```
82+
83+
84+
Connected the AD524X as rheostats, saves a few connnections.
85+
86+
```
87+
----A[ 1000K ]B +----A[ 100 K ]B +----A[ 10 K ]B +---o
88+
W | W | W |
89+
| | | | | |
90+
+----------+ +-----------+ +----------+
91+
```
92+
93+
Some math for a two potentiometer system see **cascading_potentiometers.ino** example.
94+
95+
96+
### Zero switch
97+
98+
An additional option is to connect the first A with the last B with "zero" switch to get 0 Ohm.
99+
This would solve the Wiper Resistance which is 60- 120 Ohm for the AD5422 (datasheet P3).
100+
Note with three wipers in a cascade the Wiper Resistance adds up to 200-360 Ohm,
101+
Optionally you can place a zero switch over every potentiometer.
102+
Drawback is extra components, control lines and code.
103+
104+
```
105+
"zero" switch
106+
+--------------------------o \o--------------------------------+
107+
| |
108+
| |
109+
-+--A[ 1000K ]B +----A[ 100 K ]B +----A[ 10 K ]B +---o
110+
W | W | W |
111+
| | | | | |
112+
+----------+ +-----------+ +----------+
113+
```
114+
115+
###
116+

libraries/AD524X/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2013-2024 Rob Tillaart
3+
Copyright (c) 2013-2025 Rob Tillaart
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

libraries/AD524X/README.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ The library defines AD524X_MIDPOINT == 127.
4343
To be used to set to defined mid-point.
4444

4545

46-
#### 0.5.0 Breaking change
46+
### 0.5.0 Breaking change
4747

4848
The ESP32 specific **begin(sda, scl)** is removed.
4949
The user has to call **Wire.begin()** or equivalent himself before calling **begin()**.
5050

5151

52-
#### Related
52+
### Related
5353

5454
- https://github.com/RobTillaart/AD520x
5555
- https://github.com/RobTillaart/AD524X
@@ -60,7 +60,7 @@ The user has to call **Wire.begin()** or equivalent himself before calling **beg
6060
- https://github.com/RobTillaart/X9C10X
6161

6262

63-
#### Compatibles ?
63+
### Compatibles ?
6464

6565
If you find compatible devices please let me know.
6666

@@ -77,6 +77,24 @@ The AD524X has two address lines to configure the I2C address. 0x2C - 0x2F
7777
| 47 | 0x2F | +5V | +5V |
7878

7979

80+
### I2C multiplexing
81+
82+
Sometimes you need to control more devices than possible with the default
83+
address range the device provides.
84+
This is possible with an I2C multiplexer e.g. TCA9548 which creates up
85+
to eight channels (think of it as I2C subnets) which can use the complete
86+
address range of the device.
87+
88+
Drawback of using a multiplexer is that it takes more administration in
89+
your code e.g. which device is on which channel.
90+
This will slow down the access, which must be taken into account when
91+
deciding which devices are on which channel.
92+
Also note that switching between channels will slow down other devices
93+
too if they are behind the multiplexer.
94+
95+
- https://github.com/RobTillaart/TCA9548
96+
97+
8098
## Interface
8199

82100
```cpp
@@ -87,7 +105,7 @@ The library has a number of functions which are all quite straightforward.
87105
One can get / set the value of (both) the potentiometer(s), and the O1 and O2 output lines.
88106

89107

90-
#### Constructors
108+
### Constructors
91109

92110
- **AD524X(uint8_t address, TwoWire \*wire = &Wire)** constructor base class,
93111
creates an instance with 2 potentiometer.
@@ -99,15 +117,15 @@ The developer is responsible for handling this correctly.
99117
- **AD5282(uint8_t address, TwoWire \*wire = &Wire)** create an instance with 2 potentiometer.
100118

101119

102-
#### Wire initialization
120+
### Initialization
103121

104122
- **bool begin()** initialization of the object.
105123
Note the user must call **wire.begin()** or equivalent before calling **begin()**.
106124
- **bool isConnected()** See if the address set in constructor is on the I2C bus.
107125
- **uint8_t getAddress()** returns address set in constructor, convenience.
108126

109127

110-
#### Basic IO
128+
### Basic IO
111129

112130
- **uint8_t write(uint8_t rdac, uint8_t value)** set channel rdac 0/1 to value 0..255.
113131
- **uint8_t write(uint8_t rdac, uint8_t value, uint8_t O1, uint8_t O2)** idem + set output lines O1 and O2 too.
@@ -118,15 +136,15 @@ Note the user must call **wire.begin()** or equivalent before calling **begin()*
118136
- **uint8_t getO2()** read back O2 line.
119137

120138

121-
#### Misc
139+
### Misc
122140

123141
- **uint8_t zeroAll()** sets potentiometer's to 0 and I/O to LOW.
124142
- **uint8_t reset()** sets potentiometer's to midpoint == 127 and I/O to LOW. (startup default)
125143
- **uint8_t midScaleReset(uint8_t rdac)** resets one potentiometer to midpoint == 127.
126144
- **uint8_t readBackRegister()** read register back, for debugging.
127145

128146

129-
#### Experimental
147+
### Experimental
130148

131149
- **uint8_t shutDown()** check datasheet, not tested yet, use at own risk.
132150

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// FILE: cascading_potentiometers.ino
2+
// AUTHOR: Rob Tillaart
3+
// DATE: 2024-11-05
4+
// PURPOSE: demo, calculates values for two cascaded potentiometers
5+
// URL: https://github.com/RobTillaart/AD524X/issues/26
6+
//
7+
// experimental
8+
// precision is as good as the smallest potentiometer.
9+
// math needs actual LSB and include Rwiper (TODO).
10+
//
11+
12+
#include "Arduino.h"
13+
14+
15+
uint32_t start, stop;
16+
17+
float LSB_A = 1e6 / 255.0; // 1 M Ohm
18+
float LSB_B = 1e4 / 255.0; // 10 K Ohm
19+
float R = 0;
20+
21+
void setup()
22+
{
23+
Serial.begin(115200);
24+
while (!Serial);
25+
Serial.println(__FILE__);
26+
27+
// find settings for all R's in steps of pot LSB_B
28+
// LSB_B iso 40 would be more exact but gives "no nice numbers"
29+
for (uint32_t r = 0; r <= 1000000; r += 40)
30+
{
31+
search(r);
32+
}
33+
34+
}
35+
36+
37+
void loop()
38+
{
39+
}
40+
41+
42+
//
43+
// searches optimal positions for pot A and pot B
44+
// simplified math, ignores Rwiper
45+
//
46+
void search(uint32_t value)
47+
{
48+
uint32_t t = value;
49+
int a = t / LSB_A;
50+
t -= a * LSB_A;
51+
int b = round(t / LSB_B);
52+
R = a * LSB_A + b * LSB_B;
53+
54+
Serial.print(value); // requested R
55+
Serial.print('\t');
56+
Serial.print(a); // position pot A
57+
Serial.print('\t');
58+
Serial.print(b); // position pot B
59+
Serial.print('\t');
60+
Serial.print(R); // effecive R
61+
Serial.print('\t');
62+
Serial.print(abs(R - value)); // absolute error
63+
Serial.print('\t');
64+
Serial.print(100 * abs(R - value) / value); // percentage relative error
65+
Serial.println();
66+
}
67+
68+
69+
//
70+
// prints all possible values
71+
// simplified math, ignores Rwiper
72+
//
73+
void printTable()
74+
{
75+
for (int a = 0; a < 256; a += 2)
76+
{
77+
R = a * LSB_A;
78+
for (int b = 0; b < 256; b++)
79+
{
80+
Serial.print(a);
81+
Serial.print('\t');
82+
Serial.print(b);
83+
Serial.print('\t');
84+
Serial.print(R);
85+
Serial.println();
86+
R += LSB_B;
87+
}
88+
}
89+
}
90+
91+
// -- END OF FILE --

libraries/AD524X/keywords.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ shutDown KEYWORD2
3535
AD524X_LIB_VERSION LITERAL1
3636

3737
AD524X_OK LITERAL1
38-
ADS524X_ERROR LITERAL1
38+
AD524X_ERROR LITERAL1
3939
AD524X_MIDPOINT LITERAL1
4040

libraries/AD524X/library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/AD524X"
1717
},
18-
"version": "0.5.1",
18+
"version": "0.5.2",
1919
"license": "MIT",
2020
"frameworks": "*",
2121
"platforms": "*",

libraries/AD524X/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=AD524X
2-
version=0.5.1
2+
version=0.5.2
33
author=Rob Tillaart <[email protected]>
44
maintainer=Rob Tillaart <[email protected]>
55
sentence=Arduino Library for AD524X

0 commit comments

Comments
 (0)