Hi Hodgy
Unfortunately we do not have the device here to test it.
But looking into your library, I can see that the default i²c address (that is used if you do not set the address in the device configuration (parameters)) is 0x41 (see body of Adafruit_CurrentSense, line 6). Did you verify this with i2cdetect?
What I saw in the Adafruit example code is that the registers are 16bit long:
Code:
uint16_t config = INA219_CONFIG_BVOLTAGERANGE_32V |
INA219_CONFIG_GAIN_8_320MV |
INA219_CONFIG_BADCRES_12BIT |
INA219_CONFIG_SADCRES_12BIT_1S_532US |
INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS;
wireWriteRegister(INA219_REG_CONFIG, config);
In your lib you used the write8 method.
Currently, there is no ready-to-use write16 method, but it is easy to program in your own lib:
Code:
METHOD write16 : BOOL
VAR_INPUT
usiRegister: USINT; (* register to write *)
uiValue: UINT; (* value *)
END_VAR
VAR
Buffer: ARRAY[0..2] OF BYTE;
END_VAR
---
Buffer[0] := usiRegister;
Buffer[1] := UINT_TO_USINT(SHR(uiValue, 8));
Buffer[2] := UINT_TO_USINT(uiValue AND 16#FF);
Write16 := DINT_TO_BOOL(Write(ADR(Buffer), 3));
I guess that this should solve the problem!
Instead of the BeforeWriteOutputs method you should use the AfterReadInputs method, as this device is an input device. You can compare to the SRF02, which is also a pure sensor which is similar to yours
"c:\Users\<Username>\CODESYS Control for Raspberry PI\1.1.0.0\I2C_SRF02.library"
BR
Edwin