Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Expose setCalibration functions to change calibration range from user…

… sketches.
commit bb2569842cc80db41b39292a20581b21d4061201 1 parent 9a4d386
@tdicola tdicola authored
View
10 Adafruit_INA219.cpp
@@ -86,7 +86,7 @@ void Adafruit_INA219::wireReadRegister(uint8_t reg, uint16_t *value)
@note These calculations assume a 0.1 ohm resistor is present
*/
/**************************************************************************/
-void Adafruit_INA219::ina219SetCalibration_32V_2A(void)
+void Adafruit_INA219::setCalibration_32V_2A(void)
{
// By default we use a pretty huge range for the input voltage,
// which probably isn't the most appropriate choice for system
@@ -177,7 +177,7 @@ void Adafruit_INA219::ina219SetCalibration_32V_2A(void)
@note These calculations assume a 0.1 ohm resistor is present
*/
/**************************************************************************/
-void Adafruit_INA219::ina219SetCalibration_32V_1A(void)
+void Adafruit_INA219::setCalibration_32V_1A(void)
{
// By default we use a pretty huge range for the input voltage,
// which probably isn't the most appropriate choice for system
@@ -260,7 +260,7 @@ void Adafruit_INA219::ina219SetCalibration_32V_1A(void)
wireWriteRegister(INA219_REG_CONFIG, config);
}
-void Adafruit_INA219::ina219SetCalibration_16V_400mA(void) {
+void Adafruit_INA219::setCalibration_16V_400mA(void) {
// Calibration which uses the highest precision for
// current measurement (0.1mA), at the expense of
@@ -362,8 +362,8 @@ Adafruit_INA219::Adafruit_INA219(uint8_t addr) {
/**************************************************************************/
void Adafruit_INA219::begin() {
Wire.begin();
- // Set chip to known config values to start
- ina219SetCalibration_32V_2A();
+ // Set chip to large range config values to start
+ setCalibration_32V_2A();
}
/**************************************************************************/
View
6 Adafruit_INA219.h
@@ -113,6 +113,9 @@ class Adafruit_INA219{
public:
Adafruit_INA219(uint8_t addr = INA219_ADDRESS);
void begin(void);
+ void setCalibration_32V_2A(void);
+ void setCalibration_32V_1A(void);
+ void setCalibration_16V_400mA(void);
float getBusVoltage_V(void);
float getShuntVoltage_mV(void);
float getCurrent_mA(void);
@@ -127,9 +130,6 @@ class Adafruit_INA219{
void wireWriteRegister(uint8_t reg, uint16_t value);
void wireReadRegister(uint8_t reg, uint16_t *value);
- void ina219SetCalibration_32V_2A(void);
- void ina219SetCalibration_32V_1A(void);
- void ina219SetCalibration_16V_400mA(void);
int16_t getBusVoltage_raw(void);
int16_t getShuntVoltage_raw(void);
int16_t getCurrent_raw(void);
View
10 examples/getcurrent/getcurrent.pde
@@ -10,8 +10,16 @@ void setup(void)
Serial.begin(115200);
Serial.println("Hello!");
- Serial.println("Measuring voltage and current with INA219 ...");
+ // Initialize the INA219.
+ // By default the initialization will use the largest range (32V, 2A). However
+ // you can call a setCalibration function to change this range (see comments).
ina219.begin();
+ // To use a slightly lower 32V, 1A range (higher precision on amps):
+ //ina219.setCalibration_32V_1A();
+ // Or to use a lower 16V, 400mA range (higher precision on volts and amps):
+ //ina219.setCalibration_16V_400mA();
+
+ Serial.println("Measuring voltage and current with INA219 ...");
}
void loop(void)
Please sign in to comment.
Something went wrong with that request. Please try again.