Skip to content

Commit

Permalink
Update bbn_m5atomS3_lite_INA219.ino
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrouch authored Dec 15, 2024
1 parent 2a87a5e commit f3918ef
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions bbn_m5atomS3_lite_INA219/bbn_m5atomS3_lite_INA219.ino
Original file line number Diff line number Diff line change
@@ -1 +1,49 @@
#include <M5AtomS3.h>
#include <Adafruit_INA219.h>

#include "NmeaXDR.h"

void setup() {
auto cfg = M5.config();
AtomS3.begin(cfg);
Serial.begin(4800);
Wire.begin(G2, G1, 100000UL);
if (!ina219.begin()) {
Serial.println("Failed to find INA219 chip");
while (1) {
delay(10);
}
}
/*
By default the INA219 will be calibrated with a range of 32V, 2A.
However uncomment one of the below to change the range. A smaller
range can't measure as large of values but will measure with slightly
better precision.
*/
//ina219.setCalibration_32V_1A();
//ina219.setCalibration_16V_400mA();
}

void loop() {
if (timeout < millis()) {
// Read voltage and current from INA219.
float shuntvoltage = ina219.getShuntVoltage_mV();
float busvoltage = ina219.getBusVoltage_V();
float current_mA = ina219.getCurrent_mA();

// Compute load voltage, power, and milliamp-hours.
float loadvoltage = busvoltage + (shuntvoltage / 1000);
float power_mW = loadvoltage * current_mA;

// Mode 0, display volts and amps.
printSIValue(loadvoltage, "V:", 2, 10);
display.setCursor(0, 16);
printSIValue(current_mA / 1000.0, "A:", 5, 10);

gen_nmea0183_xdr("$BBXDR,U,%.3f,V,VOLT_INA219", loadvoltage);
gen_nmea0183_xdr("$BBXDR,I,%.3f,A,AMPS_INA219", current_mA / 1000);
gen_nmea0183_xdr("$BBXDR,W,%.3f,W,WATT_INA219", power_mW / 1000);
timeout = millis() + 1000;
}
}

0 comments on commit f3918ef

Please sign in to comment.