News:

Let's find out together what makes a PIC Tick!

Main Menu

INA226 any code

Started by John Drew, Sep 17, 2025, 07:41 AM

Previous topic - Next topic

John Drew

I'm starting on a project using the INA226 by TI. It's a power/voltage/current measuring device.
It comes on a tiny board with a load resistor and the necessary parts for a few dollars. It's programmed and accessed by I2C.
Has anyone used this device successfully? If so it would save me a lot of time to get some help. The datasheet is OK but moderately complex.
I reckon I can do the fundamentals such as setting up the I2C. Data comms are 16 bit.
Best wishes
John

RGV250

Hi John,
I wonder how it differs from INA260?

Bob

John Drew

Hi Bob,
I'll check in the morning. I may have it worked out after reading the datasheet three times in between having a piece of chocolate, talking to the next door neighbour and making my wife a cup of coffee :-)
My attention span is becoming a bit short of late.
I'd be very interested in any code you might have for the other device though.
Cheers
John

RGV250


RGV250

Hi John,
I had a quick look at the datasheet and some of the registers are different (probably most) but I think the code I posted should give you a good start.

Bob

John Drew

Thanks Bob,
I'll have a good look, even if the registers are different I can be guided by your code. I've used I2C often enough to make that function work.
Cheers
John

John Drew

A very nice piece of code Bob. I can see what you're doing and it's enough to confirm I'm on the right track.
I'll also compare the data sheets in the next few days.
Thanks again for your support.
John

RGV250

Hi John,
If i am still in hospital today I will have a look and modify the definitions file if that will help.
Otherwise I will probably be bored senseless :)

Bob

top204

Hello Bob

If you do not mind me asking... Why are you in hospital?

Best regards
Les

RGV250

Hi John,
Sleepless night even after reading datasheets :)
From what I can see they are almost identical, the 226 is an earlier model by the looks of it.

The address is the same, note the comment I have not allowed all options but I doubt that would be an issue for you.

Some of the bit names have changed but the bit position doesn't seem to have.
I checked Mode, Conversion times, Average count.

The Die ID is different so in the BAS file you will need to change 2270 for 2260 for the device present test.

The only differences I can see is the Calibration register which I have not read up on as the later one does not need it.
Also the Current register is now 04h and there is a Shunt Register which is 01h (what was the current register in the 260) I think that is the voltage across the shunt resistor but without reading up on it I do not know why you would need it and obviously they agree as it is not present in the 260.

I hope that helps, I have not altered the files as there is so little by the time you download it you could do it.

It is good to know that some companies do not change lots of things for no logical reason, not mentioning any names :)

If I get time I will try to look up what is needed for the Calibration and shunt regs.

Bob

RGV250

Hi Les,
I was walking home Tuesday afternoon and felt like a geriatric, out of breath going up a couple of steps. Tuesday night I had no sleep and could not get out of bed, I lost appetite and the thought of food made me feel sick, even beer :) I thought it was just a bug and would soon pass, a woman from the NHS who is seeing me for other issues said it is not normal so get it sorted.
I called GP and got referred to Chemist, she said out of her scope, you need to go to A&E if you are that short of breath especially with all the other symptoms. At hospital I could barely stand up without falling over while checking in.
They did blood tests and said there is an infection, put me on a drip and other stuff. The nebuliser caused a major issue, quite a while in I got a massive chest pain and pulse rocketed to 140/m resting. The have apparently sorted the high pulse but I want to know what happens when the medication they gave me for that wears off, will it rocket again. Now blood pressure is too low.

Regards,
Bob

John Drew

Hi Bob,
I'm sorry to hear about the health problems. They sound serious enough to warrant close watching.
No health system is perfect and they all like to shove people out the door as soon as possible.
My little project is a tiny blip compared with looking after your health.
Best wishes,
John

RGV250

Hi John,
I am glad I did get talked into going early, someone pointed out I am not 30 anymore where I could have shrugged it off. Trouble is the brain cell thinks it still is.
Anyway, they wake you up at 05:30 just after you finally get to sleep, take blood pressure and then nothing for 2 hours or so so it was a good time to read.
As mentioned, I think you need to change very little but need to swat up on the configuration register and shunt resistor.
Let me know if you need help on the code, I very much doubt you will but always glad to help.

I liked a comment on a programming forum, "Always write your code like the end user is a homicidal maniac and he knows where you live" ;D

Bob

John Drew

#13
Hi Bob,
It always seem to me that hospitals are tuned to the needs of the organisation. Even their breakfasts are far too early and their BP measurements are timed according to their shift changeovers not the fact you finally got some sleep. The good thing is that it sounds as if things are improving. It's always a good sign when I start to complain instead of wondering if this is it    ;D  ;D
I've had a good look at the code now and understand it completely. It ties in with what I think and as you say the the registers seem mostly similar. Full marks to TI. I won't be using all the facilities of the INA226 at this stage.
You may be interested in the project.

Firstly: I chose the INA226 because there was a little board that just needs the I2C connections (has the pullups) and of course measuring inputs and a 0.003 Ohm resistor. This may not be the final choice or I'll put a paralleled load resistor.

Secondly: the project is to remotely monitor the charge current/voltage and a second board to monitor load voltage/current for a remote repeater system. I'll just use two addresses. The device will connect to the internet and we'll be able to access the readings on our computers or phones. I've done all of that in the past so reasonably confident of achieving it although nowadays more referrals to manuals and datasheets (I'm 85 on Monday)

There are three repeaters: packet simplex 147.175MHz, duplex FM 146.9/146.3 MHz FM voice, and a duplex UHF C4FM 439.825/434.825MHz digital over FM. The two metre system is the hub of our 6 connected chain of voice repeaters across the SE of South Australia and Western Victoria.The repeaters are interconnected by UHF radios so there are also three of these on this site. Total current is about 25 Amps on transmit. We have 600W of solar cells and a 200AH LiFePO4 battery. The solar charger is set for a max of 20A. If you're interested have a look at our club website https://serg.org.au and navigate to the repeater pages. I look after the website - nothing fancy but plenty of information primarily for our members.
All the FM controllers are of my design and using PICs programmed with Positron of course.

All the best from Oz. I hope things are continuing to improve.
John

PS Added a screenshot from my phone receiving dummy data. Testing connection to network and index.html.

top204

You get yourself better Bob... I am looking forward to seeing you when you come up here again. It's always good to see friends face to face, and talk all nerdy with each other. :-)

RGV250

Hi Les,
Had a bit of a setback today, the food FIFO buffer is not working properly,  the FI bit is fine but no FO.
I am waiting for them to decide if the buffer needs clearing :)

Bob