### Battery Calibration

When you put a new set of batteries into the uConsole, the power controller needs to "learn" the capacity of the new batteries. This process is known as "calibration". Until you calibrate the power controller, it won't know the real capacity of your batteries, and may report 65% when they're empty, or (as mine are doing right now) 34% when they've been charging overnight and are presumably full.

To calibrate the power controller for a new set of batteries ...

* If you have a power tester (see [below](#power-testers)), plug it in between the power cable and the uConsole so you can monitor how much power the is being consumed, rather than having to trust the possibly-faulty numbers from the uConsole's charging circuitry.

* If the uConsole is configured with any "auto shutdown" or "battery saver" featires, disable them. We're going to be deliberately running the batteries down to empty.

* Plug in the charging cable and wait until the batteries are full.

    If you're using a power tester, you should see the power consumption fall at some point. My own uConsole went from 9W to 2-3W when the batteries were full.

    **You can watch the state of the battery** using `upower`, which is normally included with the Raspberry Pi images.

    ```
    BAT=$( upower -e | grep 'apx20x_battery' )
    watch -n5 "upower -i $BAT | egrep '(state|percentage):'"
    ```

    You can leave the `watch` command running in a terminal window while performing the steps below.

* Tell the power controller to start the calibration process.  In a terminal window ...
    ```
    echo 1 | sudo tee /sys/class/power_supply/axp20x-battery/calibrate
    ```

* Unplug the power cable, so the uConsole is running on batteries.

* Let the unit run until the battery dies. This can take a while.

    If you'd rather not wait so long, you can do things on the system to increase it's power consumption, such as ...

    * Exercise the CPU. I ran the following command in a terminal window to keep the CPU busy:
        ```
        while true ; do dd status=none bs=1G count=1 if=/dev/urandom | sha256sum ; done | cat -n
        ```

        This command makes the kernel *generate* 1 GB of random numbers, calculates the SHA256 checksum of those numbers, and prints the result, over and over until the system dies. (The `cat -n` at the end puts a count in front of each checksum, in case you're curious how many GB of random data have been processed.)

    * If you have USB accessories that draw power, make sure they're plugged in and being used. As an example, if you have a USB disk mounted as `/mnt/disk`, you can exercise the disk by continually reading every file from the disk, using a command like this:
        ```
        while true ; do date ; find . -xdev -type f -exec cat {} > /dev/null \; ; done | cat -n
        ```

* When the uConsole dies, plug the power cable in, but do not power it on.

* Wait until the batteries are full. If you're using a power tester, you'll see the power consumption drop to zero when this happens. If not, all I can suggest is to let the unit charge overnight.

* When you power the unit on, it should have an accurate picture of the batteries' true capacity, and the percentages should be accurate.


### Batteries

* &#x2753; Amazon - [Authentic Samsung30Q, 3.7V Flat Top Real 3000mAh 18650 Battery Rechargeable 30Q (4 Pack)](https://www.amazon.com/dp/B0BNLPWKXR)

    While reading about peoples' experiences with "fake" batteries, I found several web sites which recommended buying only genuine Panasonic or Samsung batteries. These are advertised as "Authentic Samsung", so I'm hoping they will last longer than two hours.

    These haven't arrived yet. Once they do, and I've had a chance to do some testing with them, I'll update this page with what I figured out.


### Power Testers

These are little gadgets that plug in between the charging cable and the uConsole, to show how much power the uConsole is drawing.

* &#x2705; Amazon - [2 Pack USB C Adapter with Digital Display, PD 240W USB-C Male to Female Connector for iPhone 15 Series, iPad, MacBook, Support Voltage, Current and Power Smart LED Display (Transparent)](https://www.amazon.com/dp/B0D7T7Q858)

    This connects between the charging cable and the uConsole. The display cycles between volts, amps, and watts every few seconds. If you have a laptop or other device which draws more power, this one says it can measure up to 240W (i.e. 5A at 48V).

* &#x2705; Amazon - [USB C Adapter, 2-Pack 100W Female to Male Extension with Power Meter Tester & Digital Display for iPad Pro, iPhone 16/15 Pro Max, MacBook Pro, Laptop (Grey)](https://www.amazon.com/dp/B0CKRQCL1T)

    This also connects between the charging cable and the uConsole. The product description says that it shows volts, amps, and watts, however I've only ever seen it show watts. It also shows a "PD" indicator when the connection was negotiated using USB-PD (seen while charging an iPad). This one says it can measure up to 100W (5A at 20V).

