### Set and Get Reset Voltage Threshold Source: https://context7.com/adafruit/adafruit_max1704x/llms.txt Configure the voltage threshold for battery removal/replacement detection. The default is 3.0 V, with a resolution of 40 mV/LSB and a valid range of 0–5.08 V. ```cpp void setup() { Serial.begin(115200); while (!Serial) delay(10); while (!maxlipo.begin()) { delay(2000); } // Lower the reset threshold for deeply discharged batteries maxlipo.setResetVoltage(2.5); Serial.print("Reset voltage set to: "); Serial.print(maxlipo.getResetVoltage()); // e.g., "2.50" Serial.println(" V"); } ``` -------------------------------- ### Reset Voltage Threshold Source: https://context7.com/adafruit/adafruit_max1704x/llms.txt Functions to get or set the voltage threshold that triggers a battery removal/replacement event. The default is 3.0 V. ```APIDOC ## `setResetVoltage()` / `getResetVoltage()` — Reset Voltage Threshold Gets or sets the voltage threshold below which the IC treats the condition as a battery removal/replacement event. Default is 3.0 V. Resolution is 40 mV/LSB; valid range is 0–5.08 V. ```cpp void setup() { Serial.begin(115200); while (!Serial) delay(10); while (!maxlipo.begin()) { delay(2000); } // Lower the reset threshold for deeply discharged batteries maxlipo.setResetVoltage(2.5); Serial.print("Reset voltage set to: "); Serial.print(maxlipo.getResetVoltage()); // e.g., "2.50" Serial.println(" V"); } ``` ``` -------------------------------- ### begin() — Initialize the Device Source: https://context7.com/adafruit/adafruit_max1704x/llms.txt Initializes I2C communication, verifies device presence, checks for battery connection, resets the IC, and disables sleep mode. Returns false if the chip cannot be found or no battery is connected. ```APIDOC ## begin() ### Description Initializes I2C communication, verifies the device is present and a battery is attached, resets the IC, and disables sleep mode. Returns `false` if the chip cannot be found (e.g., no battery connected). ### Method `bool begin()` ### Return Value - `true` if initialization is successful. - `false` if the device cannot be found or no battery is connected. ``` -------------------------------- ### Initialize MAX17048 Device Source: https://context7.com/adafruit/adafruit_max1704x/llms.txt Sets up I2C communication and verifies device and battery presence. Returns false if the chip cannot be found. Requires Adafruit BusIO library. ```cpp #include "Adafruit_MAX1704X.h" Adafruit_MAX17048 maxlipo; void setup() { Serial.begin(115200); while (!Serial) delay(10); // begin() returns false if device not found or battery not connected while (!maxlipo.begin()) { Serial.println("Couldn't find MAX17048 — make sure a battery is plugged in!"); delay(2000); } Serial.println("MAX17048 initialized successfully!"); Serial.print("Chip ID: 0x"); Serial.println(maxlipo.getChipID(), HEX); // e.g., "0x00" Serial.print("IC Version: 0x"); Serial.println(maxlipo.getICversion(), HEX); // e.g., "0x0010" } ``` -------------------------------- ### Enable and Use Ultra-Low-Power Sleep Mode Source: https://context7.com/adafruit/adafruit_max1704x/llms.txt Enable and enter a sleep mode that draws approximately 1 µA. `enableSleep(true)` must be called before `sleep(true)` can take effect. `begin()` disables sleep by default. ```cpp void setup() { Serial.begin(115200); while (!Serial) delay(10); while (!maxlipo.begin()) { delay(2000); } // Enable and enter 1uA ultra-low-power sleep mode maxlipo.enableSleep(true); maxlipo.sleep(true); Serial.println("MAX17048 is now sleeping (~1uA)"); delay(10000); // sleep for 10 seconds // Wake up and re-enable normal measurements maxlipo.sleep(false); Serial.println("MAX17048 awake"); Serial.print("Voltage: "); Serial.print(maxlipo.cellVoltage(), 3); Serial.println(" V"); } ``` -------------------------------- ### Configure and Read Voltage Alert Thresholds Source: https://context7.com/adafruit/adafruit_max1704x/llms.txt Sets minimum and maximum cell voltage bounds to trigger an alert. Reads back the configured alert range. Resolution is 20 mV/LSB. ```cpp void setup() { Serial.begin(115200); while (!Serial) delay(10); while (!maxlipo.begin()) { delay(2000); } // Set alert range: trigger if voltage < 2.0V or > 4.2V maxlipo.setAlertVoltages(2.0, 4.2); float alert_min, alert_max; maxlipo.getAlertVoltages(alert_min, alert_max); Serial.print("Alert range: "); Serial.print(alert_min); // e.g., "2.00" Serial.print(" ~ "); Serial.print(alert_max); // e.g., "4.20" Serial.println(" V"); } ``` -------------------------------- ### Handle MAX1704x Alerts Source: https://context7.com/adafruit/adafruit_max1704x/llms.txt Check for active alerts, read alert status flags, and clear individual flags after handling. Ensure alerts are enabled in the IC for this to function. ```cpp void loop() { if (maxlipo.isActiveAlert()) { uint8_t flags = maxlipo.getAlertStatus(); Serial.print("ALERT! Status flags = 0x"); Serial.println(flags, HEX); if (flags & MAX1704X_ALERTFLAG_SOC_CHANGE) { Serial.println(" -> SOC changed by 1%"); maxlipo.clearAlertFlag(MAX1704X_ALERTFLAG_SOC_CHANGE); } if (flags & MAX1704X_ALERTFLAG_SOC_LOW) { Serial.println(" -> SOC critically low!"); maxlipo.clearAlertFlag(MAX1704X_ALERTFLAG_SOC_LOW); } if (flags & MAX1704X_ALERTFLAG_VOLTAGE_RESET) { Serial.println(" -> Voltage reset detected"); maxlipo.clearAlertFlag(MAX1704X_ALERTFLAG_VOLTAGE_RESET); } if (flags & MAX1704X_ALERTFLAG_VOLTAGE_LOW) { Serial.println(" -> Voltage too low"); maxlipo.clearAlertFlag(MAX1704X_ALERTFLAG_VOLTAGE_LOW); } if (flags & MAX1704X_ALERTFLAG_VOLTAGE_HIGH) { Serial.println(" -> Voltage too high"); maxlipo.clearAlertFlag(MAX1704X_ALERTFLAG_VOLTAGE_HIGH); } if (flags & MAX1704X_ALERTFLAG_RESET_INDICATOR) { Serial.println(" -> IC was reset"); maxlipo.clearAlertFlag(MAX1704X_ALERTFLAG_RESET_INDICATOR); } } delay(2000); } ``` -------------------------------- ### Configure Auto-Hibernation Thresholds Source: https://context7.com/adafruit/adafruit_max1704x/llms.txt Set thresholds for automatic hibernation. The IC enters hibernation if the charge rate is below `hibthresh` (%/hr) for 6 minutes and exits when voltage change exceeds `actthresh` (V). ```cpp void setup() { Serial.begin(115200); while (!Serial) delay(10); while (!maxlipo.begin()) { delay(2000); } // Auto-hibernate if charge rate < 5%/hr for 6 min; wake on >0.15V change maxlipo.setHibernationThreshold(5.0); // 5 %/hr maxlipo.setActivityThreshold(0.15); // 0.15 V change Serial.print("Hibernation threshold: "); Serial.print(maxlipo.getHibernationThreshold()); // e.g., "4.99 %/hr" Serial.println(" %/hr"); Serial.print("Activity threshold: "); Serial.print(maxlipo.getActivityThreshold()); // e.g., "0.15 V change" Serial.println(" V change"); } ``` -------------------------------- ### Trigger Quick SOC Auto-Calibration Source: https://context7.com/adafruit/adafruit_max1704x/llms.txt Triggers an immediate re-estimation of the state-of-charge. Use this after a known-good battery is connected, but not immediately after power-up or under heavy load to avoid inaccurate readings. ```cpp void setup() { Serial.begin(115200); while (!Serial) delay(10); while (!maxlipo.begin()) { delay(2000); } // Only call quickStart() after the battery has been connected and // the circuit is at rest — NOT immediately after powerup under load maxlipo.quickStart(); Serial.println("Quick start triggered — SOC re-estimated"); delay(500); // allow IC to settle Serial.print("SOC after quick start: "); Serial.print(maxlipo.cellPercent(), 1); Serial.println(" %"); } ``` -------------------------------- ### chargeRate() — Read Charge / Discharge Rate Source: https://context7.com/adafruit/adafruit_max1704x/llms.txt Reads and returns the rate at which the battery is charging or discharging in percent-per-hour (%/hr). Positive values indicate charging; negative values indicate discharging. Returns `NAN` if the rate cannot be read. ```APIDOC ## chargeRate() ### Description Returns the rate at which the battery is charging or discharging in percent-per-hour (%/hr). Positive values indicate charging; negative values indicate discharging. Resolution is 0.208%/hr per LSB. ### Method `float chargeRate()` ### Return Value - The charge/discharge rate in %/hr (float). - `NAN` if the rate cannot be read. ``` -------------------------------- ### Alert Handling Source: https://context7.com/adafruit/adafruit_max1704x/llms.txt Functions to check for active alerts, retrieve alert status flags, and clear individual alert flags. Includes constants for different alert conditions. ```APIDOC ## `isActiveAlert()` / `getAlertStatus()` / `clearAlertFlag()` — Alert Handling Checks whether any alert condition is active, reads the status register for the specific alert flags, and clears individual flags after handling. Six alert flag constants are defined: | Flag Constant | | Meaning | | `MAX1704X_ALERTFLAG_SOC_CHANGE` | State-of-charge changed by 1% | | `MAX1704X_ALERTFLAG_SOC_LOW` | SOC crossed the empty threshold | | `MAX1704X_ALERTFLAG_VOLTAGE_RESET` | Voltage dipped below reset threshold | | `MAX1704X_ALERTFLAG_VOLTAGE_LOW` | Voltage fell below alert minimum | | `MAX1704X_ALERTFLAG_VOLTAGE_HIGH` | Voltage rose above alert maximum | | `MAX1704X_ALERTFLAG_RESET_INDICATOR` | IC has been reset | ```cpp void loop() { if (maxlipo.isActiveAlert()) { uint8_t flags = maxlipo.getAlertStatus(); Serial.print("ALERT! Status flags = 0x"); Serial.println(flags, HEX); if (flags & MAX1704X_ALERTFLAG_SOC_CHANGE) { Serial.println(" -> SOC changed by 1%"); maxlipo.clearAlertFlag(MAX1704X_ALERTFLAG_SOC_CHANGE); } if (flags & MAX1704X_ALERTFLAG_SOC_LOW) { Serial.println(" -> SOC critically low!"); maxlipo.clearAlertFlag(MAX1704X_ALERTFLAG_SOC_LOW); } if (flags & MAX1704X_ALERTFLAG_VOLTAGE_RESET) { Serial.println(" -> Voltage reset detected"); maxlipo.clearAlertFlag(MAX1704X_ALERTFLAG_VOLTAGE_RESET); } if (flags & MAX1704X_ALERTFLAG_VOLTAGE_LOW) { Serial.println(" -> Voltage too low"); maxlipo.clearAlertFlag(MAX1704X_ALERTFLAG_VOLTAGE_LOW); } if (flags & MAX1704X_ALERTFLAG_VOLTAGE_HIGH) { Serial.println(" -> Voltage too high"); maxlipo.clearAlertFlag(MAX1704X_ALERTFLAG_VOLTAGE_HIGH); } if (flags & MAX1704X_ALERTFLAG_RESET_INDICATOR) { Serial.println(" -> IC was reset"); maxlipo.clearAlertFlag(MAX1704X_ALERTFLAG_RESET_INDICATOR); } } delay(2000); } ``` ``` -------------------------------- ### Control Forced Hibernation Mode Source: https://context7.com/adafruit/adafruit_max1704x/llms.txt Force the IC into or out of hibernation to reduce power consumption by slowing ADC sampling. `isHibernating()` checks the current state. ```cpp void setup() { Serial.begin(115200); while (!Serial) delay(10); while (!maxlipo.begin()) { delay(2000); } // Force hibernation to save power during idle periods maxlipo.hibernate(); Serial.print("Hibernating: "); Serial.println(maxlipo.isHibernating() ? "YES" : "NO"); // "YES" delay(5000); // Wake back up for normal operation maxlipo.wake(); Serial.print("Hibernating: "); Serial.println(maxlipo.isHibernating() ? "YES" : "NO"); // "NO" } ``` -------------------------------- ### Read Battery State of Charge Source: https://context7.com/adafruit/adafruit_max1704x/llms.txt Reads the battery state-of-charge as a percentage (0.0 to 100.0). Returns NAN if no battery is attached. Uses the IC's internal ModelGauge algorithm. ```cpp void loop() { float percent = maxlipo.cellPercent(); if (isnan(percent)) { Serial.println("Failed to read charge percent!"); delay(2000); return; } Serial.print("Battery Charge: "); Serial.print(percent, 1); // e.g., "72.3 %" Serial.println(" %"); delay(2000); } ``` -------------------------------- ### Read Charge / Discharge Rate Source: https://context7.com/adafruit/adafruit_max1704x/llms.txt Reads the rate of battery charging or discharging in percent-per-hour (%/hr). Positive values indicate charging, negative values indicate discharging. Resolution is 0.208%/hr per LSB. ```cpp void loop() { float rate = maxlipo.chargeRate(); if (isnan(rate)) { Serial.println("Failed to read charge rate!"); delay(2000); return; } Serial.print("Charge Rate: "); Serial.print(rate, 1); // e.g., "-12.5 %/hr" when discharging Serial.println(" %/hr"); delay(2000); } ``` -------------------------------- ### Auto-Hibernation Tuning Source: https://context7.com/adafruit/adafruit_max1704x/llms.txt Functions to configure automatic hibernation behavior. The IC enters hibernation if the charge rate stays below a threshold for a set duration and exits when voltage change exceeds another threshold. ```APIDOC ## `setActivityThreshold()` / `setHibernationThreshold()` — Auto-Hibernation Tuning Configures the automatic hibernation behavior. The IC enters hibernation if the charge rate stays below `hibthresh` (%/hr) for more than 6 minutes, and exits when the voltage change exceeds `actthresh` (V). ```cpp void setup() { Serial.begin(115200); while (!Serial) delay(10); while (!maxlipo.begin()) { delay(2000); } // Auto-hibernate if charge rate < 5%/hr for 6 min; wake on >0.15V change maxlipo.setHibernationThreshold(5.0); // 5 %/hr maxlipo.setActivityThreshold(0.15); // 0.15 V change Serial.print("Hibernation threshold: "); Serial.print(maxlipo.getHibernationThreshold()); // e.g., "4.99 %/hr" Serial.println(" %/hr"); Serial.print("Activity threshold: "); Serial.print(maxlipo.getActivityThreshold()); // e.g., "0.15 V change" Serial.println(" V change"); } ``` ``` -------------------------------- ### Ultra-Low-Power Sleep Mode Source: https://context7.com/adafruit/adafruit_max1704x/llms.txt Functions to enable or disable the sleep mode capability, which reduces power consumption to approximately 1 µA. `enableSleep(true)` must be called before `sleep(true)`. ```APIDOC ## `sleep()` / `enableSleep()` — Ultra-Low-Power Sleep Mode Enables or disables the sleep mode capability (draws only ~1 µA). `enableSleep(true)` must be called before `sleep(true)` can take effect. `begin()` calls `enableSleep(false)` by default to disable sleep on init. ```cpp void setup() { Serial.begin(115200); while (!Serial) delay(10); while (!maxlipo.begin()) { delay(2000); } // Enable and enter 1uA ultra-low-power sleep mode maxlipo.enableSleep(true); maxlipo.sleep(true); Serial.println("MAX17048 is now sleeping (~1uA)"); delay(10000); // sleep for 10 seconds // Wake up and re-enable normal measurements maxlipo.sleep(false); Serial.println("MAX17048 awake"); Serial.print("Voltage: "); Serial.print(maxlipo.cellVoltage(), 3); Serial.println(" V"); } ``` ``` -------------------------------- ### cellPercent() — Read Battery State of Charge Source: https://context7.com/adafruit/adafruit_max1704x/llms.txt Reads and returns the battery state-of-charge as a percentage (0.0 to 100.0). Returns `NAN` if no battery is attached. ```APIDOC ## cellPercent() ### Description Returns the battery state-of-charge as a float from 0.0 to 100.0 percent, derived from the IC's internal ModelGauge algorithm. Returns `NAN` if no battery is attached. ### Method `float cellPercent()` ### Return Value - The battery state-of-charge percentage (float). - `NAN` if no battery is attached. ``` -------------------------------- ### Forced Hibernation Mode Source: https://context7.com/adafruit/adafruit_max1704x/llms.txt Functions to force the IC into or out of hibernation mode to reduce power consumption by slowing ADC sampling. `isHibernating()` checks the current state. ```APIDOC ## `hibernate()` / `wake()` / `isHibernating()` — Forced Hibernation Mode Forces the IC into or out of hibernation mode, which reduces power consumption by slowing ADC sampling. `isHibernating()` returns `true` if the IC is currently hibernating. ```cpp void setup() { Serial.begin(115200); while (!Serial) delay(10); while (!maxlipo.begin()) { delay(2000); } // Force hibernation to save power during idle periods maxlipo.hibernate(); Serial.print("Hibernating: "); Serial.println(maxlipo.isHibernating() ? "YES" : "NO"); // "YES" delay(5000); // Wake back up for normal operation maxlipo.wake(); Serial.print("Hibernating: "); Serial.println(maxlipo.isHibernating() ? "YES" : "NO"); // "NO" } ``` ``` -------------------------------- ### setAlertVoltages() / getAlertVoltages() — Voltage Alert Thresholds Source: https://context7.com/adafruit/adafruit_max1704x/llms.txt Configures and retrieves the minimum and maximum cell voltage thresholds that trigger an alert. The ALRT pin goes low and the alert flag is set when the voltage falls below the minimum or rises above the maximum. ```APIDOC ## setAlertVoltages() / getAlertVoltages() ### Description Configures the minimum and maximum cell voltage bounds that will trigger an alert. Resolution is 20 mV/LSB. When the cell voltage falls below `minv` or rises above `maxv`, the ALRT pin goes low and the alert flag is set. ### Methods `void setAlertVoltages(float minv, float maxv)` `void getAlertVoltages(float &minv, float &maxv)` ### Parameters #### `setAlertVoltages` - **minv** (float) - Required - The minimum cell voltage threshold in Volts. - **maxv** (float) - Required - The maximum cell voltage threshold in Volts. #### `getAlertVoltages` - **minv** (float&) - Output - Reference to a float to store the minimum alert voltage. - **maxv** (float&) - Output - Reference to a float to store the maximum alert voltage. ``` -------------------------------- ### Read Battery Voltage Source: https://context7.com/adafruit/adafruit_max1704x/llms.txt Reads the current cell voltage in Volts. Returns NAN if no battery is attached. Resolution is 78.125 µV/LSB. ```cpp void loop() { float voltage = maxlipo.cellVoltage(); if (isnan(voltage)) { Serial.println("Failed to read cell voltage — check battery connection!"); delay(2000); return; } Serial.print("Battery Voltage: "); Serial.print(voltage, 3); // e.g., "3.854 V" Serial.println(" V"); delay(2000); } ``` -------------------------------- ### cellVoltage() — Read Battery Voltage Source: https://context7.com/adafruit/adafruit_max1704x/llms.txt Reads and returns the current battery cell voltage in Volts. Returns `NAN` if no battery is attached. ```APIDOC ## cellVoltage() ### Description Returns the current cell voltage in floating-point Volts. Resolution is 78.125 µV/LSB. Returns `NAN` if no battery is attached. ### Method `float cellVoltage()` ### Return Value - The current battery voltage in Volts (float). - `NAN` if no battery is attached. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.