Battery voltage
What this example shows
Read the voltage of the Li-ion battery on the JST connector once and print it on the screen. Connect a battery for a meaningful reading.
Example code
"""Read the battery voltage."""
# Include needed libraries
from inkplate7spectra import Inkplate
# Creates an Inkplate object
inkplate = Inkplate()
# Initialize the display, needs to be called only once
inkplate.begin()
# Get the battery reading as a string
battery = str(inkplate.read_battery())
# Set text size to double from the original size, so we can see the text better
inkplate.set_text_size(2)
# Print the text at coordinates 100,100 (from the upper left corner)
inkplate.print_text(100, 100, "Battery voltage: " + battery + "V")
# Show it on the display
inkplate.display()
Functions used
Inkplate()returns InkplateCreates the display object from the inkplate7spectra module.
ReturnsThe display object.
inkplate.begin()returns boolSets up the board, the battery ADC on IO1 included, and a white frame buffer. Call it once.
ReturnsTrue.
inkplate.read_battery()returns floatSwitches on the battery measurement divider with GPIO expander pin P1-1, reads the ADC on IO1, switches the divider off and converts the reading to volts.
ReturnsBattery voltage in volts.
inkplate.set_text_size(s)returns NoneSets the text scale factor, here 2.
ReturnsNothing.
inkplate.print_text(x, y, s)returns NoneDraws text at (x, y) in the current size and color, without moving the cursor.
ReturnsNothing.
inkplate.display(leave_on=False)returns NoneSends the frame buffer to the panel and refreshes it.
ReturnsNothing.
What to expect
After the refresh, the screen shows Battery voltage: followed by the reading and V, in black at (100, 100). The script reads the battery once; run it again for a new reading. Nothing is printed in the shell.
🔗Open the complete example
examples/inkplate7spectra/battery_read.py