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

Add: Ina219 current/voltage sensor over I2C #381

Merged
merged 7 commits into from
Sep 26, 2024
Merged

Add: Ina219 current/voltage sensor over I2C #381

merged 7 commits into from
Sep 26, 2024

Conversation

Suke0811
Copy link
Collaborator

@Suke0811 Suke0811 commented Sep 20, 2024

  • Hardware to be tested, at least it seems to be alive so far

@Suke0811
Copy link
Collaborator Author

Q:
any idea why this is the case?
edg/parts/Ina219.py:29: error: Argument 1 to "init_from" of "Port" has incompatible type "DigitalBidir"; expected "DigitalSink" [arg-type]
When i locally run mypy, i got the same error but otherwise, i don't see the error.

edg/parts/Ina219.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@ducky64 ducky64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good, few fixes inline.
Let's get it tested before merging?

edg/parts/Ina219.py Show resolved Hide resolved
edg/parts/Ina219.py Outdated Show resolved Hide resolved
edg/parts/Ina219.py Outdated Show resolved Hide resolved
@Suke0811
Copy link
Collaborator Author

image
The sensor seems to be alive and the voltage is reasonable.

I used https://github.com/RobTillaart/INA219 instead of the adafruit library since they assume a predefined shunt resistor and no mechanisms to change it without modifying the library.

Copy link
Collaborator

@ducky64 ducky64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hooray!

@ducky64
Copy link
Collaborator

ducky64 commented Sep 25, 2024

Actually, would it make sense to specify the default shunt resistance t 0.1ohm for compatibility with the Adafruit board?

edit - I guess 2mOhm is what is in the TI reference datasheet, though 0.1ohm might be a good default for things that don't process serious power. idk 🤷‍♀️, either's fine I guess, feel free to merge as-is.

@Suke0811
Copy link
Collaborator Author

Adafruit lib has hardcoded calibration with a set shunt resistor, so maybe it's not good for general purposes. In the inline comment, they say implement your own lol

  void setCalibration_32V_2A();
  void setCalibration_32V_1A();
  void setCalibration_16V_400mA();
  // By default we use a pretty huge range for the input voltage,
// which probably isn't the most appropriate choice for system
// that don't use a lot of power.  But all of the calculations
// are shown below if you want to change the settings.  You will
// also need to change any relevant register settings, such as
// setting the VBUS_MAX to 16V instead of 32V, etc.

@ducky64
Copy link
Collaborator

ducky64 commented Sep 26, 2024

Fair enough! 2mOhm it is, and the datasheet is probably a more authoritative source anyways.

@ducky64 ducky64 merged commit 2080f8a into master Sep 26, 2024
11 checks passed
@ducky64 ducky64 deleted the ina219 branch September 26, 2024 07:15
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

Successfully merging this pull request may close these issues.

2 participants