16340 Module

The following products are supported:

Module 16340

Module16340 is a power monitor battery module. It uses the onboard INA226 sensor on the Module I2C bus to read bus voltage, shunt voltage, current, and power.

UiFlow2 Example

Read power monitor values

This example creates a Module16340 object and reads voltage, current, and power values from the onboard INA226 sensor.

Open the base16340_cores3_example.m5f2 project in UiFlow2.

UiFlow2 Code Block:

init.png

Example output:

None

MicroPython Example

Read power monitor values

This example prints the bus voltage, shunt voltage, current, and power values.

MicroPython Code Block:

 1# SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8from module import Module16340
 9import time
10
11
12title0 = None
13label0 = None
14label1 = None
15label2 = None
16label3 = None
17module16340_0 = None
18
19
20def setup():
21    global title0, label0, label1, label2, label3, module16340_0
22
23    M5.begin()
24    Widgets.setRotation(1)
25    Widgets.fillScreen(0x222222)
26    title0 = Widgets.Title(
27        "Base16340 CoreS3 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.Montserrat18
28    )
29    label0 = Widgets.Label("label0", 2, 50, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.Montserrat18)
30    label1 = Widgets.Label("label1", 2, 94, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.Montserrat18)
31    label2 = Widgets.Label("label2", 2, 138, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.Montserrat18)
32    label3 = Widgets.Label("label3", 2, 176, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.Montserrat18)
33
34    module16340_0 = Module16340(address=0x45)
35
36
37def loop():
38    global title0, label0, label1, label2, label3, module16340_0
39    M5.update()
40    time.sleep(1)
41    label0.setText(str((str("Shunt Voltage:") + str((module16340_0.read_shunt_voltage())))))
42    label1.setText(str((str("Bus Voltage:") + str((module16340_0.read_bus_voltage())))))
43    label2.setText(str((str("Current:") + str((module16340_0.read_current())))))
44    label3.setText(str((str("Power:") + str((module16340_0.read_power())))))
45
46
47if __name__ == "__main__":
48    try:
49        setup()
50        while True:
51            loop()
52    except (Exception, KeyboardInterrupt) as e:
53        try:
54            from utility import print_error_msg
55
56            print_error_msg(e)
57        except ImportError:
58            print("please update to latest firmware")

Example output:

None

API

Module16340

class module.module16340.Module16340(address=69)

Bases: INA226

Create an Module16340 object.

UiFlow2 Code Block:

init.png

MicroPython Code Block:

from module import Module16340

module16340 = Module16340()
calibrate(max_expected_current=0, cal_value=None)

Calibrate the INA226.

Parameters:
  • max_expected_current (float) – The maximum expected current in Amperes.

  • cal_value (int) – The calibration value to use. If None, it will be calculated based on the maximum expected current and the shunt resistor value.

MicroPython Code Block:

ina226_0.calibrate(10)

ina226_0.calibrate(cal_value=0xC80)
read_bus_voltage()

Read the bus voltage in Volts.

Returns:

The bus voltage in Volts.

Return type:

float

UiFlow2 Code Block:

read_bus_voltage.png

MicroPython Code Block:

ina226_0.read_bus_voltage()
read_current()

Read the current in Amperes.

Returns:

The current in Amperes.

Return type:

float

UiFlow2 Code Block:

read_current.png

MicroPython Code Block:

ina226_0.read_current()
read_power()

Read the power in Watts.

Returns:

The power in Watts.

Return type:

float

UiFlow2 Code Block:

read_power.png

MicroPython Code Block:

ina226_0.read_power()
read_shunt_voltage()

Read the shunt voltage in Volts.

Returns:

The shunt voltage in Volts.

Return type:

float

UiFlow2 Code Block:

read_shunt_voltage.png

MicroPython Code Block:

ina226_0.read_shunt_voltage()