Skip to content

Commit 5ca6809

Browse files
committed
Merge pull request adafruit#115 from omryn/master
Bug fix: signed differential sample values are ignored in ADS1015 (12 bi...
2 parents 0c1bb48 + ac011c4 commit 5ca6809

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Adafruit_ADS1x15/Adafruit_ADS1x15.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,11 @@ def readADCDifferential(self, chP=0, chN=1, pga=6144, sps=250):
289289
result = self.i2c.readList(self.__ADS1015_REG_POINTER_CONVERT, 2)
290290
if (self.ic == self.__IC_ADS1015):
291291
# Shift right 4 bits for the 12-bit ADS1015 and convert to mV
292-
return ( ((result[0] << 8) | (result[1] & 0xFF)) >> 4 )*pga/2048.0
292+
val = ((result[0] << 8) | (result[1] & 0xFF)) >> 4
293+
# (Take signed values into account as well)
294+
if val >> 11:
295+
val = val - 0xfff
296+
return val*pga/2048.0
293297
else:
294298
# Return a mV value for the ADS1115
295299
# (Take signed values into account as well)

0 commit comments

Comments
 (0)