|
| 1 | +[Latest Release - ](https://github.com/Flowduino/LithiumPowered/releases/latest/) |
| 2 | + |
| 3 | +Need Help? [](https://discord.gg/jpwBy7VzaG) [](https://instagram.com/Flowduino) |
| 4 | + |
| 5 | +# LithiumPowered |
| 6 | +A (hopefully) Universal Library for Lithium-Powered Projects, designed to be available for both Arduino IDE and PlatformIO Projects. |
| 7 | + |
| 8 | +This Library uses a Coulomb Counter (*such as the LTC4150 circuit*) to accurately keep track of the state of specifically Lithium Ion (*Li-Ion*) and Lithium Polymer (*Li-Po*) Batteries. |
| 9 | + |
| 10 | +What makes this Library particularly beneficial is that it fully-encapsulates the code necessary to automatically and dynamically Calibrate the Battery Capacity (*in mAh*) while the Battery is Charging *and* Discharging. It also leverages persistent Storage on your MCU so that the Battery State is always remembered between power cycles (*switching your device off and on*) |
| 11 | + |
| 12 | +## Cross-Platform |
| 13 | +LithiumPowered is designed to function identically for all MCUs* and all Lithium Battery Types & Capacities**. |
| 14 | + |
| 15 | +>* *Must have suitable GPIO pins, support Interrupts (*ISR*), and provide some form of compatible persistent Storage (*e.g. EEPROM*). |
| 16 | +>* **You must configure your `Battery` instance by telling it the expected Capacity (*in mAh*) of your Lithium Cell(s) |
| 17 | +
|
| 18 | +## Easy Callbacks |
| 19 | +The operative Class, `Battery`, can be initialised with an Instance of your own custom decendant of `BatteryCallbacks`. Each method defined in `BatteryCallbacks` that you override in your decendant will be invokved as an *Event* reflecting the name of the respective overriden Method. |
| 20 | + |
| 21 | +e.g. |
| 22 | + |
| 23 | +```c++ |
| 24 | +class MyBatteryCallbacks: public BatteryCallbacks { |
| 25 | + public: |
| 26 | + void onBatteryNowCharging() { |
| 27 | + Serial.println("Battery is now Charging!"); |
| 28 | + } |
| 29 | + |
| 30 | + void onBatteryNowDischarging() { |
| 31 | + Serial.println("Battery is no longer Charging!"); |
| 32 | + } |
| 33 | +}; |
| 34 | +``` |
| 35 | + |
| 36 | +## GPIO Settings |
| 37 | +The operative Class, `Battery`, can be initialised with an Instance of your own custom decendant of `BatteryGPIO`. |
| 38 | +Each method defined in `BatteryGPIO` that you override in your decendant will define an explicit GPIO Pin to be used for the corresponding Coloumb Pin represented by the name of the respective overriden Method. |
| 39 | + |
| 40 | +e.g. |
| 41 | + |
| 42 | +```c++ |
| 43 | +class MyBatteryGPIO: public BatteryGPIO { |
| 44 | + uint8_t getPinInterrupt() { return 14; }; |
| 45 | +}; |
| 46 | +``` |
| 47 | +
|
| 48 | +The above will tell our `Battery` instance to use GPIO Pin 14 for the main Coloumb Counter Interrupt pin, rather than the default defined in the Base Class, `BatteryGPIO`. |
| 49 | +
|
| 50 | +## Initialising Battery |
| 51 | +
|
| 52 | +```c++ |
| 53 | +#include <LithiumPowered.h> |
| 54 | +
|
| 55 | +Battery myBattery(); |
| 56 | +
|
| 57 | +void setup() { |
| 58 | + Serial.begin(115200); |
| 59 | +
|
| 60 | + myBattery.setCallbacks(new MyBatteryCallbacks()); // Use your Custom Callbacks |
| 61 | + myBattery.setGpio(new MyBatteryGPIO()); // Use your Custom GPIO Settings |
| 62 | + // We would now change any Properties of myBattery as required |
| 63 | + myBattery.setup(); // This will Initialise our Battery instance with the given Property values |
| 64 | +}; |
| 65 | +
|
| 66 | +void loop() { |
| 67 | + myBattery.loop(); // We need to ensure we Loop our Battery Instance to update its State |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +With the above in place, we will now see lines appear in the Console Output each time we connect or disconnect (respectively) our Device to an external Power Supply. |
| 72 | + |
| 73 | +**Note: If you are supplying power through the cable used to monitor Serial output, your Device will *always* be Charging!** |
0 commit comments