Skip to content

Commit

Permalink
Fix multiple compilation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinyu-Zhao committed Aug 5, 2022
0 parents commit 8e60aae
Show file tree
Hide file tree
Showing 9 changed files with 999 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
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
21 changes: 21 additions & 0 deletions LICENSE
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.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# INA3221 Library
Arduino library for INA3221 current and voltage sensor.
45 changes: 45 additions & 0 deletions examples/get_started/get_started.ino
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);
}
72 changes: 72 additions & 0 deletions examples/offset_compensation/offset_compensation.ino
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);
}
16 changes: 16 additions & 0 deletions library.json
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"
}
9 changes: 9 additions & 0 deletions library.properties
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=*
Loading

0 comments on commit 8e60aae

Please sign in to comment.