From da29c8d56bd77dcc8ec6c0ee9186135454d6bb55 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Mon, 25 Jan 2016 22:52:24 +0100 Subject: [PATCH] read temperature from one i2c device and send it as string to another --- i2c/ds1621_lcd.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 i2c/ds1621_lcd.py diff --git a/i2c/ds1621_lcd.py b/i2c/ds1621_lcd.py new file mode 100755 index 0000000..5390bb7 --- /dev/null +++ b/i2c/ds1621_lcd.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import smbus +import time + +bus = smbus.SMBus(1) +address = 0x49 + +def getTemp(): + bus.read_byte_data(address, 0xEE) + tempFull = bus.read_byte_data(address, 0xAA) + counter = bus.read_word_data(address, 0xA8) + slope = bus.read_word_data(address, 0xA9) + temp = tempFull - 0.25 + float(slope - counter) / slope + bus.read_byte_data(address, 0x22) + return temp + +while True: + for c in '%9.1f' % round(getTemp(), 1) + ' C': + bus.write_byte(0x23, ord(c)) + time.sleep(1)