#Thank you @sam blenny . I was looking

1 messages · Page 1 of 1 (latest)

paper crag
#

Have you tried stripping your hardware and software setup down to the bare minimum to rule out stuff like supply voltage fluctuations, EMI, ground loops, and such from being connected to your full system? For example, if you just set up CircuitPython board and the INA228 with a load resistor, does it act the same way? Does anything change if you call time.sleep(2) at the start of your code before trying to initialize the I2C bus (I ask because I've had trouble in the past with sensors getting confused due to bus voltage brownouts after startup transients).

tiny dust
#

Interestingly, someone just submitted a PR for INA237/238 (not INA228): the power register was 3 bytes, not two. But your issue may be unrelated.

#

You could try using the Arduino library in the same setup and see what you get.

bleak tulip
bleak tulip
#

Also, @paper crag I forgot to mention that I tried to play with the calibration settings with ina228.set_calibration, but this function is not available in the library. Looks like a bug.

paper crag
#

hmm... sounds like good odds there's something off with the CURRENT_LSB stuff

bleak tulip
#

Yeah... I think I will poke around in the code and compare to the data sheet to see if there are any inconsistencies with the CURRENT_LSB and CURRENT calculations. I thought it looked ok when I looked at it before, but should probably give it another go. @tiny dust noting the INA237/238 issue with the power register has me wondering...

tiny dust
#

Note print(f"Current: {ina228.current*1000:.2f} mA") so the current does look like amps, but it could be a small float.

#

I mean, we do write guides and test the code in the guides. Maybe your setup wasn't tested, or maybe there's a wiring issue.

bleak tulip
tiny dust
#

or try the Arduino lib and see if you get the same large result. If so, I suspect wiring

bleak tulip
#

ok. I have Vin+ connected to the battery (4V; highest project voltage) and Vin- to the board (load's highest potential). Perhaps I have misunderstood.

tiny dust
#

do you have an ammeter (multimeter) you could insert in the circuit to measure the current yourself?

#

is the lower left board actually working?

#

the CPB is not connected to USB. How are you getting the measurement out?

bleak tulip
#

Don't have an ammeter (that I trust). The board on the lower-left is a Pico2 on its side. It is the INA228 host.

tiny dust
#

do you have a multimeter at all?

bleak tulip
#

Yes

tiny dust
#

so it should have amps and milliamps

#

they often have a separate 10A plug

#

vin- should be going to the +V at the battery plug on the CPB, is that right?

bleak tulip
#

It does. I will give it a try. I am hoping, though, that I have understood the wiring instructions. I use a Pico2 to run the INA228, which is connected to a CPB powered by a battery. This is what is shown (poorly) in the picture.

tiny dust
#

why is the battery "-" connected to GND on the INA228

bleak tulip
#

Yes, Vin- goes to the +V battery plug on the CPB.

tiny dust
#

it should not be, I think there should be nothing connected to the GND pin on the INA228 board. You should just tie the battery ground to the CPB ground

bleak tulip
#

I thought that everything should be connected to a common ground.

tiny dust
#

no

#

the wiring diagrams don't show that

#

nothing connected to ground on the INA228

bleak tulip
#

Then that is the error. Let me tie the ground wires together and give it a try.

tiny dust
#

the INA228 is measuring current flow between the project voltage and the load. The project and load grounds are not used

paper crag
#

If you're doing a high-side measurement, you want to insert the shunt resistor between the positive source and the positive input terminal.

tiny dust
#

if you were measuring the current with an ammeter, you would break the circuit on the high side (if doing high side) and insert the ammeter in series. Ground would not enter into that. Same here: the INA228 is just a fancy ammeter

#

I'm not sure what you were measuring, but maybe the battery was dumping a lot of current into something. it might have been getting hot

bleak tulip
#

The ground wire fix (tie battery ground to CPB ground) did not change the measurement.

#

Nothing was getting hot when I was connecting everything to the INA228 ground.

tiny dust
#

so go ahead and try measuring the current with your multimeter.

#

the CPB is working OK, is that right? If you measure the voltage at the battery socket on the CPB, it looks reasonable, right? (only a little lower than the voltage at the battery)

#

you may want to wire all this up on a breadboard so you can convenient rewire things

#

I just suggested using the 10A range in case it really is high current. You don't want to blow a fuse on the multimer. That's a nuisance.

bleak tulip
#

Checked the CPB voltage. Looks right (4V) and it is working properly.

tiny dust
#

also measure the voltage between Vin- and Vin+ on the board. It should be only a few mv

bleak tulip
#

0.2mV between Vin- and Vin+

tiny dust
#

makes sense,

#

could you upload your test program?

#

you can use the + to the left

bleak tulip
#

It is just a variation on the example that Liz Clark provided in the guide.

#

I am running out of steam so will have to try the current measurement tomorrow. Thanks for your help, as always.

tiny dust
#

no problem -- it's confusing. you're welcome!

bleak tulip
#

I measured the current with an ammeter. Measured about 10 mA (not flashing LEDs or playing sound) to 30mA (flashing LEDs and playing sound). Note that this is remarkably consistent with my INA228 measurements above if the units are mA rather than Amps. Suggests a simple scaling issue with the adafruit_ina228 library.

bleak tulip
#

Also tried using the Arduino INA228 library and sketch provided in the learn guide (used a PicoW for the host board). Measured about 15mA when the CPB is not flashing any LEDs or using the speaker and about 30-40mA when it flashes the LEDs and/or uses the speaker. Note that the Arduino sketch uses the function ina228.getCurrent_mA(), so exports current readings in mA by default.

#

I guess this all means that there is a bug in the adafruit_ina228 library?

paper crag
#

kinda sounds like maybe the CircuitPython library followed the math from the Arduino library but Amps vs mA difference didn't make it across into the documentation.

bleak tulip
#

Well, as best I can figure the CP library follows the logic provided in the INA228 technical document, but perhaps to your point the Arduino ina228.getCurrent_mA() logic was used in the ina228.current function. I have been looking over the CP code a bit but have not noted any errors, unfortunately.

paper crag
#

do the values seem off by a factor of 1000, or is it perhaps more like 1024? Are you working with enough precision to tell the difference? In one case, you might have some math with a rogue multiplication by 1000, in the other you might have a shift by 10

bleak tulip
#

I am not doing anything with the monitor point values read in each case. My suspicion is that there is a scaling error on the CP side, but I have not found it yet. Still digging, though.