{
  "id": "howmanyoliversarethere/micropython-bq27220",
  "name": "micropython-bq27220",
  "prettyName": "micropython-bq27220",
  "description": "MicroPython driver for the TI BQ27220 single-cell fuel gauge",
  "version": "",
  "author": "howmanyoliversarethere",
  "license": "MIT",
  "tags": [],
  "status": "VALID",
  "official": false,
  "source": "https://github.com/howmanyoliversarethere/micropython-bq27220",
  "updatedAt": "2026-10-28T08:38:28.344Z",
  "page": "https://checkmim.com/packages/howmanyoliversarethere+micropython-bq27220",
  "createdAt": "2026-10-28T08:38:26.664Z",
  "submittedBy": "oliverr",
  "install": {
    "mpremote": "mpremote mip install github:howmanyoliversarethere/micropython-bq27220",
    "mip": "import mip; mip.install(\"github:howmanyoliversarethere/micropython-bq27220\")"
  },
  "readme": "# BQ27220 fuel gauge\n\nA MicroPython driver for the Texas Instruments **BQ27220** single-cell\nLi-ion fuel gauge: state of charge, voltage, current, capacity, time to\nempty/full, temperature and status flags, over I2C.\n\nCopy `bq27220.py` onto your board, or install it with `mip`:\n\n```python\nimport mip\nmip.install(\"github:HowManyOliversAreThere/micropython-bq27220\")\n```\n\n## Usage\n\n```python\nfrom machine import I2C, Pin\nimport bq27220\n\ni2c = I2C(0, sda=Pin(19), scl=Pin(20), freq=400_000)\ngauge = bq27220.BQ27220(i2c)\n\nprint(gauge.state_of_charge(), \"%\")\nprint(gauge.voltage(), \"mV\", gauge.current(), \"mA\")   # current > 0 while charging\nprint(gauge.time_to_empty(), \"min to empty\")           # None unless discharging\nif gauge.status() & bq27220.STATUS_SYSDWN:\n    print(\"battery critically low\")\n\ngauge.set_capacity(1000)  # configure for a 1000 mAh cell (only writes if it differs)\n```\n\n## Notes\n\n- The address is fixed at 0x55. By default the constructor reads the\n  device number and raises `OSError` unless it's 0x0220.\n- The gauge's figures are only as good as its configuration. The data\n  memory is RAM: it's back to TI's defaults (a 3000 mAh cell) whenever\n  the gauge loses power, so call `set_capacity()` at every start-up. It\n  sets the design capacity and the starting full-charge capacity, which\n  the gauge then learns over charge cycles. Writing takes about 2 s.\n- `write_data_memory()` and `read_data_memory()` reach any other\n  setting, by address (values big-endian). They unseal with TI's default\n  keys, and seal again after if it was sealed. The rest of the CEDV\n  profile stays generic; for the best accuracy, characterise your cell\n  with TI's tools. The addresses and update sequence follow\n  [Flipper Zero's driver](https://github.com/flipperdevices/flipperzero-firmware/tree/dev/lib/drivers),\n  since the technical reference manual (SLUUBD4) gets the procedure\n  wrong.\n- Current, voltage and so on update about once a second.\n\n## License\n\nMIT - see [LICENSE](LICENSE).\n"
}