Skip to content

Commit de2a3cc

Browse files
committed
0.1.1 DS1804
1 parent 603c37a commit de2a3cc

15 files changed

Lines changed: 278 additions & 25 deletions

File tree

libraries/DS1804/.github/workflows/arduino-lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ jobs:
66
runs-on: ubuntu-latest
77
timeout-minutes: 5
88
steps:
9-
- uses: actions/checkout@v4
10-
- uses: arduino/arduino-lint-action@v1
9+
- uses: actions/checkout@v5
10+
- uses: arduino/arduino-lint-action@v2
1111
with:
1212
library-manager: update
1313
compliance: strict

libraries/DS1804/.github/workflows/arduino_test_runner.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
timeout-minutes: 20
99

1010
steps:
11-
- uses: actions/checkout@v4
11+
- uses: actions/checkout@v5
1212
- uses: ruby/setup-ruby@v1
1313
with:
1414
ruby-version: 2.6

libraries/DS1804/.github/workflows/jsoncheck.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ on:
55
paths:
66
- '**.json'
77
pull_request:
8+
paths:
9+
- '**.json'
810

911
jobs:
1012
test:
1113
runs-on: ubuntu-latest
1214
timeout-minutes: 5
1315
steps:
14-
- uses: actions/checkout@v4
16+
- uses: actions/checkout@v5
1517
- name: json-syntax-check
1618
uses: limitusus/json-syntax-check@v2
1719
with:

libraries/DS1804/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
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.1.1] - 2025-12-10
10+
- add **bool selected()** to get status.
11+
- add example **DS1804_array.ino**
12+
- update GitHub actions
13+
- minor edits
14+
915
## [0.1.0] - 2024-11-11
1016
- initial version
1117

libraries/DS1804/DS1804.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
//
33
// FILE: DS1804.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.1.0
5+
// VERSION: 0.1.1
6+
// DATE: 24-11-11
67
// PURPOSE: Arduino library for DS1804 Nonvolatile Trimmer Potentiometer.
78
// URL: https://github.com/RobTillaart/DS1804
89

910

1011
#include "Arduino.h"
1112

12-
#define DS1804_LIB_VERSION (F("0.1.0"))
13+
#define DS1804_LIB_VERSION (F("0.1.1"))
1314

1415

1516
class DS1804
@@ -42,6 +43,12 @@ class DS1804
4243
};
4344

4445

46+
inline bool selected()
47+
{
48+
return (digitalRead(_csPin) != LOW);
49+
};
50+
51+
4552
void moveUp(uint8_t n = 1)
4653
{
4754
if (n > 100) n = 100;

libraries/DS1804/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) 2024-2024 Rob Tillaart
3+
Copyright (c) 2024-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/DS1804/PARALLEL.MD

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
## Parallel control of multiple DS1804
3+
4+
It is easy to control N DS1804 with N+2 lines.
5+
Design wise it is very much like the SPI bus.
6+
7+
- all share GND (including processor).
8+
- all share U/D pin
9+
- all share INC pin
10+
- all have **unique CS** pins
11+
12+
Note that the DS1804's need a **separate** power source.
13+
14+
15+
### Schema
16+
17+
```
18+
+----------+ +----------+
19+
| INC |-----------------------+---| INC |
20+
| | | | |
21+
| U/D |--------------------+------| U/D |
22+
| | | | | |
23+
| CS |-----+ +------------------| CS |
24+
| | | | | | | |
25+
| DS1804 | | | | | | DS1804 |
26+
+----------+ | | | | +----------+
27+
| | | |
28+
| | | |
29+
+----------+ | | | | +----------+
30+
| INC |-----------------------+---| INC |
31+
| | | | | | | |
32+
| U/D |--------------------+------| U/D |
33+
| | | | | | | |
34+
| CS |--+ | | +---------------| CS |
35+
| | | | | | | | | |
36+
| DS1804 | | | | | | | | DS1804 |
37+
+----------+ | | | | | | +----------+
38+
| | | | | |
39+
| | | | | |
40+
| | | | | |
41+
| | | | | |
42+
+-------------------------------------------------+
43+
| 0 1 2 3 u i |
44+
| |
45+
| |
46+
| |
47+
| |
48+
| processor |
49+
+-------------------------------------------------+
50+
51+
Note common GND is not in the schema.
52+
```
53+
54+
55+
### Code
56+
57+
in the code
58+
- select the Up or DOWN mode with pin u.
59+
- select the device with pin 0, 1, 2, 3, .... n
60+
- set a HIGH LOW pulse train on pin i to move the number of steps.
61+
62+
63+
### Parallelism
64+
65+
It is possible to select multiple devices and give them a number of pulses so they go up/down in parallel.
66+
- left and right channel in stereo.
67+
- set all (or subset) to zero.
68+
- more complex patterns to increase parallelism (performance) but this is more difficult coding wise.
69+
70+
71+

libraries/DS1804/README.md

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,42 @@ Arduino library for DS1804 Nonvolatile Trimmer Potentiometer.
2121
The library implements a class for the DS1804 potentiometer.
2222
These devices come in 10K, 50K and 100K and allows control in 100 steps.
2323

24-
The DS1804 has a simple pulse interface and cannot be read back
25-
so the library cannot provide the current position of the wiper.
24+
The DS1804 has a simple pulse interface and can **not** be read back
25+
so the library can not provide the current position of the wiper.
2626

2727
The DS1804 has an EEPROM to save the current position (writeable for 50000 times)
28-
and uses that as start position at power up.
28+
and uses that value as start position at power up.
29+
30+
Feedback as always is welcome.
31+
2932

3033
### Power up / down
3134

3235
(from datasheet)
33-
On power-up, wiper position will be loaded within a maximum time
34-
period of 500µs once the power-supply is stable.
35-
Additionally, the three-terminal interface port will be active after 50 ms.
36+
On **power-up**, wiper position will be loaded within a maximum time
37+
period of **500 µs** once the power-supply is stable.
38+
Additionally, the three-terminal interface port will be active after **50 ms**.
3639

37-
On power-down, the wiper position register data will be **lost**.
40+
On **power-down**, the wiper position register data will be **lost**.
3841
On the next device power-up, the value of
3942
EEPROM memory will be loaded into the wiper position register.
4043

4144
There is no defined factory default, expect the value to be random.
45+
As the device has no feedback, one must send 100 pulses to move the trimmer to the begin or end point.
46+
47+
48+
### Alternative use
4249

50+
One could use the UP/ DOWN pins of the device to read signals from an
51+
external system. The microprocessor could monitor the state by means of an
52+
ADC measurement (and optional act upon it).
53+
54+
This is not implemented in the library, just worth to mention.
55+
4356

4457
### Related
4558

46-
Other digipots
59+
Other digipots (not all)
4760

4861
- https://github.com/RobTillaart/AD520x
4962
- https://github.com/RobTillaart/AD524X
@@ -67,13 +80,18 @@ Other digipots
6780
- **void begin(bool b = false)** initializes pins,
6881
default the device is not selected.
6982

83+
7084
### Base
7185

7286
- **void select(bool b)** enable / disable device.
73-
- **void moveUp(uint8_t n = 1)** if enabled move position n steps up (n is clipped to 0..100)
74-
- **void moveDown(uint8_t n = 1)** if enabled move position n steps down (n is clipped to 0..100)
87+
- **bool selected()** returns current status (csPin).
88+
- **void moveUp(uint8_t steps = 1)** if enabled move position n steps up (steps is clipped to 0..100)
89+
- **void moveDown(uint8_t steps = 1)** if enabled move position n steps down (steps is clipped to 0..100)
90+
91+
Duration of moveUp/Down depends linearly on the parameter steps, expect less than half a millisecond.
92+
93+
Note: One must send 100 pulses to move the trimmer to the begin or end point. (no feedback).
7594

76-
Duration of moveUp/Down depends linearly on n, expect less than half a millisecond.
7795

7896
### EEPROM power up value
7997

@@ -95,15 +113,14 @@ See **DS1804_save_EEPROM.ino**
95113

96114
#### Should
97115

98-
- array example (sharing UD, INC pins, unique CS)
99-
- stereo example, (sharing all pins).
100116

101117
#### Could
102118

103119
- default true for select() / begin()?
104120

105121
#### Wont
106122

123+
- void mute(); (depends on 3 pins if up or down is mute)
107124

108125
## Support
109126

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// FILE: DS1804_array.ino
2+
// AUTHOR: Rob Tillaart
3+
// PURPOSE: demo
4+
// URL: https://github.com/RobTillaart/DS1804
5+
//
6+
// not tested yet
7+
8+
#include "DS1804.h"
9+
10+
11+
// adjust pins if needed
12+
const uint8_t CSPIN1 = 3;
13+
const uint8_t CSPIN2 = 4;
14+
const uint8_t CSPIN3 = 5;
15+
const uint8_t INCPIN = 6;
16+
const uint8_t UDPIN = 7;
17+
18+
19+
DS1804 ds[3] =
20+
{
21+
DS1804(CSPIN1, INCPIN, UDPIN),
22+
DS1804(CSPIN2, INCPIN, UDPIN),
23+
DS1804(CSPIN3, INCPIN, UDPIN)
24+
};
25+
26+
int idx = 0;
27+
28+
29+
void setup()
30+
{
31+
Serial.begin(115200);
32+
while (!Serial);
33+
Serial.println();
34+
Serial.println(__FILE__);
35+
Serial.print("DS1804_LIB_VERSION: ");
36+
Serial.println(DS1804_LIB_VERSION);
37+
Serial.println();
38+
39+
// all deselected by default
40+
for (int i = 0; i < 3; i++)
41+
{
42+
ds[i].begin();
43+
}
44+
}
45+
46+
47+
void loop()
48+
{
49+
if (Serial.available())
50+
{
51+
int c = Serial.read();
52+
// SELECT MODULE
53+
if (c == '0') {
54+
idx = 0;
55+
ds[0].select(true);
56+
ds[1].select(false);
57+
ds[2].select(false);
58+
};
59+
if (c == '1') {
60+
idx = 1;
61+
ds[0].select(false);
62+
ds[1].select(true);
63+
ds[2].select(false);
64+
};
65+
if (c == '2') {
66+
idx = 2;
67+
ds[0].select(false);
68+
ds[1].select(false);
69+
ds[2].select(true);
70+
};
71+
// DESELECT ALL
72+
if (c == '3') {
73+
idx = 0;
74+
ds[0].select(false);
75+
ds[1].select(false);
76+
ds[2].select(false);
77+
};
78+
// UP DOWN
79+
if (c == 'U') ds[idx].moveUp();
80+
if (c == 'D') ds[idx].moveDown();
81+
}
82+
}
83+
84+
85+
// -- END OF FILE --

libraries/DS1804/examples/DS1804_demo/DS1804_demo.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99

1010
// adjust pins if needed
11-
const uint8_t CSPIN = 5;
11+
const uint8_t CSPIN = 5;
1212
const uint8_t INCPIN = 6;
13-
const uint8_t UDPIN = 7;
13+
const uint8_t UDPIN = 7;
1414

1515
DS1804 ds(CSPIN, INCPIN, UDPIN);
1616

@@ -19,9 +19,11 @@ void setup()
1919
{
2020
Serial.begin(115200);
2121
while (!Serial);
22+
Serial.println();
2223
Serial.println(__FILE__);
2324
Serial.print("DS1804_LIB_VERSION: ");
2425
Serial.println(DS1804_LIB_VERSION);
26+
Serial.println();
2527

2628
ds.begin();
2729
ds.select(true);

0 commit comments

Comments
 (0)