Skip to content

Commit bde254d

Browse files
committed
added updated examples
1 parent da97f8c commit bde254d

File tree

5 files changed

+102
-12
lines changed

5 files changed

+102
-12
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ bundles
99
*.DS_Store
1010
.eggs
1111
dist
12-
**/*.egg-info
12+
**/*.egg-info
13+
.vscode/

README.rst

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,42 @@ Usage Example
6363
import adafruit_ds3502
6464
from analogio import AnalogIn
6565
66+
####### NOTE ################
67+
# this example will not work with Blinka/rasberry Pi due to the lack of analog pins.
68+
# Blinka and Raspberry Pi users should run the "ds3502_blinka_simpletest.py" example
69+
6670
i2c = board.I2C()
6771
ds3502 = adafruit_ds3502.DS3502(i2c)
6872
wiper_output = AnalogIn(board.A0)
6973
70-
ds3502.wiper = 127
71-
print("Wiper value: %d"%wiper_output.value)
72-
sleep(1.0)
73-
74-
ds3502.wiper = 0
75-
print("Wiper value: %d"%wiper_output.value)
74+
while True:
75+
76+
ds3502.wiper = 127
77+
print("Wiper set to %d"%ds3502.wiper)
78+
voltage = wiper_output.value
79+
voltage *= 3.3
80+
voltage /= 65535
81+
print("Wiper voltage: %.2f"%voltage)
82+
print("")
83+
sleep(1.0)
84+
85+
ds3502.wiper = 0
86+
print("Wiper set to %d"%ds3502.wiper)
87+
voltage = wiper_output.value
88+
voltage *= 3.3
89+
voltage /= 65535
90+
print("Wiper voltage: %.2f"%voltage)
91+
print("")
92+
sleep(1.0)
93+
94+
ds3502.wiper = 63
95+
print("Wiper set to %d"%ds3502.wiper)
96+
voltage = wiper_output.value
97+
voltage *= 3.3
98+
voltage /= 65535
99+
print("Wiper voltage: %.2f"%voltage)
100+
print("")
101+
sleep(1.0)
76102
77103
78104
Contributing

examples/ds3502_blinka_simpletest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from time import sleep
2+
import board
3+
import adafruit_ds3502
4+
5+
i2c = board.I2C()
6+
ds3502 = adafruit_ds3502.DS3502(i2c)
7+
8+
# As this code runs, measure the voltage between ground and the RW (wiper) pin
9+
# with a multimeter. You should see the voltage change with each print statement.
10+
while True:
11+
ds3502.wiper = 127
12+
print("Wiper value set to 127")
13+
sleep(5.0)
14+
15+
ds3502.wiper = 0
16+
print("Wiper value set to 0")
17+
sleep(5.0)
18+
19+
ds3502.wiper = 63
20+
print("Wiper value set to 63")
21+
sleep(5.0)

examples/ds3502_set_default.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from time import sleep
2+
import board
3+
import adafruit_ds3502
4+
from analogio import AnalogIn
5+
6+
i2c = board.I2C()
7+
ds3502 = adafruit_ds3502.DS3502(i2c)
8+
wiper_output = AnalogIn(board.A0)
9+
10+
ds3502.wiper = 127
11+
print("Wiper value: %d"%wiper_output.value)
12+
sleep(1.0)
13+
14+
ds3502.wiper = 0
15+
print("Wiper value: %d"%wiper_output.value)

examples/ds3502_simpletest.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,40 @@
33
import adafruit_ds3502
44
from analogio import AnalogIn
55

6+
####### NOTE ################
7+
# this example will not work with Blinka/rasberry Pi due to the lack of analog pins.
8+
# Blinka and Raspberry Pi users should run the "ds3502_blinka_simpletest.py" example
9+
610
i2c = board.I2C()
711
ds3502 = adafruit_ds3502.DS3502(i2c)
812
wiper_output = AnalogIn(board.A0)
913

10-
ds3502.wiper = 127
11-
print("Wiper value: %d"%wiper_output.value)
12-
sleep(1.0)
14+
while True:
15+
16+
ds3502.wiper = 127
17+
print("Wiper set to %d"%ds3502.wiper)
18+
voltage = wiper_output.value
19+
voltage *= 3.3
20+
voltage /= 65535
21+
print("Wiper voltage: %.2f"%voltage)
22+
print("")
23+
sleep(1.0)
24+
25+
ds3502.wiper = 0
26+
print("Wiper set to %d"%ds3502.wiper)
27+
voltage = wiper_output.value
28+
voltage *= 3.3
29+
voltage /= 65535
30+
print("Wiper voltage: %.2f"%voltage)
31+
print("")
32+
sleep(1.0)
1333

14-
ds3502.wiper = 0
15-
print("Wiper value: %d"%wiper_output.value)
34+
ds3502.wiper = 63
35+
print("Wiper set to %d"%ds3502.wiper)
36+
voltage = wiper_output.value
37+
voltage *= 3.3
38+
voltage /= 65535
39+
print("Wiper voltage: %.2f"%voltage)
40+
print("")
41+
sleep(1.0)
42+

0 commit comments

Comments
 (0)