Skip to content

Interacting With The INA219

Pymata_rh provides a separate API method call to retrieve each of the measurements that an INA219 can perform.

The following API methods to allow you to control and monitor the INA219:

  • ina_initialize
  • ina_read_bus_voltage
  • ina_read_bus_voltage_last
  • ina_read_bus_current
  • ina_read_bus_current_last
  • ina_read_power
  • ina_read_power_last
  • ina_read_shunt_voltage
  • ina_read_shunt_voltage_last
  • ina_read_supply_voltage
  • ina_read_supply_voltage_last

Each of the methods that end in _last retrieves the last data values read from the device. These methods do not do a physical read of the INA219.

All the other methods that do not end with _last perform a physical read of the device.

ina_initialize

def ina_initialize(self, address=64, shunt_ohms=0.2, 
                   max_expected_amps=0.2, callback=None)

    This method instantiates an INA219 object.

    :param address: The i2c address of the device

    :param shunt_ohms: The shunt resistance in ohms

    :param max_expected_amps: The maximum expected current in amps

    :param callback: Callback method that will INA219 callbacks

    Note: There is a single callback shared by all INA methods.

This method must be called before calling any of the other INA219 methods. Typically, you can accept all of the default values. If you wish to have your application automatically notified of any INA219 reads, you must specify a callback function.

Using a callback is optional but highly recommended. A callback function ensures that your application receives the latest INA219 data automatically without any polling interaction. If you do not specify a callback method, you may still poll for the latest reported values using the INA219 methods that end in _last

The data frame returned as a result of any of the reads is described in the specific read methods.

For a discussion on callbacks and polling, please refer to this section of the document.

Example:

ina_test.py

ina_read_bus_voltage

def ina_read_bus_voltage(self):
        """
        This method well execute a read of the bus voltage.
        If a callback was specified in ina_initialize, then
        a callback frame is specified as follows:

        [pin_type=0x11, device_i2c_address, read_type=0 (bus voltage), 
         voltage, units='V', timestamp]

        The data is also saved to be retrieved by ina_read_supply_voltage_last()

        :return: callback is called and storage updated with latest value
        """

Example:

ina_test.py

ina_read_bus_voltage_last


def ina_read_bus_voltage_last(self):
    """
    Retrieve last bus voltage value read from the ina_219.

    :return: list: [pin_type=0x11, device_i2c_address,
                   read_type=0 (bus voltage), units='V', timestamp]
    """
    return self.ina_last_value_bus_voltage

Example:

ina_test.py

ina_read_bus_current

def ina_read_bus_current(self):
        """
        This method well execute a read of the bus current.
        If a callback was specified in ina_initialize, then
        a callback frame is specified as follows:

        [pin_type=0x11, device_i2c_address, read_type=1 (bus current), 
         current, units='mA', timestamp]

        The data is also saved to be retrieved by ina_read_bus_current_last()

        :return: callback is called and storage updated with latest value
        """

Example:

ina_test.py

ina_read_bus_current_last

 def ina_read_bus_current_last(self):
        """
        Retrieve last supply voltage value read from the ina_219.

        :return: list:
        [pin_type=0x11, device_i2c_address, read_type=1 (bus voltage),
         voltage, units='mA', timestamp]
        """

Example:

ina_test.py

def ina_read_supply_voltage(self):
        """
        This method well execute a read of the supply voltage.
        If a callback was specified in ina_initialize, then
        a callback frame is specified as follows:

        [pin_type=0x11, device_i2c_address, read_type=2 (supply voltage),
         supply voltage, unit='V',timestamp]

        The data is also saved to be retrieved by ina_read_supply_voltage_last()

        :return: callback is called and storage updated with latest value
        """

Example:

ina_test.py

ina_read_supply_voltage_last


def ina_read_supply_voltage_last(self):
        """
        This method retrieves the last supply voltage read.
        :return: list:

        [pin_type=0x11, device_i2c_address, read_type=2 (supply voltage),
         voltage, units='V', timestamp]
        """

Example:

ina_test.py

ina_read_shunt_voltage


def ina_read_shunt_voltage(self):
        """
        This method well execute a read of the shunt voltage.
        If a callback was specified in ina_initialize, then
        a callback frame is specified as follows:

        [pin_type=0x11, device_i2c_address, read_type=3 (supply voltage), 
         shunt voltage, units='mV', timestamp]

        The data is also saved to be retrieved by ina_read_shunt_voltage_last()

        :return: callback is called and storage updated with latest value
        """

Example:

ina_test.py

ina_read_shunt_voltage_last


def ina_read_shunt_voltage_last(self):
        """
        This method well execute a read of the shunt voltage.
        If a callback was specified in ina_initialize, then
        a callback frame is specified as follows:

        :return: list:
        [pin_type=0x11, device_i2c_address, read_type=3 (shunt voltage), shunt voltage, units='mV', timestamp]
        """

Example:

ina_test.py

ina_read_power

def ina_read_power(self):
        """
        This method well execute a read of the power.
        If a callback was specified in ina_initialize, then
        a callback frame is specified as follows:

        [pin_type=0x11, device_i2c_address, read_type=4 (power), 
         power, units='mW', timestamp]

        The data is also saved to be retrieved by ina_read_power_last()

        :return: callback is called and storage updated with latest value
        """

Example:

ina_test.py



## ina_read_power_last
def ina_read_power_last(self):
        """
        This method retrieves the last read power value.
        :return: list:

                [pin_type=0x11, device_i2c_address, read_type=4 (power), 
                 power, units='mW', timestamp]
        """

Example:

ina_test.py

ina_sleep

def ina_sleep(self):
        """
        Place the ina219 into sleep mode.
        """

Example:

ina_test.py

ina_wake

def ina_wake(self):
        """
        Wake the ina219 from sleep model
        """

Example:

ina_test.py



Copyright (C) 2020 Alan Yorinks. All Rights Reserved.