Skip to content

Commit

Permalink
for a/wio_log.. add chassisBatter_volt
Browse files Browse the repository at this point in the history
  • Loading branch information
neilh20 authored and neilh20 committed Sep 29, 2023
1 parent 05328d5 commit 70ff44e
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 31 deletions.
1 change: 1 addition & 0 deletions a/wio_log_display_mmw/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ cmn_lib_deps =
https://github.com/neilh10/InsituModbus
https://github.com/neilh10/KellerModbus
martinl1/BMP388_DEV@^1.0.11 ; dissapeared from github.com/MartinL1/BMP388_DEV.git
https://github.com/sparkfun/SparkFun_BQ27441_Arduino_Library

; Ignore these folders or PlatformIO will double count all the dependencies
; Development: ModularSensors Release1: src ?
Expand Down
94 changes: 89 additions & 5 deletions a/wio_log_display_mmw/src/log_display_to_MMW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,35 @@ AOSongAM2315 am23xx(I2CPower);
/** End [ao_song_am2315] */
#endif // ASONG_AM23XX_UUID

#if defined(BAT_VOLTAGE_UUID )
#include "SparkFunBQ27441.h"
const unsigned int BATTERY_CAPACITY = 650; // Set Wio Terminal Battery's Capacity

#define CHASSIS_BATTERY_NOT_PRESENT -0.123
float chassisBattery_volt = CHASSIS_BATTERY_NOT_PRESENT;

bool battery_present=false;

float getChassisBattery_volt(void) {
if (battery_present) {
// Read battery stats from the BQ27441-G1A
uint16_t volts_mv = lipo.voltage(); // Read battery voltage (mV)
chassisBattery_volt = ((float)volts_mv)/1000; //Convert to Volts
}
return chassisBattery_volt;
} //getChassisBattery_volt

Variable* chassisBattery_variable = new Variable(
getChassisBattery_volt, // function that does the calculation
3, // resolution
"batteryVoltage", // var name. This must be a value from
// http://vocabulary.odm2.org/variablename/
"volts", // var unit. This must be a value from This must be a
// value from http://vocabulary.odm2.org/units/
"Volt1", // var code
BAT_VOLTAGE_UUID);

#endif //BAT_VOLTAGE_UUID

// ==========================================================================
// Creating the Variable Array[s] and Filling with Variable Objects
Expand All @@ -272,12 +301,11 @@ Variable* variableList[] = {
new MaximDS18_Temp(&ds18phy_c, TEMPERATURE_C_UUID,"Ds18Tc"),
new MaximDS18_Temp(&ds18phy_d, TEMPERATURE_D_UUID,"Ds18Td"),
#endif //TEMPERATURE_ALL_DS18

// calcAM2315_TempF
#endif // ASONG_AM23XX_UUID
#if defined(ARDUINO_AVR_ENVIRODIY_MAYFLY)
new ProcessorStats_Battery(&mcuBoard,BAT_VOLTAGE_UUID ),
#endif // ARDUINO_AVR_ENVIRODIY_MAYFLY

#if defined(BAT_VOLTAGE_UUID)
chassisBattery_variable,
#endif // BAT_VOLTAGE_UUID
};


Expand Down Expand Up @@ -340,6 +368,59 @@ uiHelperWioT ui_display;
#endif //USE_DISPLAY
/** End [working_functions] */

#if defined(BAT_VOLTAGE_UUID )

void setupBQ27441(void)
{
// Use lipo.begin() to initialize the BQ27441-G1A and confirm that it's
// connected and communicating.
if (!lipo.begin()) // begin() will return true if communication is successful
{
// If communication fails, print an error message and loop forever.
Serial.println("Error: Unable to communicate with BQ27441.");
Serial.println(" Check battery unit plugged in.");

battery_present=false;
return;
}
battery_present=true;
Serial.println("Connected to BQ27441!");

// Uset lipo.setCapacity(BATTERY_CAPACITY) to set the design capacity
// of your battery.
lipo.setCapacity(BATTERY_CAPACITY);

} // setupBQ27441

void printBatteryStats()
{
if (battery_present) {
// Read battery stats from the BQ27441-G1A
unsigned int soc = lipo.soc(); // Read state-of-charge (%)
unsigned int volts_mv = lipo.voltage(); // Read battery voltage (mV)
int current = lipo.current(AVG); // Read average current (mA)
//unsigned int fullCapacity = lipo.capacity(FULL); // Read full capacity (mAh)
unsigned int capacity = lipo.capacity(REMAIN); // Read remaining capacity (mAh)
int power = lipo.power(); // Read average power draw (mW)
int health = lipo.soh(); // Read state-of-health (%)
// Now print out those values:
String toPrint = "BatteryStats, ";
toPrint += String(soc) + ",%, ";
toPrint += String(volts_mv) + " ,mV, ";
toPrint += String(current) + ",mA,";
toPrint += String(capacity) + ",mAh, ";
//toPrint += String(fullCapacity) + " mAh | ";
toPrint += String(power) + ",mW,";
toPrint += String(health) + ",%";

Serial.println(toPrint);
}
} // printBatteryStats()

#else
void setupBQ27441(void) {}
void printBatteryStats() {Serial.println("Battery : No battery present")}
#endif // BAT_VOLTAGE_UUID

// ==========================================================================
// Arduino Setup Function
Expand Down Expand Up @@ -427,6 +508,8 @@ void setup() {
// Always set the RTC to be in UTC (UTC+0)
Logger::setRTCTimeZone(0);

setupBQ27441();
printBatteryStats();
// Attach the modem and information pins to the logger
dataLogger.attachModem(modemPhy);
//modemPhy.setModemLED(modemLEDPin); //not mapped/tested WioTerminal
Expand Down Expand Up @@ -550,6 +633,7 @@ void loop() {
}
#endif // USE_DISPLAY

printBatteryStats();
dataLogger.logDataAndPubReliably(); //TCP / RTL !there


Expand Down
27 changes: 1 addition & 26 deletions a/wio_log_display_mmw/src/ms_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,31 +184,6 @@ THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN.

//#define SENSOR_CONFIG_GENERAL 1
//#define KellerAcculevel_ACT 1
// Defaults for data.envirodiy.org
//Test08 https://monitormywatershed.org/sites/tu_rc_test08/
#define LOGGERID_DEF_STR "test08"
#define NEW_LOGGERID_MAX_SIZE 40
#define registrationToken_UUID "0cf7c40a-232e-457d-87d6-cea5c0757fec"
#define samplingFeature_UUID "236c674b-69b9-43af-b0d6-33d67b870ecc"
#define SEQUENCE_NUMBER_UUID "8c57835f-a32f-4d62-82dc-0ba09f04cf52"

#define TEMPERATURE_ALL_DS18 1
#define TEMPERATURE_A_UUID "03e7b375-97a7-4423-a3f0-1d822d8b19b9"
#define TEMPERATURE_B_UUID "c62fcd8a-406e-4fe1-87d9-ff3dca8e1b90"
#define TEMPERATURE_C_UUID "43bcda9b-2973-4639-af2c-f0b6bb3fa44b"
#define TEMPERATURE_D_UUID "ff4d732d-88d8-4a1b-b499-16417603edfe"
#define BAT_VOLTAGE_UUID "3bebd4a3-8b54-4f92-ba55-5fd2fd021358"

#if defined SENSIRION_SHT4X_UUID
#define SENSIRION_SHT4X_Air_Temperature_UUID "Air_Temperature_UUID"
//#define SENSIRION_SHT4X_Air_TemperatureF_UUID "Air_TemperatureF_UUID"
#define SENSIRION_SHT4X_Air_Humidity_UUID "Air_Humidity_UUID"
#elif defined ASONG_AM23XX_UUID
//#define ASONG_AM23_Air_Temperature_UUID "Air_Temperature_UUID"
#define ASONG_AM23_Air_Temperature_UUID "8849814d-1603-4a2f-861f-f31ae68cccf3"
//#define ASONG_AM23_Air_TemperatureF_UUID "Air_TemperatureF_UUID"
//#define ASONG_AM23_Air_Humidity_UUID "Air_Humidity_UUID"
#define ASONG_AM23_Air_Humidity_UUID "08646cc3-c5de-414c-af65-c795b2dcac24"
#endif // ASONG_AM23XX_UUID

#include "ms_cfg_uuids.h"
#endif // ms_cfg_h
27 changes: 27 additions & 0 deletions a/wio_log_display_mmw/src/ms_cfg_uuids.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Defaults for data.envirodiy.org
//Test08 https://monitormywatershed.org/sites/tu_rc_test08/
#define LOGGERID_DEF_STR "tu_rc_test08"

#define registrationToken_UUID "0cf7c40a-232e-457d-87d6-cea5c0757fec"
#define samplingFeature_UUID "236c674b-69b9-43af-b0d6-33d67b870ecc"

#define SEQUENCE_NUMBER_UUID "8c57835f-a32f-4d62-82dc-0ba09f04cf52"

#define TEMPERATURE_ALL_DS18 1
#define TEMPERATURE_A_UUID "03e7b375-97a7-4423-a3f0-1d822d8b19b9"
#define TEMPERATURE_B_UUID "c62fcd8a-406e-4fe1-87d9-ff3dca8e1b90"
#define TEMPERATURE_C_UUID "43bcda9b-2973-4639-af2c-f0b6bb3fa44b"
#define TEMPERATURE_D_UUID "ff4d732d-88d8-4a1b-b499-16417603edfe"
#define BAT_VOLTAGE_UUID "3bebd4a3-8b54-4f92-ba55-5fd2fd021358"

#if defined SENSIRION_SHT4X_UUID
#define SENSIRION_SHT4X_Air_Temperature_UUID "Air_Temperature_UUID"
//#define SENSIRION_SHT4X_Air_TemperatureF_UUID "Air_TemperatureF_UUID"
#define SENSIRION_SHT4X_Air_Humidity_UUID "Air_Humidity_UUID"
#elif defined ASONG_AM23XX_UUID
//#define ASONG_AM23_Air_Temperature_UUID "Air_Temperature_UUID"
#define ASONG_AM23_Air_Temperature_UUID "8849814d-1603-4a2f-861f-f31ae68cccf3"
//#define ASONG_AM23_Air_TemperatureF_UUID "Air_TemperatureF_UUID"
//#define ASONG_AM23_Air_Humidity_UUID "Air_Humidity_UUID"
#define ASONG_AM23_Air_Humidity_UUID "08646cc3-c5de-414c-af65-c795b2dcac24"
#endif // ASONG_AM23XX_UUID

0 comments on commit 70ff44e

Please sign in to comment.