code.py
 1  # SPDX-FileCopyrightText: 2021 Tim C for Adafruit Industries
 2  # SPDX-License-Identifier: MIT
 3  """
 4  CircuitPython simple sensor data display demo using LC709203 battery monitor and TFT display
 5  """
 6  import time
 7  import board
 8  import terminalio
 9  from displayio import Group
10  from adafruit_display_text import bitmap_label
11  from adafruit_lc709203f import LC709203F
12  
13  text_area = bitmap_label.Label(terminalio.FONT, scale=2)
14  text_area.anchor_point = (0.5, 0.5)
15  text_area.anchored_position = (board.DISPLAY.width // 2, board.DISPLAY.height // 2)
16  
17  main_group = Group()
18  
19  main_group.append(text_area)
20  
21  print("LC709203F test")
22  print("Make sure LiPoly battery is plugged into the board!")
23  
24  sensor = LC709203F(board.I2C())
25  
26  print("IC version:", hex(sensor.ic_version))
27  
28  board.DISPLAY.show(main_group)
29  
30  while True:
31      text_area.text = "Battery:\n{:.1f} Volts \n{}%".format(sensor.cell_voltage, sensor.cell_percent)
32      time.sleep(1)