As mentioned on the Pinouts page, six of the seven buttons on the Xteink X4 are connected to a resistor ladder read by two analog pins. The Xteink X4 helper library makes reading those buttons a lot easier. There's also a few helper functions for reading the battery voltage.
Library Usage with Web Workflow
To use with CircuitPython, you need to first install the Xteink X4 library into the lib folder on the Xteink X4. Then you need to update code.py with the example script.
Thankfully, we can do this in one go. In the example below, click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file.
# SPDX-FileCopyrightText: Copyright (c) 2026 Liz Clark for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
Xteink X4 Helper Demo
Uses button inputs and battery monitor
"""
from adafruit_xteink_x4 import BatteryMonitor, InputManager
battery = BatteryMonitor()
buttons = InputManager()
print(f"Battery: {battery.percentage}% ({battery.volts:.2f}V)")
print()
while True:
buttons.update()
if buttons.any_pressed:
for i in range(7):
if buttons.was_pressed(i):
print(f"Pressed: {buttons.button_name(i)}")
if buttons.any_released:
for i in range(7):
if buttons.was_released(i):
held = buttons.held_time
print(f"Released: {buttons.button_name(i)} (held {held:.2f}s)")
print(f"Battery: {battery.percentage}% ({battery.volts:.2f}V)")
Extract the contents of the zip file. You'll see the following contents in the extracted folder:
In the Web Workflow Code Editor, click the Open button.
Next, you'll upload the code.py file to the Xteink X4. Click the Upload button and then Upload Files.
After running the code, you'll see the battery voltage print out before going into the loop. In the loop, the button you press will print out to the serial monitor along with the battery voltage. You'll see the CircuitPython REPL on the eInk display.
Page last edited March 18, 2026
Text editor powered by tinymce.