Skip to content

Commit 066b5fb

Browse files
authored
Merge pull request #13 from dgriswo/main
Add thermistor support
2 parents 7df9ebe + 7b914db commit 066b5fb

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

adafruit_lc709203f.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
LC709203F_CMD_INITRSOC = const(0x07)
4242
LC709203F_CMD_CELLVOLTAGE = const(0x09)
4343
LC709203F_CMD_CELLITE = const(0x0F)
44+
LC709203F_CMD_CELLTEMPERATURE = const(0x08)
45+
LC709203F_CMD_THERMISTORB = const(0x06)
46+
LC709203F_CMD_STATUSBIT = const(0x16)
4447

4548

4649
class CV:
@@ -121,6 +124,18 @@ def cell_percent(self):
121124
"""Returns percentage of cell capacity"""
122125
return self._read_word(LC709203F_CMD_CELLITE) / 10
123126

127+
@property
128+
def cell_temperature(self):
129+
"""Returns the temperature of the cell"""
130+
return self._read_word(LC709203F_CMD_CELLTEMPERATURE) / 10 - 273.15
131+
132+
@cell_temperature.setter
133+
def cell_temperature(self, value):
134+
"""Sets the temperature in the LC709203F"""
135+
if self.thermistor_enable:
136+
raise AttributeError("temperature can only be set in i2c mode")
137+
self._write_word(LC709203F_CMD_CELLTEMPERATURE, int(value + 273.15) * 10)
138+
124139
@property
125140
def ic_version(self):
126141
"""Returns read-only chip version"""
@@ -159,6 +174,28 @@ def pack_size(self, size):
159174
raise AttributeError("pack_size must be a PackSize")
160175
self._write_word(LC709203F_CMD_APA, size)
161176

177+
@property
178+
def thermistor_bconstant(self):
179+
"""Returns the thermistor B-constant"""
180+
return self._read_word(LC709203F_CMD_THERMISTORB)
181+
182+
@thermistor_bconstant.setter
183+
def thermistor_bconstant(self, bconstant):
184+
"""Sets the thermistor B-constant"""
185+
self._write_word(LC709203F_CMD_THERMISTORB, bconstant)
186+
187+
@property
188+
def thermistor_enable(self):
189+
"""Returns the current temperature source"""
190+
return self._read_word(LC709203F_CMD_STATUSBIT)
191+
192+
@thermistor_enable.setter
193+
def thermistor_enable(self, status):
194+
"""Sets the temperature source to Tsense"""
195+
if not status in (True, False):
196+
raise AttributeError("thermistor_enable must be True or False")
197+
self._write_word(LC709203F_CMD_STATUSBIT, status)
198+
162199
# pylint: disable=no-self-use
163200
def _generate_crc(self, data):
164201
"""8-bit CRC algorithm for checking data"""

examples/lc709203f_thermistortest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SPDX-FileCopyrightText: 2021 Daniel Griswold
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import time
6+
import board
7+
from adafruit_lc709203f import LC709203F
8+
9+
print("LC709203F thermistor test")
10+
print("Make sure a thermistor is connected to the board!")
11+
12+
sensor = LC709203F(board.I2C())
13+
14+
# check your NTC thermistor datasheet for the appropriate B-Constant
15+
sensor.thermistor_bconstant = 3950
16+
sensor.thermistor_enable = True
17+
18+
print("IC version:", hex(sensor.ic_version))
19+
while True:
20+
print("Cell Temperature: %0.2f C" % (sensor.cell_temperature))
21+
time.sleep(1)

0 commit comments

Comments
 (0)