-
Notifications
You must be signed in to change notification settings - Fork 0
/
read-adc-voltage.py
46 lines (34 loc) · 1.26 KB
/
read-adc-voltage.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
42
43
44
45
46
#!/usr/bin/python
from ABE_ADCPi import ADCPi
from ABE_helpers import ABEHelpers
import time
import os
"""
================================================
ABElectronics ADC Pi 8-Channel ADC demo
Version 1.0 Created 09/05/2014
Version 1.1 16/11/2014 updated code and functions to PEP8 format
Requires python smbus to be installed
run with: python demo-read_voltage.py
================================================
Initialise the ADC device using the default addresses and sample rate,
change this value if you have changed the address selection jumpers
Sample rate can be 12,14, 16 or 18
"""
i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc = ADCPi(bus, 0x68, 0x69, 12)
while (True):
# clear the console
os.system('clear')
# read from adc channels and print to screen
print ("Channel 1: %02f" % adc.read_voltage(1))
print ("Channel 2: %02f" % adc.read_voltage(2))
print ("Channel 3: %02f" % adc.read_voltage(3))
print ("Channel 4: %02f" % adc.read_voltage(4))
print ("Channel 5: %02f" % adc.read_voltage(5))
print ("Channel 6: %02f" % adc.read_voltage(6))
print ("Channel 7: %02f" % adc.read_voltage(7))
print ("Channel 8: %02f" % adc.read_voltage(8))
# wait 0.5 seconds before reading the pins again
time.sleep(0.5)