Skip to main content

Battery voltage

What this example shows​

Read the voltage of the Li-ion battery on the JST connector and show it next to a battery symbol, every 10 seconds. You need a battery connected for a meaningful reading. The symbol comes from battSymbol.h in the example folder.

Example code​

Select Board
Inkplate7SPECTRA_Read_Battery_Voltage.ino
#include "Inkplate.h" // Include Inkplate library to the sketch
#include "battSymbol.h" // Include the battery voltage bitmap
// It is in same folder as this sketch. You can even open it (read it) by clicking on battSymbol.h tab in Arduino IDE
Inkplate display; // Create an object on Inkplate library

void setup()
{
display.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
Serial.begin(115200);
}

void loop()
{
float voltage = display.readBattery(); // Read battery voltage
display.clearDisplay(); // Clear everything in frame buffer of e-paper display
display.drawBitmap(100, 100, battSymbol, battSymbol_w, battSymbol_h,
INKPLATE_BLUE); // Draw battery symbol at position X=100 Y=100
display.setCursor(210, 120);
display.setTextColor(INKPLATE_BLUE);
display.setTextSize(2);
display.print(voltage, 2); // Print battery voltage
display.print('V');
display.display(); // Send everything to display (refresh the screen)*/
delay(10000); // Wait 10 seconds before new measurement
}

Functions used​

Inkplate()returns None

Creates the Inkplate object. Inkplate 7SPECTRA has a single six-color mode, so the constructor takes no mode argument.

ReturnsConstructor; no return value.

display.begin()returns void

Initializes the library, the peripherals and the frame buffer. Call it once in setup().

ReturnsNothing.

display.readBattery()returns double

Switches on the battery measurement divider through GPIO expander pin P1-1, reads IO1 at 12-bit resolution, switches the divider off again and converts the reading. The divider halves the battery voltage, and the function scales it back.

ReturnsBattery voltage in volts.

display.clearDisplay()returns void

Fills the frame buffer with white. It does not change the panel.

ReturnsNothing.

display.drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h, uint16_t color)returns void

Draws a 1-bit bitmap with its top-left corner at (x, y), here the battery symbol in blue. From the Adafruit GFX class.

ReturnsNothing.

display.setCursor(int16_t x, int16_t y)returns void

Sets where the next printed text starts.

ReturnsNothing.

display.setTextColor(uint16_t c)returns void

Sets the text color, here INKPLATE_BLUE.

ReturnsNothing.

display.setTextSize(uint8_t s)returns void

Sets the text magnification, here 2.

ReturnsNothing.

display.print(value, digits)returns size_t

Prints into the frame buffer like Serial.print(). For a float, the second argument sets the number of decimals, here 2.

ReturnsNumber of bytes printed.

display.display(bool _leaveOn = 0)returns void

Sends the whole frame buffer to the panel and refreshes it.

ReturnsNothing.

What to expect​

A blue battery symbol appears near the top-left corner with the battery voltage beside it in blue, two decimals and a V. The reading updates every 10 seconds, each time with a full refresh. The sketch starts Serial but prints nothing to it.

🔗Open the complete example

examples/Inkplate7SPECTRA/Advanced/Other/Inkplate7SPECTRA_Read_Battery_Voltage

→