-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8e60aae
Showing
9 changed files
with
999 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.pio | ||
.vscode/.browse.c_cpp.db* | ||
.vscode/c_cpp_properties.json | ||
.vscode/launch.json | ||
.vscode/ipch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Tinyu Zhao | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# INA3221 Library | ||
Arduino library for INA3221 current and voltage sensor. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <Wire.h> | ||
#include <INA3221.h> | ||
|
||
#define SERIAL_SPEED 115200 // serial baud rate | ||
#define PRINT_DEC_POINTS 3 // decimal points to print | ||
|
||
// Set I2C address to 0x41 (A0 pin -> VCC) | ||
INA3221 ina_0(INA3221_ADDR40_GND); | ||
INA3221 ina_1(INA3221_ADDR41_VCC); | ||
|
||
void current_measure_init() { | ||
ina_0.begin(&Wire); | ||
ina_0.reset(); | ||
ina_0.setShuntRes(10, 10, 10); | ||
ina_1.begin(&Wire); | ||
ina_1.reset(); | ||
ina_1.setShuntRes(10, 10, 10); | ||
} | ||
|
||
void setup() { | ||
Serial.begin(SERIAL_SPEED); | ||
current_measure_init(); | ||
|
||
while (!Serial) { | ||
delay(1); | ||
} | ||
// Set shunt resistors to 10 mOhm for all channels | ||
} | ||
|
||
void loop() { | ||
Serial.printf( | ||
"A1%3.0fma %1.1fV A2%3.0fma %1.1fV\r\n", | ||
ina_0.getCurrent(INA3221_CH1) * 1000, ina_0.getVoltage(INA3221_CH1), | ||
ina_0.getCurrent(INA3221_CH2) * 1000, ina_0.getVoltage(INA3221_CH2)); | ||
Serial.printf( | ||
"B1%3.0fma %1.1fV B2%3.0fma %1.1fV\r\n", | ||
ina_0.getCurrent(INA3221_CH3) * 1000, ina_0.getVoltage(INA3221_CH3), | ||
ina_1.getCurrent(INA3221_CH1) * 1000, ina_1.getVoltage(INA3221_CH1)); | ||
Serial.printf( | ||
"C1%3.0fma %1.1fV C2%3.0fma %1.1fV\r\n\n", | ||
ina_1.getCurrent(INA3221_CH2) * 1000, ina_1.getVoltage(INA3221_CH2), | ||
ina_1.getCurrent(INA3221_CH3) * 1000, ina_1.getVoltage(INA3221_CH3)); | ||
|
||
delay(1000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include <Wire.h> | ||
#include <INA3221.h> | ||
|
||
#define SERIAL_SPEED 115200 // serial baud rate | ||
#define PRINT_DEC_POINTS 3 // decimal points to print | ||
|
||
// Set I2C address to 0x41 (A0 pin -> VCC) | ||
INA3221 ina3221(INA3221_ADDR40_GND); | ||
|
||
void setup() { | ||
Serial.begin(SERIAL_SPEED); | ||
|
||
while (!Serial) { | ||
delay(1); | ||
} | ||
|
||
ina3221.begin(); | ||
ina3221.reset(); | ||
|
||
// Set shunt resistors to 10 mOhm for all channels | ||
ina3221.setShuntRes(10, 10, 10); | ||
|
||
// Set series filter resistors to 10 Ohm for all channels. | ||
// Series filter resistors introduce error to the current measurement. | ||
// The error can be estimated and depends on the resitor values and the bus | ||
// voltage. | ||
ina3221.setFilterRes(10, 10, 10); | ||
} | ||
|
||
void loop() { | ||
float current[3]; | ||
float current_compensated[3]; | ||
float voltage[3]; | ||
|
||
current[0] = ina3221.getCurrent(INA3221_CH1); | ||
current_compensated[0] = ina3221.getCurrentCompensated(INA3221_CH1); | ||
voltage[0] = ina3221.getVoltage(INA3221_CH1); | ||
|
||
current[1] = ina3221.getCurrent(INA3221_CH2); | ||
current_compensated[1] = ina3221.getCurrentCompensated(INA3221_CH2); | ||
voltage[1] = ina3221.getVoltage(INA3221_CH2); | ||
|
||
current[2] = ina3221.getCurrent(INA3221_CH3); | ||
current_compensated[2] = ina3221.getCurrentCompensated(INA3221_CH3); | ||
voltage[2] = ina3221.getVoltage(INA3221_CH3); | ||
|
||
Serial.print("Channel 1: \n Current: "); | ||
Serial.print(current[0], PRINT_DEC_POINTS); | ||
Serial.print("A\n Compensated current: "); | ||
Serial.print(current_compensated[0], PRINT_DEC_POINTS); | ||
Serial.print("\n Voltage: "); | ||
Serial.print(voltage[0], PRINT_DEC_POINTS); | ||
Serial.println("V"); | ||
|
||
Serial.print("Channel 2: \n Current: "); | ||
Serial.print(current[1], PRINT_DEC_POINTS); | ||
Serial.print("A\n Compensated current: "); | ||
Serial.print(current_compensated[1], PRINT_DEC_POINTS); | ||
Serial.print("\n Voltage: "); | ||
Serial.print(voltage[1], PRINT_DEC_POINTS); | ||
Serial.println("V"); | ||
|
||
Serial.print("Channel 3: \n Current: "); | ||
Serial.print(current[2], PRINT_DEC_POINTS); | ||
Serial.print("A\n Compensated current: "); | ||
Serial.print(current_compensated[2], PRINT_DEC_POINTS); | ||
Serial.print("\n Voltage: "); | ||
Serial.print(voltage[2], PRINT_DEC_POINTS); | ||
Serial.println("V\n"); | ||
|
||
delay(1000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "INA3221", | ||
"description": "Library for INA3221 Chip", | ||
"keywords": "INA3221 current and voltage sensor", | ||
"authors": { | ||
"name": "Tinyu", | ||
"url": "https://github.com/Tinyu-Zhao" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Tinyu-Zhao/INA3221.git" | ||
}, | ||
"version": "0.0.1", | ||
"frameworks": "arduino", | ||
"platforms": "espressif32" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name=INA3221 | ||
version=0.0.1 | ||
author=Tinyu | ||
maintainer=Tinyu <[email protected]> | ||
sentence=INA3221 Triple-Channel Sensor Driver. | ||
paragraph=INA3221 Triple-Channel Sensor Driver. | ||
category=Sensors | ||
url=https://github.com/Tinyu-Zhao/INA3221 | ||
architectures=* |
Oops, something went wrong.