david_1234
Posts: 200
Joined: Mon Jan 01, 2018 2:14 pm

Raspberry Pi INA219 Tutorial problem

Mon Nov 04, 2019 12:16 pm

I have done everything it said
but while I'm trying to run the example code

Code: Select all

from ina219 import INA219, DeviceRangeError
from time import sleep

SHUNT_OHMS = 0.1
MAX_EXPECTED_AMPS = 2.0
ina = INA219(SHUNT_OHMS, MAX_EXPECTED_AMPS)
ina.configure(ina.RANGE_16V)

def read_ina219():
    try:
        print('Bus Voltage: {0:0.2f}V'.format(ina.voltage()))
        print('Bus Current: {0:0.2f}mA'.format(ina.current()))
        print('Power: {0:0.2f}mW'.format(ina.power()))
        print('Shunt Voltage: {0:0.2f}mV\n'.format(ina.shunt_voltage()))
    except DeviceRangeError as e:
        # Current out of device range with specified shunt resister
        print(e)

while 1:
    read_ina219()
    sleep(1)
I get this error:

Code: Select all



sudo python3 Documents/VoltTest.py 
Traceback (most recent call last):
  File "Documents/VoltTest.py", line 1, in <module>
    from ina219 import INA219, DeviceRangeError
ImportError: bad magic number in 'ina219': b'\x03\xf3\r\n'
pi@raspberrypi:~ $ sudo python Documents/VoltTest.py 
Traceback (most recent call last):
  File "Documents/VoltTest.py", line 1, in <module>
    from ina219 import INA219, DeviceRangeError
  File "/home/pi/Documents/ina219.py", line 1, in <module>
    """ This library supports the INA219 current and power monitor
ImportError: cannot import name INA219



what could be the problem ?

Thanks ,


** this is without any connection to my other post https://www.raspberrypi.org/forums/view ... 0#p1561230

DirkS
Posts: 10006
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Raspberry Pi INA219 Tutorial problem

Mon Nov 04, 2019 12:32 pm

Which tutorial?


User avatar
DougieLawson
Posts: 36509
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Raspberry Pi INA219 Tutorial problem

Mon Nov 04, 2019 1:21 pm

I think you need to give us a photo of your INA219 board and a clear (well focused) view of how you've wired it to your Raspberry.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

david_1234
Posts: 200
Joined: Mon Jan 01, 2018 2:14 pm

Re: Raspberry Pi INA219 Tutorial problem

Mon Nov 04, 2019 1:26 pm

My camera phone is not wroking ....
sorry

but I will show you the setup :

VCC - Pin 17 (3.3V)
GND - Pin 39 (GND)
Scl - PIn 5 (SCL)
Dsa- Pin 3 (SDA)

now I'm trying to use the PI4 with buster installed

Thasnk ,

User avatar
DougieLawson
Posts: 36509
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Raspberry Pi INA219 Tutorial problem

Mon Nov 04, 2019 1:56 pm

That's no good. You're spouting the theory. We need to see if your reality matches the instructions.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

david_1234
Posts: 200
Joined: Mon Jan 01, 2018 2:14 pm

Re: Raspberry Pi INA219 Tutorial problem

Mon Nov 04, 2019 2:33 pm

found a phone :-)


hope the image is clear to understand
20191104_162623.jpg
20191104_162623.jpg (158.14 KiB) Viewed 845 times
this is the 3rd try
using PI4 with a clean buster (after first setup did only update&upgrade , open SSH\VNC\I2C)

User avatar
DougieLawson
Posts: 36509
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Raspberry Pi INA219 Tutorial problem

Mon Nov 04, 2019 2:43 pm

Are those pins soldered into your INA219 breakout board?

Do you have an arduino or esp8266/esp12/esp01 that you could use to test that sensor with?
https://learn.adafruit.com/adafruit-ina ... out/wiring
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

david_1234
Posts: 200
Joined: Mon Jan 01, 2018 2:14 pm

Re: Raspberry Pi INA219 Tutorial problem

Mon Nov 04, 2019 2:48 pm

Yes ,
Are those pins are soldered into my INA219 breakout board.

I will try to find a arduino here and check if I can see the device , it will take me a few hours I guess
after I will find I will let you know

Thanks (for now)

david_1234
Posts: 200
Joined: Mon Jan 01, 2018 2:14 pm

Re: Raspberry Pi INA219 Tutorial problem

Mon Nov 04, 2019 4:08 pm

I found Arduino Ethernet here
use this code:

Code: Select all

#include <Wire.h>
#include <Adafruit_INA219.h>

Adafruit_INA219 ina219;


void setup(void)
{
  Serial.begin(115200);
  while (!Serial) {
    // will pause Zero, Leonardo, etc until serial console opens
    delay(1);
  }

  uint32_t currentFrequency;

  Serial.println("Hello!");

  // Initialize the INA219.
  // By default the initialization will use the largest range (32V, 2A).  However
  // you can call a setCalibration function to change this range (see comments).
  ina219.begin();
  // To use a slightly lower 32V, 1A range (higher precision on amps):
  //ina219.setCalibration_32V_1A();
  // Or to use a lower 16V, 400mA range (higher precision on volts and amps):
  ina219.setCalibration_16V_400mA();

  Serial.println("Measuring voltage and current with INA219 ...");
}

void loop(void)
{
  float shuntvoltage = 0;
  float busvoltage = 0;
  float current_mA = 0;
  float loadvoltage = 0;
  float power_mW = 0;

  shuntvoltage = ina219.getShuntVoltage_mV();
  busvoltage = ina219.getBusVoltage_V();
  current_mA = ina219.getCurrent_mA();
  power_mW = ina219.getPower_mW();
  loadvoltage = busvoltage + (shuntvoltage / 1000);

  Serial.print("Bus Voltage:   "); Serial.print(busvoltage); Serial.println(" V");
  Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV");
  Serial.print("Load Voltage:  "); Serial.print(loadvoltage); Serial.println(" V");
  Serial.print("Current:       "); Serial.print(current_mA); Serial.println(" mA");
  Serial.print("Power:         "); Serial.print(power_mW); Serial.println(" mW");
  Serial.println("");

  delay(2000);
}


connected the INA219 to 3.3,GND,SCL,SDA
but on the monitor I only get

Code: Select all

Hello!
nothing after it

I have try to use 2 more INA219 I have here
get the same thing
Last edited by david_1234 on Mon Nov 04, 2019 4:11 pm, edited 1 time in total.

User avatar
DougieLawson
Posts: 36509
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Raspberry Pi INA219 Tutorial problem

Mon Nov 04, 2019 4:10 pm

Sorry, You'll have to RTFD. I don't know because I've never used one. RTFD == read the fine datasheet
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

david_1234
Posts: 200
Joined: Mon Jan 01, 2018 2:14 pm

Re: Raspberry Pi INA219 Tutorial problem

Mon Nov 04, 2019 4:12 pm

what do you wnat me to find ?

I have try with and without the external power - if this is what you mean

still the same thing - get nothing after the
"Hello!"

User avatar
DougieLawson
Posts: 36509
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Raspberry Pi INA219 Tutorial problem

Mon Nov 04, 2019 4:40 pm

Read this: http://www.ti.com/lit/ds/symlink/ina219.pdf it tells you how your device works.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

chipace
Posts: 78
Joined: Sat Jun 29, 2019 2:56 am
Location: brown paper bag in a septic tank

Re: Raspberry Pi INA219 Tutorial problem

Mon Nov 04, 2019 11:49 pm

Are you able to see the i2c device address when you run the following command?

Code: Select all

i2cdetect -y 1
I can't see where you are specifying your i2c device address in your python script.
I assume your A0 and A1 pins are tied to GND so that you have a device address of 0x40.

david_1234
Posts: 200
Joined: Mon Jan 01, 2018 2:14 pm

Re: Raspberry Pi INA219 Tutorial problem

Tue Nov 05, 2019 8:58 am

I have try to do something else now
I jumper A0 and A1
so when I run the scanner I can see this:

Code: Select all

sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- 45 -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --  
which is good - the device is working

I don't think the problem is in the wiring

david_1234
Posts: 200
Joined: Mon Jan 01, 2018 2:14 pm

Re: Raspberry Pi INA219 Tutorial problem

Tue Nov 05, 2019 9:38 am

Everything is OK like the guide
Capture.PNG
Capture.PNG (250.36 KiB) Viewed 722 times






******
I took this INA219 device and connected it to Arduino as suggested , and there it works and show me the data V\A\P.

so no hardware problem for 100%

maybe I need to allow \enable soemthing ??

I saw that maybe in old pis there is only 1 i2c pins , and in the PI4 I see there is 2
pins 3,5 and pins 27,28
so maybe I need to change soemthing in the setup \ main code to make it work on i2c1 ?

Return to “Beginners”