View difference between Paste ID: GTnhUSuC and KQUGLdAb
SHOW: | | - or go back to the newest paste.
1
#!/usr/bin/python
2
3
import time #, signal, sys
4
import traceback
5
from Adafruit_ADS1x15 import ADS1x15
6
7
#def signal_handler(signal, frame):
8
#        print 'You pressed Ctrl+C!'
9
#        sys.exit(0)
10
#signal.signal(signal.SIGINT, signal_handler)
11
12
try:
13
        ADS1015 = 0x00  # 12-bit ADC
14
        ADS1115 = 0x01  # 16-bit ADC
15
        adc = ADS1x15(ic=ADS1115)
16
17
        # read channel 0 in single-ended mode, +/- 4.096V, 250 sps:
18
        volts = adc.readADCSingleEnded(0, 4096, 250) / 1000
19
20
        print "%.6f" % (volts)
21
except:
22-
         print "*** ERROR ***"
22+
         formatted_lines = traceback.format_exc().splitlines()
23-
         print repr(traceback.format_exception(exc_type, exc_value,
23+
         print "*** ERROR: " + formatted_lines[-1] + " ***"