-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
1 changed file
with
48 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 |
---|---|---|
@@ -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; | ||
} | ||
} | ||
|