From 3be5c02c11ab7aa26842abc8f9a32155c167343c Mon Sep 17 00:00:00 2001 From: Zachary Stence Date: Wed, 15 Feb 2023 19:03:02 -0600 Subject: [PATCH 1/2] feat: fix battery reading for Inkplate 6 Color --- inkplate6_COLOR.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/inkplate6_COLOR.py b/inkplate6_COLOR.py index 494d518..4a989a8 100644 --- a/inkplate6_COLOR.py +++ b/inkplate6_COLOR.py @@ -106,6 +106,12 @@ def begin(self): self.SD_ENABLE = gpioPin(self._PCAL6416A, 10, modeOUTPUT) + # Battery + self.V_BAT_MOS = gpioPin(self._PCAL6416A, 9, modeOUTPUT) + self.V_BAT = ADC(Pin(35)) + self.V_BAT.atten(ADC.ATTN_11DB) + self.V_BAT.width(ADC.WIDTH_12BIT) + self.framebuf = bytearray(D_ROWS * D_COLS // 2) self.GFX = GFX( @@ -464,12 +470,18 @@ def printText(self, x, y, s, c=BLACK): @classmethod def readBattery(self): - self.VBAT_EN.value(0) + self.V_BAT_MOS.digitalWrite(1) # Probably don't need to delay since Micropython is slow, but we do it anyway time.sleep_ms(1) - value = self.VBAT.read() - self.VBAT_EN.value(1) - result = (value / 4095.0) * 1.1 * 3.548133892 * 2 + raw_value = self.V_BAT.read() + self.V_BAT_MOS.digitalWrite(0) + + # Calculate the voltage using the following formula + # 1.1V is internal ADC reference of ESP32 + # 3.548133892 is 11dB in linear scale (Analog signal is attenuated by 11dB before ESP32 ADC input) + # Multiply by 2 for voltage divider circuit + result = (raw_value / 4095.0) * 1.1 * 3.548133892 * 2 + return result @classmethod From 60b7f81749d4ed2f01738e16c97de98b635d55be Mon Sep 17 00:00:00 2001 From: Zachary Stence Date: Wed, 15 Feb 2023 19:03:17 -0600 Subject: [PATCH 2/2] feat: add battery reading example for Inkplate 6 Color --- Examples/Inkplate6COLOR/battery.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Examples/Inkplate6COLOR/battery.py diff --git a/Examples/Inkplate6COLOR/battery.py b/Examples/Inkplate6COLOR/battery.py new file mode 100644 index 0000000..e667bf0 --- /dev/null +++ b/Examples/Inkplate6COLOR/battery.py @@ -0,0 +1,13 @@ +from inkplate6_COLOR import Inkplate + +display = Inkplate() + +if __name__ == "__main__": + display.begin() + display.clearDisplay() + + battery = str(display.readBattery()) + + display.setTextSize(2) + display.printText(100, 100, "batt: " + battery + "V") + display.display()