From ac011c4a43d82f15f08256769f042126120895c2 Mon Sep 17 00:00:00 2001 From: Omry Nachman Date: Wed, 1 Apr 2015 12:53:25 +0300 Subject: [PATCH] Bug fix: signed differential sample values are ignored in ADS1015 (12 bit) --- 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..eb58087d 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 + # (Take signed values into account as well) + if val >> 11: + val = val - 0xfff + return val*pga/2048.0 else: # Return a mV value for the ADS1115 # (Take signed values into account as well)