-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathread_volts_example.py
executable file
·41 lines (24 loc) · 1.08 KB
/
read_volts_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import ads1256 # import this lib
gain = 1 # ADC's Gain parameter
sps = 25 # ADC's SPS parameter
# Create the first list. It will receive ADC's absolute values
AllChannelValuesVolts = [0,0,0,0,0,0,0,0]
# Create the second list. It will received absolute values converted to Volts
AllChannelValues = [0,0,0,0,0,0,0,0]
# Initialize the ADC using the parameters
ads1256.start(str(gain),str(sps))
# Fill the first list with all the ADC's absolute channel values
AllChannelValues = ads1256.read_all_channels()
for i in range(0, 8):
# Fill the second list with the voltage values
AllChannelValuesVolts[i] = (((AllChannelValues[i] * 100) /167.0)/int(gain))/1000000.0
for i in range(0, 8):
# Print all the absolute values
print AllChannelValues[i]
# Print a new line
print ("\n");
for i in range(0, 8):
# Print all the Volts values converted from the absolute values
print AllChannelValuesVolts[i]
# Stop the use of the ADC
ads1256.stop()