I have edited the title of this thread to be more explicit.
In older posts I have recommended to add these settings:
But after a deeper analysis of the code I can se that those pre-configured "calibration" settings seem just the most usual or expected uses of the module but there could be many more possible uses.
Those pre-configured uses are the combination of different values of these constants:
bus_voltage_range
gain
bus_adc_resolution
shunt_adc_resolution
mode
We could expose these constants and its fixed values as "sensor settings" in openplotter but we would also need to expose these private variables:
_current_lsb
_cal_value
_power_lsb
and here comes the problem because calculating these private variables is really complex for normal users. Here is an example of calculating them for "set_calibration_16V_5A"
We could do that but we would need a good documentation or at least values for all these variables for our own pre-configured settings.
This is the result of the html tool to calculate them in your example:
![[Image: attachment.php?aid=1961]](https://forum.openmarine.net/attachment.php?aid=1961)
but that result is for arduino and we should make sure those settings are the same as the python settings:
_cal_value
_current_lsb
_power_lsb
bus_voltage_range
gain
bus_adc_resolution
shunt_adc_resolution
mode
Does this all make sense to you?
In older posts I have recommended to add these settings:
Quote:set_calibration_32V_2A
"""Configures to INA219 to be able to measure up to 32V and 2A of current. Counter
overflow occurs at 3.2A.
.. note:: These calculations assume a 0.1 shunt ohm resistor is present
"""
set_calibration_32V_1A
"""Configures to INA219 to be able to measure up to 32V and 1A of current. Counter overflow
occurs at 1.3A.
.. note:: These calculations assume a 0.1 ohm shunt resistor is present"""
set_calibration_16V_400mA
"""Configures to INA219 to be able to measure up to 16V and 400mA of current. Counter
overflow occurs at 1.6A.
.. note:: These calculations assume a 0.1 ohm shunt resistor is present"""
set_calibration_16V_5A
"""Configures to INA219 to be able to measure up to 16V and 5000mA of current. Counter
overflow occurs at 8.0A.
.. note:: These calculations assume a 0.02 ohm shunt resistor is present"""
But after a deeper analysis of the code I can se that those pre-configured "calibration" settings seem just the most usual or expected uses of the module but there could be many more possible uses.
Those pre-configured uses are the combination of different values of these constants:
bus_voltage_range
gain
bus_adc_resolution
shunt_adc_resolution
mode
We could expose these constants and its fixed values as "sensor settings" in openplotter but we would also need to expose these private variables:
_current_lsb
_cal_value
_power_lsb
and here comes the problem because calculating these private variables is really complex for normal users. Here is an example of calculating them for "set_calibration_16V_5A"
Quote: """Configures to INA219 to be able to measure up to 16V and 5000mA of current. Counter
overflow occurs at 8.0A.
.. note:: These calculations assume a 0.02 ohm shunt resistor is present"""
# Calibration which uses the highest precision for
# current measurement (0.1mA), at the expense of
# only supporting 16V at 5000mA max.
# VBUS_MAX = 16V
# VSHUNT_MAX = 0.16 (Assumes Gain 3, 160mV)
# RSHUNT = 0.02 (Resistor value in ohms)
# 1. Determine max possible current
# MaxPossible_I = VSHUNT_MAX / RSHUNT
# MaxPossible_I = 8.0A
# 2. Determine max expected current
# MaxExpected_I = 5.0A
# 3. Calculate possible range of LSBs (Min = 15-bit, Max = 12-bit)
# MinimumLSB = MaxExpected_I/32767
# MinimumLSB = 0.0001529 (uA per bit)
# MaximumLSB = MaxExpected_I/4096
# MaximumLSB = 0.0012207 (uA per bit)
# 4. Choose an LSB between the min and max values
# (Preferrably a roundish number close to MinLSB)
# CurrentLSB = 0.00016 (uA per bit)
self._current_lsb = 0.1524 # in milliamps
# 5. Compute the calibration register
# Cal = trunc (0.04096 / (Current_LSB * RSHUNT))
# Cal = 13434 (0x347a)
self._cal_value = 13434
# 6. Calculate the power LSB
# PowerLSB = 20 * CurrentLSB
# PowerLSB = 0.003 (3.048mW per bit)
self._power_lsb = 0.003048
We could do that but we would need a good documentation or at least values for all these variables for our own pre-configured settings.
This is the result of the html tool to calculate them in your example:
but that result is for arduino and we should make sure those settings are the same as the python settings:
_cal_value
_current_lsb
_power_lsb
bus_voltage_range
gain
bus_adc_resolution
shunt_adc_resolution
mode
Does this all make sense to you?