Skip to content

Commit

Permalink
[PowerFeather] Add configuration of maximum battery charging current (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-bs authored Aug 4, 2024
1 parent 24f64bf commit 24a6716
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions BresserWeatherSensorLW.ino
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
// from LittleFS (optional)
// 20240729 PowerFeather: Enabled battery temperature measurement, added specific configuration
// 20240730 PowerFeather: modified setSupplyMaintainVoltage()
// 20240804 PowerFeather: Added configuration of maximum battery charging current
//
// ToDo:
// -
Expand Down Expand Up @@ -231,6 +232,7 @@ AppLayer appLayer(&rtc, &rtcLastClockSync);
struct sPowerFeatherCfg PowerFeatherCfg = {
.battery_capacity = BATTERY_CAPACITY_MAH,
.supply_maintain_voltage = PF_SUPPLY_MAINTAIN_VOLTAGE,
.max_charge_current = PF_MAX_CHARGE_CURRENT_MAH,
.temperature_measurement = PF_TEMPERATURE_MEASUREMENT,
.battery_fuel_gauge = PF_BATTERY_FUEL_GAUGE
};
Expand Down Expand Up @@ -513,6 +515,7 @@ void setup()
Board.setSupplyMaintainVoltage(PowerFeatherCfg.supply_maintain_voltage); // Set supply maintain voltage
}
Board.enableBatteryCharging(true); // Enable battery charging
Board.setBatteryChargingMaxCurrent(PowerFeatherCfg.max_charge_current); // Set max charging current
#endif

#if defined(ARDUINO_ARCH_RP2040)
Expand Down
3 changes: 3 additions & 0 deletions BresserWeatherSensorLWCfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
// 20240726 Renamed BATTERY_DISCHARGE_LIMIT/BATTERY_CHARGE_LIMIT
// 20240729 Added PowerFeather specific configuration
// 20240730 Modified PF_SUPPLY_MAINTAIN_VOLTAGE
// 20240804 PowerFeather: Added configuration of max. battery charging current
//
// Note:
// Depending on board package file date, some defines are written either
Expand Down Expand Up @@ -103,6 +104,7 @@ struct sPowerFeatherCfg {

uint16_t battery_capacity; /// Battery capacity in mAh
uint16_t supply_maintain_voltage; /// Supply voltage to maintain in mV
uint16_t max_charge_current; /// Maximum charging current in mA
bool temperature_measurement; /// Enable temperature measurement
bool battery_fuel_gauge; /// Enable battery fuel gauge
};
Expand Down Expand Up @@ -222,6 +224,7 @@ const uint8_t MAX_DOWNLINK_SIZE = 51;
#define PF_TEMPERATURE_MEASUREMENT true // enable/diable temperature measurement
#define PF_SUPPLY_MAINTAIN_VOLTAGE 0 // ~maximum power point (MPP) voltage if using a solar panel; 0: disabled
#define PF_BATTERY_FUEL_GAUGE true // enable/disable battery fuel gauge
#define PF_MAX_CHARGE_CURRENT_MAH 50 // maximum charging current in mA
#if BATTERY_CAPACITY_MAH == 0
#pragma message("Battery capacity set to 0 - battery voltage measurement disabled.")
#endif
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ Create an account and set up a device configuration in your LoRaWAN network prov
| `PF_TEMPERATURE_MEASUREMENT` / <br>`powerfeather/temperature_measurement` | see [https://docs.powerfeather.dev](https://docs.powerfeather.dev) | X | | X |
| `PF_BATTERY_FUEL_GAUGE` / <br>`powerfeather/battery_fuel_gauge` | see [https://docs.powerfeather.dev](https://docs.powerfeather.dev) | X | | X |
| `PF_SUPPLY_MAINTAIN_VOLTAGE` / <br>`powerfeather/supply_maintain_voltage` | see [https://docs.powerfeather.dev](https://docs.powerfeather.dev) | X | | X |

| `PF_MAX_CHARGE_CURRENT_MAH` / <br>`powerfeather/max_charge_current` | see [https://docs.powerfeather.dev](https://docs.powerfeather.dev) | X | | X |

### Enabling Debug Output

Expand Down Expand Up @@ -711,6 +711,7 @@ The following parameters are available:
| powerfeather/ | PowerFeather specific (see [https://docs.powerfeather.dev](https://docs.powerfeather.dev)) | |
| &nbsp;&nbsp;battery_capacity | Battery capacity in mAh<br>(`0`: no battery connected)<br>see [PowerFeather Docs: `init()`](https://docs.powerfeather.dev/sdk/api/mainboard#result-inituint16_t-capacity--0-batterytype-type--batterytypegeneric_3v7) | `0` |
| &nbsp;&nbsp;supply_maintain_voltage | see [PowerFeather Docs: `setSupplyMaintainVoltage()`](https://docs.powerfeather.dev/sdk/api/mainboard#result-setsupplymaintainvoltageuint16_t-voltage)<br>`0`: not set | `0` |
| &nbsp;&nbsp;max_charge_current | see [PowerFeather Docs: `setBatteryChargingMaxCurrent()`](https://docs.powerfeather.dev/sdk/api/mainboard##result-setbatterychargingmaxcurrentuint16_t-current) | `50` |
| &nbsp;&nbsp;temperature_measurement | see [PowerFeather Docs: `enableBatteryTempSense()`](https://docs.powerfeather.dev/sdk/api/mainboard#result-enablebatterytempsensebool-enable) | `true` |
| &nbsp;&nbsp;battery_fuel_gauge | see [PowerFeather Docs: `enableBatteryFuelGauge()`](https://docs.powerfeather.dev/sdk/api/mainboard#result-enablebatteryfuelgaugebool-enable) | `true` |

Expand Down
4 changes: 3 additions & 1 deletion data/node_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"battery_charge_lim": 4201,
"powerfeather": {
"battery_capacity": 2201,
"supply_maintain_voltage": 4600,
"max_charge_current": 50,
"temperature_measurement": true,
"battery_fuel_gauge": true
}
}
}
5 changes: 5 additions & 0 deletions src/LoadNodeCfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
//
// 20240725 Created
// 20240729 Added PowerFeather specific configuration
// 20240804 Added max_charge_current
//
// ToDo:
// -
Expand Down Expand Up @@ -103,6 +104,9 @@ void loadNodeCfg(
if (pf.containsKey("supply_maintain_voltage")) {
powerFeatherCfg.supply_maintain_voltage = pf["supply_maintain_voltage"];
}
if (pf.containsKey("max_charge_current")) {
powerFeatherCfg.max_charge_current = pf["max_charge_current"];
}
if (pf.containsKey("temperature_measurement")) {
powerFeatherCfg.temperature_measurement = pf["temperature_measurement"];
}
Expand All @@ -123,6 +127,7 @@ void loadNodeCfg(
log_d("PowerFeather");
log_d(" Battery capacity: %4d mAh", powerFeatherCfg.battery_capacity);
log_d(" Supply maintain voltage: %4d mV", powerFeatherCfg.supply_maintain_voltage);
log_d(" Max. charge current: %4d mA", powerFeatherCfg.max_charge_current);
log_d(" Temperature measurement: %s", powerFeatherCfg.temperature_measurement ? "true" : "false");
log_d(" Battery fuel gauge: %s", powerFeatherCfg.battery_fuel_gauge ? "true" : "false");
} // loadNodeCfg()
2 changes: 2 additions & 0 deletions src/LoadNodeCfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
//
// 20240725 Created
// 20240729 Added PowerFeather specific configuration
// 20240804 Added max_charge_current
//
// ToDo:
// -
Expand Down Expand Up @@ -64,6 +65,7 @@
* "powerfeather": {
* "battery_capacity":, 2200
* "supply_maintain_voltage": 5500,
* "max_charge_current": 50,
* "temperature_measurement": true,
* "battery_fuel_gauge": true
* }
Expand Down

0 comments on commit 24a6716

Please sign in to comment.