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

INA219 - Wrong current reading #622

Open
2 of 7 tasks
r3v1 opened this issue Mar 21, 2024 · 0 comments
Open
2 of 7 tasks

INA219 - Wrong current reading #622

r3v1 opened this issue Mar 21, 2024 · 0 comments

Comments

@r3v1
Copy link

r3v1 commented Mar 21, 2024

The issue

I'm running the example provided by de library with an ESP32 and INA219 sensor, configured for 400mA, 16V and 40mV gain as:

  ESP_ERROR_CHECK(ina219_configure(&dev, INA219_BUS_RANGE_16V, INA219_GAIN_1,
                                   INA219_RES_12BIT_1S, INA219_RES_12BIT_1S, INA219_MODE_CONT_SHUNT_BUS));

That is the same configuration I've been using the Adafruit INA219 library in Arduino. However, the esp-idf-lib library reports wrong measures on this simple circuit (also simulated in Falstad):

image

The multimeter shows almost the same value around 36mA, but the library says about 76mA.

I think the calibration factor is somehow, in the Arduino library says 0x2000 and here, as is computed dinamically, says 0x1000. I tried to hardcode this value with no positive results. Shunt resistor is set to 100miliohms.

Which SDK are you using?

esp-idf

Which version of SDK are you using?

master

Which build target have you used?

  • esp32
  • esp32s2
  • esp32s3
  • esp32c2
  • esp8266
  • other

Component causing the issue

ina219

Anything in the logs that might be useful for us?

I (102) main_task: Started on CPU0
I (102) main_task: Calling app_main()
I (102) INA219_example: Initializing INA219
D (102) i2cdev: Reconfiguring I2C driver on port 0
D (102) i2cdev: I2C driver successfully reconfigured on port 0
D (112) i2cdev: Timeout: ticks = 0 (0 usec) on port 0
D (112) ina219: Initialize, config: 0x03ff
I (112) INA219_example: Configuring INA219
D (112) ina219: Config: 0x019f
D (112) i2cdev: Timeout: ticks = 0 (0 usec) on port 0
I (112) INA219_example: Calibrating INA219
D (112) i2cdev: Timeout: ticks = 0 (0 usec) on port 0
D (112) ina219: Calibration: 0.1000 Ohm, 0x1000
D (112) i2cdev: Timeout: ticks = 0 (0 usec) on port 0
I (102) main_task: Returned from app_main()
I (112) INA219_example: Starting the loop
D (112) i2cdev: Timeout: ticks = 0 (0 usec) on port 0
112,92.00
D (1112) i2cdev: Timeout: ticks = 0 (0 usec) on port 0
1112,-100.00
D (2112) i2cdev: Timeout: ticks = 0 (0 usec) on port 0
2112,76.00
D (3112) i2cdev: Timeout: ticks = 0 (0 usec) on port 0
3112,76.00
D (4112) i2cdev: Timeout: ticks = 0 (0 usec) on port 0
4112,76.00
D (5112) i2cdev: Timeout: ticks = 0 (0 usec) on port 0
5112,76.00

Additional information or context

No response

Confirmation

  • This report is not a question nor a request for drivers.
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

1 participant