Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dfrobot _ina 219 #2

Open
cristeamihai opened this issue Mar 26, 2020 · 4 comments
Open

dfrobot _ina 219 #2

cristeamihai opened this issue Mar 26, 2020 · 4 comments

Comments

@cristeamihai
Copy link

the provided code is not working with python either python 3

error get when python

pi@raspberrypi:~/DFRobot_INA219/Python/RespberryPi $ python get_voltage_current_power.py
Traceback (most recent call last):
File "get_voltage_current_power.py", line 29, in
while not ina.begin():
File "/home/pi/DFRobot_INA219/Python/RespberryPi/DFRobot_INA219.py", line 69, in begin
self.set_bus_ADC(self.adc_bits_12, self.adc_sample_8)
File "/home/pi/DFRobot_INA219/Python/RespberryPi/DFRobot_INA219.py", line 118, in set_bus_ADC
if(bits < adc_bits_12 and sample > adc_sample_1):
NameError: global name 'adc_bits_12' is not defined

found working code at pi-ina219 1.3.0

@Sincoster
Copy link

I have that same problem.

Now i test what you found.

@KrzysztofSikora
Copy link

I have the same problem. Could you add better documentation?

@cristeamihai
Copy link
Author

Just look for common library and example for raspi ina219 ic, the moded code I ve losted. Now use current to voltage analog. I'll put moded code if I LL found on computer. Good luck

@KrzysztofSikora
Copy link

KrzysztofSikora commented Sep 23, 2020

@cristeamihai Thanks for your help. I've found library and the code works.
https://github.com/chrisb2/pi_ina219

#!/usr/bin/env python
from ina219 import INA219
from ina219 import DeviceRangeError

SHUNT_OHMS = 0.1


def read():
    ina = INA219(SHUNT_OHMS, address=0x45)
    ina.configure()

    print("Bus Voltage: %.3f V" % ina.voltage())
    try:
        print("Bus Current: %.3f mA" % ina.current())
        print("Power: %.3f mW" % ina.power())
        print("Shunt voltage: %.3f mV" % ina.shunt_voltage())
    except DeviceRangeError as e:
        # Current out of device range with specified shunt resistor
        print(e)


if __name__ == "__main__":
    read()

gsotirchos added a commit to gsotirchos/DFRobot_INA219 that referenced this issue Apr 9, 2021
gsotirchos added a commit to gsotirchos/DFRobot_INA219 that referenced this issue Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants