From cc5a97ffa4d6022e9c6353c149af78e2509e7fcf Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Mon, 11 Jan 2016 12:41:10 +0100 Subject: [PATCH] Simple temperature reading --- i2c/ds1621.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/i2c/ds1621.py b/i2c/ds1621.py index 3f726cc..9ec0242 100755 --- a/i2c/ds1621.py +++ b/i2c/ds1621.py @@ -1,3 +1,31 @@ #!/usr/bin/env python -print 'nothing yet' +import smbus + +bus = smbus.SMBus(1) +address = 0x49 + +print 'Start: ' + hex(bus.read_byte_data(address, 0xEE)) + +tempFull = bus.read_byte_data(address, 0xAA) +print 'Temp (1 deg): ' + str(tempFull) + +halfDegreeTemp = bus.read_word_data(address, 0xAA) +tempHalf = halfDegreeTemp & 0x00FF +if halfDegreeTemp & 0xFF00: + tempHalf += 0.5 +print 'Temp (0.5 deg): ' + str(tempHalf) + +counter = bus.read_word_data(address, 0xA8) +print 'Counter: ' + str(counter) + +slope = bus.read_word_data(address, 0xA9) +print 'Slope: ' + str(slope) + +tempHi = tempFull - 0.25 + float(slope - counter) / slope +print 'Temp (hi-res): ' + str(tempHi) + +print 'End: ' + hex(bus.read_byte_data(address, 0x22)) + + +