User avatar
Mettauk
Posts: 260
Joined: Mon Dec 10, 2012 12:40 pm
Location: Zarg

ina260 energy monitor

Fri Jul 30, 2021 4:13 pm

I'm making a small wind turbine (3d print) and want to log energy output and rpm over time. I have sorted the rpm logging and have bought an Adafruit INA260 which I hope is the right thing to measure and log turbine output?!

Having tried to follow the guidance at https://learn.adafruit.com/adafruit-ina ... cuitpython I am now stuck in my ignorance!

Can anyone help with getting this going. I have it wired up and seemingly working but I'm lost with how to even print Current/Watts/power from an external source. I don't understand the part about high side and low side which might be why I'm lost.

Ive connected a 12v DC supply but the readout seems way off...
When connecting a 12v 4w lamp in the circuit I get the following, which just seems weird.

Code: Select all

Current: 6.25 mA Voltage: 0.00 V Power:0.00 mW
Current: 13.75 mA Voltage: 0.81 V Power:0.00 mW
Current: 17.50 mA Voltage: 0.51 V Power:0.00 mW
Current: 10.00 mA Voltage: 0.57 V Power:0.00 mW
Current: 11.25 mA Voltage: 0.56 V Power:0.00 mW
Current: 8.75 mA Voltage: 0.00 V Power:0.00 mW
Current: 12.50 mA Voltage: 0.12 V Power:30.00 mW
Current: 6.25 mA Voltage: 0.44 V Power:10.00 mW
Current: 6.25 mA Voltage: 1.10 V Power:0.00 mW
Current: 16.25 mA Voltage: 0.51 V Power:0.00 mW
Current: 15.00 mA Voltage: 1.46 V Power:0.00 mW
Current: 7.50 mA Voltage: 0.00 V Power:0.00 mW
Current: 13.75 mA Voltage: 0.73 V Power:0.00 mW
Current: 13.75 mA Voltage: 0.35 V Power:0.00 mW
INA260wiring.jpg
INA260wiring.jpg (71.02 KiB) Viewed 562 times
SensorWiring2.jpg
SensorWiring2.jpg (186.82 KiB) Viewed 454 times
Voltage be 12.4 but Ive either wired it wrongly or Im really missing something??

Python code for above readout is

Code: Select all

# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
import board
import adafruit_ina260

i2c = board.I2C()
ina260 = adafruit_ina260.INA260(i2c)
while True:
    print(
        "Current: %.2f mA Voltage: %.2f V Power:%.2f mW"
        % (ina260.current, ina260.voltage, ina260.power)
    )
    time.sleep(1)
Last edited by Mettauk on Sat Jul 31, 2021 1:48 am, edited 2 times in total.
As humans we have been the same for a very very long time, technology changes how we do... not who we are as people.

Eirikur
Posts: 133
Joined: Sun Sep 09, 2018 9:43 pm

Re: ina260 energy monitor

Fri Jul 30, 2021 11:08 pm

I took a quick peek at that Adafruit breakout. Do you have both the input voltage+ input voltage- connected? If that's not so, I think you may be measuring noise.
If so, just read the Adafruit documentation about the +and- inputs. Limor, Fried, founder of Adafruit, is a cool, very nice, person. If I file a bug on github about one of their libraries, chances are that I'll get an email response from ladyada (Limor) the same day, often at night.

The chip has an onboard precision resistor and it works by measuring the voltage across that resistor. So, you you have to have both ends connected. You may already know this. I just couldn't quite see in your photo.

User avatar
Mettauk
Posts: 260
Joined: Mon Dec 10, 2012 12:40 pm
Location: Zarg

Re: ina260 energy monitor

Sat Jul 31, 2021 12:49 am

Thanks for responding. Attached to original post is another hopefully clearer picture, using a motor this time. Same problem getting any real data. the 12v brick to the motor and voltage display + goes through the INA260 via the screw terminals, the ground is also grounded to the Pi which was a bit scary but that's what the guidance says to do.

when running the motor, for the first line and last few the 12v brick is not plugged in...

Code: Select all

~ $ python3 ina60.py
Current: 1.25 mA Voltage: 0.00 V Power:0.00 mW
Current: 58.75 mA Voltage: 0.76 V Power:80.00 mW
Current: 40.00 mA Voltage: 0.00 V Power:0.00 mW
Current: 46.25 mA Voltage: 0.27 V Power:40.00 mW
Current: 61.25 mA Voltage: 0.21 V Power:10.00 mW
Current: 37.50 mA Voltage: 1.08 V Power:30.00 mW
Current: 51.25 mA Voltage: 0.63 V Power:30.00 mW
Current: 30.00 mA Voltage: 1.17 V Power:40.00 mW
Current: 56.25 mA Voltage: 0.09 V Power:0.00 mW
Current: -1.25 mA Voltage: 0.13 V Power:0.00 mW
Current: 0.00 mA Voltage: 0.99 V Power:0.00 mW
Current: 0.00 mA Voltage: 0.00 V Power:0.00 mW
Current: -1.25 mA Voltage: 0.14 V Power:0.00 mW
^CTraceback (most recent call last):
  File "ina60.py", line 15, in <module>
    time.sleep(1)
KeyboardInterrupt
I'm not sure what you mean by input voltage + and - (If you mean the 12v brick to the motor then only the + passes through the screw terminal but the ground is "branched" in? I don't think its a bug, I think it is me coupled with very limited usage guidance from adafruit??
I also don't understand "By default power and voltage measurements are only accurate for high side current sensing"
As humans we have been the same for a very very long time, technology changes how we do... not who we are as people.

User avatar
Gavinmc42
Posts: 6069
Joined: Wed Aug 28, 2013 3:31 am

Re: ina260 energy monitor

Sat Jul 31, 2021 9:09 am

Wiring looks about right.
Does that have on board sense resistor?

See if "i2cdetect -y 1" can find it.
Test with "i2cdump -y 1 0x40 w" on that INA2xx series as that can get the 16bit register data.

Currently updating a solar/wind that has old model A system with 6 shunts on it.
I made my own boards years ago before Adafruit and others did breakouts.
Uses LTC2945 but same sort of sensor.

I faked up a test jig with 1 Ohm sense resistor, 240 Ohm load resistor and a 10k Pot and feed it 12 volts or so
Tested the jig and sensors yesterday, easier than testing on the real system.
Wish I had thought of that the first time years ago.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

User avatar
Mettauk
Posts: 260
Joined: Mon Dec 10, 2012 12:40 pm
Location: Zarg

Re: ina260 energy monitor

Sat Jul 31, 2021 9:41 am

I get...

Code: Select all

pi@mill:~ $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
pi@Mill:~ $ i2cdump -y 1 0x40 w
     0,8  1,9  2,a  3,b  4,c  5,d  6,e  7,f
00: 2761 0000 0f00 0000 ffff 0000 0800 0000
08: ffff ffff XXXX b2ec ffff c0ff 4954 7022
10: 2761 0000 0000 0000 ffff 0000 0800 0000
18: ffff ffff XXXX b2ec ffff c0ff 4954 7022
20: 2761 0000 4000 0000 ffff 0000 0800 0000
28: ffff ffff XXXX b2ec ffff c0ff 4954 7022
30: 2761 0000 5000 0000 ffff 0000 0800 0000
38: ffff ffff XXXX b2ec ffff c0ff 4954 7022
40: 2761 ffff 0000 0000 ffff 0000 0800 0000
48: ffff ffff XXXX b2ec ffff c0ff 4954 7022
50: 2761 ffff 0000 0000 ffff 0000 0800 0000
58: ffff ffff XXXX b2ec ffff c0ff 4954 7022
60: 2761 ffff 0000 0000 ffff 0000 0800 0000
68: ffff ffff XXXX b2ec ffff c0ff 4954 7022
70: 2761 ffff 0000 0000 ffff 0000 0800 0000
78: ffff ffff XXXX b2ec ffff c0ff 4954 7022
80: 2761 ffff 2d03 0000 ffff 0000 0800 0000
88: ffff ffff XXXX b2ec ffff c0ff 4954 7022
90: 2761 0000 0000 0000 ffff 0000 0800 0000
98: ffff ffff XXXX b2ec ffff c0ff 4954 7022
a0: 2761 0100 2803 0000 ffff 0000 0800 0000
a8: ffff ffff XXXX b2ec ffff c0ff 4954 7022
b0: 2761 ffff 4100 0000 ffff 0000 0800 0000
b8: ffff ffff XXXX b2ec ffff c0ff 4954 7022
c0: 2761 0100 2c03 0000 ffff 0000 0800 0000
c8: ffff ffff XXXX b2ec ffff c0ff 4954 7022
d0: 2761 0000 0b00 0000 ffff 0000 0800 0000
d8: ffff ffff XXXX b2ec ffff c0ff 4954 7022
e0: 2761 0000 3503 0000 ffff 0000 0800 0000
e8: ffff ffff XXXX b2ec ffff c0ff 4954 7022
f0: 2761 ffff 0000 0000 ffff 0000 0800 0000
f8: ffff ffff XXXX b2ec ffff c0ff 4954 7022
Either it is faulty or I'm still doing something wrong??
As humans we have been the same for a very very long time, technology changes how we do... not who we are as people.

User avatar
Gavinmc42
Posts: 6069
Joined: Wed Aug 28, 2013 3:31 am

Re: ina260 energy monitor

Sat Jul 31, 2021 11:57 am

Looks like the sensor is working fine.
I don't remember what values I used but you need to set the config AND calibration registers.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

User avatar
Mettauk
Posts: 260
Joined: Mon Dec 10, 2012 12:40 pm
Location: Zarg

Re: ina260 energy monitor

Sat Jul 31, 2021 8:49 pm

Oh, really, how and what are these settings and how do I know what values to use?

I "simply" want to know what my little 3d printed turbine is putting out in DC for given measured rpm. Somewhere between 0 and 25v max around 4amps, probably less, but I don't know.
As humans we have been the same for a very very long time, technology changes how we do... not who we are as people.

User avatar
Gavinmc42
Posts: 6069
Joined: Wed Aug 28, 2013 3:31 am

Re: ina260 energy monitor

Sat Jul 31, 2021 11:57 pm

That's interesting, the 260 has internal resistor.
The 219 uses external resistor, so needs the calibration register setting.
The INA260 should be easier to use.

Hmm, the output from the ID registers are byte reversed in i2cdump output.
So is the default config.
What does your Python code give you when you read those registers?

Byte order issue?
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

User avatar
Mettauk
Posts: 260
Joined: Mon Dec 10, 2012 12:40 pm
Location: Zarg

Re: ina260 energy monitor

Sun Aug 01, 2021 4:12 pm

After a few days of thinking I decided to solder up the other unit, installed software on another Pi and presto, it works perfectly. Then tried the first unit and it works too. So I guess I messed up the software install on Pi No1 .
As humans we have been the same for a very very long time, technology changes how we do... not who we are as people.

User avatar
Gavinmc42
Posts: 6069
Joined: Wed Aug 28, 2013 3:31 am

Re: ina260 energy monitor

Mon Aug 02, 2021 12:56 am

Once things work you might find something new.
I used Python for 24/7 monitoring.
That had issues when I started back in 2012 with Pi - i2c sensors.
Memory leaks or something.

I ended up with shell script reading the sensors and logging to csv file.
I can use Python or anything else to read those files.
I also uses Dygraphs to plot the data on a Pi webpage server.

Anyway I learned to use i2ctools for testing before trying to debug my own software.
There are some nice USB i2c testers that can plug into USB on a PC too.
A CRO can be handy to debug missing pull ups or reversed SDL/SCL.

This is fun, bargain at that price compared to a CRO.
https://www.adafruit.com/product/4267
When you consider how much your time is worth, this is about one hours cost.

Been meaning to turn a Zero into a logic analyzer.
Got as far as a LCARS styled display.
Have to learn DMA to finish that.
So much to do, so much to learn.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

The_Jackal
Posts: 3
Joined: Thu Apr 29, 2021 11:49 am

Re: ina260 energy monitor

Wed Aug 04, 2021 4:31 am

I am still new to all this stuff. Not even sure if this is the right place to post this. I'm not sure if this helps, but I just made a slight change to the source file, INA260.cpp to work with rp2040. You can use any notepad/ wordpad or whatever to change the .cpp file, I prefer Notepad++. Currently I am using Wire1 pins which is why the code is modified in such a way. My other i2c component for communication is on the original wire. A big thanks to Matthew Brush who wrote the original code. I just modified the source file of the code slightly, to work with the wire1 selection on a Rasperry Pi Pico. I suspect this little change may work for other devices which may not be compatible to the wire file as well. I hope this helps someone.
ina260-master.zip
(10.2 KiB) Downloaded 7 times
Keep in mind you must change the library back to the original before using with an Arduino or something alike. Also, with rp2040 the wire1 sda, scl pins must be changed within the source file. Right now the source file is using pins 26 and 27 for sda, scl. I'm sure someone else can provide a fancier option, but this worked great and was the easiest solution for me.

User avatar
Mettauk
Posts: 260
Joined: Mon Dec 10, 2012 12:40 pm
Location: Zarg

Re: ina260 energy monitor

Wed Aug 04, 2021 8:14 am

Thank you The Jackal,

That sounds really useful, especially as I am thinking about learning to use the 2040 board.
As humans we have been the same for a very very long time, technology changes how we do... not who we are as people.

Return to “General discussion”