diff --git a/Adafruit_ADS1x15/output_voltage.py b/Adafruit_ADS1x15/output_voltage.py new file mode 100644 index 00000000..0d13d5b1 --- /dev/null +++ b/Adafruit_ADS1x15/output_voltage.py @@ -0,0 +1,30 @@ +#!/usr/bin/python + +import time, signal, sys +from Adafruit_ADS1x15 import ADS1x15 + +def signal_handler(signal, frame): + print '\nprogram terminated by user' + sys.exit(0) +signal.signal(signal.SIGINT, signal_handler) +print '>>Press Ctrl+C to exit<<\n' + +ADS1015 = 0x00 # 12-bit ADC +ADS1115 = 0x01 # 16-bit ADC + +# Initialise the ADC using the default mode (use default I2C address) +# Set this to ADS1015 or ADS1115 depending on the ADC you are using! +adc = ADS1x15(ic=ADS1015) + +while True: + + # Read channels 2 and 3 in single-ended mode, at +/-4.096V and 250sps + volts0 = adc.readADCSingleEnded(0, 4096, 250)/1000.0 + volts1 = adc.readADCSingleEnded(1, 4096, 250)/1000.0 + + # Now do a differential reading of channels 2 and 3 + voltsdiff = adc.readADCDifferential01(4096, 250)/1000.0 + + # Display the two different reading for comparison purposes + print "%.4f %.4f %.4f %.4f" % (volts0, volts1, volts1-volts0, -voltsdiff) + time.sleep(2)