From 008d77eafb9d0ab493ea490ed238cad246d90762 Mon Sep 17 00:00:00 2001 From: daliaga86 Date: Mon, 15 Sep 2014 17:13:35 -0400 Subject: [PATCH] Update Adafruit_ADS1x15.py Line 293 take into account negative voltages for ads_1015. Current state only does that for ads_1115 even though 1015 is able to read differential voltages --- Adafruit_ADS1x15/Adafruit_ADS1x15.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Adafruit_ADS1x15/Adafruit_ADS1x15.py b/Adafruit_ADS1x15/Adafruit_ADS1x15.py index 32141f4b..b9bcbf60 100644 --- a/Adafruit_ADS1x15/Adafruit_ADS1x15.py +++ b/Adafruit_ADS1x15/Adafruit_ADS1x15.py @@ -289,7 +289,11 @@ def readADCDifferential(self, chP=0, chN=1, pga=6144, sps=250): result = self.i2c.readList(self.__ADS1015_REG_POINTER_CONVERT, 2) if (self.ic == self.__IC_ADS1015): # Shift right 4 bits for the 12-bit ADS1015 and convert to mV - return ( ((result[0] << 8) | (result[1] & 0xFF)) >> 4 )*pga/2048.0 + val=( ((result[0] << 8) | (result[1] & 0xFF)) >> 4 ); + if val > 2047.0: + return (val - 4096.0)*pga/2048.0 + else: return val*pga/2048.0 + else: # Return a mV value for the ADS1115 # (Take signed values into account as well)