A picture of me.

Tom Hodson

Maker, Baker Programmer Reformed Physicist


Micropython on an E-Reader

I travelled around the world last year, by land and sea, with just a backpack. When we got to Shenzen we wandered through the sprawling electronics markets, realising that these are the real life places that explain why aliexpress looks the way it does. But because of the packpack constraint I couldn’t really buy all the random dev boards that I perhaps wanted to!

IMG_3483

What I settled on getting was this incredibly cute e-reader, the XTEINK 4. Here’s mine on top of my beloved Kobo, which is my actual e-reader du jour.

A shot of a tiny e-reader (xteink x4) sitting on top of a larger green e-reader (a kobo in a case)  The smaller one is showing the opening line from pride and prejudice “it is a truth universally acknowledged that a single man  in possession of a good fortune must be in want of a wife.”

Reading online a bit, it sounds like the manufacturer has started to disable the USB JTAG interface needed to load custom firmware unless you shell out for the developer version. By a stroke of luck the one I picked had no such restriction or simply was the developer version being sold more cheaply in Shenzen than online.

For my first actual project I thought it we be fun to just put a load of images on the SD card and see how they look rendered on the monochrome display.

Flashing MicroPython

First I suggest you follow adafruit’s advice to backup the stock firmware and keep it somewhere safe:

esptool --chip esp32c3 --port /dev/cu.usbmodem101 read_flash 0x0 0x1000000 firmware_backup.bin
[abridged output]
Read 16777216 bytes from 0x00000000 in 60.2 seconds (2230.0 kbit/s) to 'firmware_backup.bin'.

While we’re here check the efuses, anything set not set to 0 is interesting.

espefuse --chip esp32c3 --port /dev/cu.usbmodem101 summary       

Then I followed the official micropython instructions here to put micropython on it. That’s as simple as esptool erase-flash followed by esptool.py --baud 460800 write_flash 0 ESP32_GENERIC_C3-20260824-v1.29.0.bin where that file is just whatever the latest micropython build for ESP32-C3 is.

The Hardware

Adafruit has already put circuitpython on the same hardware and it’s also supported by the very popular open source e-reader firmware crosspoint, so hardware details are quite easy to find online. To summarise it quickly here:

The device has a screen, an SD card slot, a battery and associated charging circuitry, two front buttons and two side buttons. Of the buttons three are connected to two analog inputs and are read out using a resistor ladder and one, the top side button, is directly connected to an interupt capable GPIO, only that last button can wake the device from sleep as far as I know.

The screen and SD card live on a shared SPI bus, copying and pasting from my later python code:

from machine import Pin

spi_miso = Pin(7)
spi_sck = Pin(8)
spi_mosi = Pin(10)

SPI buses use a chip select (CS) pin controlled by the host (esp32) which tells the peripherals (screen, sd card) which is currently active.

sdcard_cs = Pin(12)

The screen, in addition to its own CS pin, also needs a reset, busy and ‘dc’ pin which I assume stands for something like data/control and tells the screen whether the current data transfer should be interpreted as data or a command but I haven’t looked into it deeply.

screen_dc = Pin(4)
screen_rst = Pin(5)
screen_busy = Pin(6)
screen_cs = Pin(21)

The screen is a 800×480 monochrome e-ink display with an SSD1677 controller, the name of the controller is key when looking online for code to drive it. The display itself has model number GDEY0426T82.

There’s a voltage divider connecting the battery to pin 0 and another signal that pulls pin 20 high when a USB cable is plugged and the device is charging:

battery_voltage_divider = machine.ADC(Pin(0))
battery_charging_pin = Pin(20, Pin.IN)

Finally we have two analog inputs on pins 1 and 2 that can read three of the buttons, while the crucial wake from sleep power button is attached to pin 3, we enable a pullup because the button pulls that pin low when pressed.

buttons_divider_1 = machine.ADC(Pin(1))
buttons_divider_2 = machine.ADC(Pin(2))
power_button = Pin(3, Pin.IN, pull = Pin.PULL_UP)

With a bit of searching I find a single file SSD1677 driver written in micropython that I can just drop into the project.

I was a bit dissapointed to read that the official micropython SD card library does not support shared SPI buses, however a little bit more searching yields this single file SD library in the micropython project that seems to be perfectly hapy sharing the SPI bus.

With the previous in definitions we can initialise the SPI bus, screen and SD card like this:

import machine
from machine import Pin, SPI
from lib import sdcard
from lib import ssd1677

spi = machine.SPI(
    1,
    baudrate=4_000_000,
    polarity=0,
    phase=0,
    sck=spi_sck,
    mosi=spi_mosi,
    miso=spi_miso,
)

# sdcard using software driver from https://github.com/micropython/micropython-lib/blob/master/micropython/drivers/storage/sdcard/sdcard.py
sd = sdcard.SDCard(spi, sdcard_cs)

# Screen 800 x 400
screen = ssd1677.SSD1677(
    800,
    480,
    spi,
    dc=screen_dc,
    cs=screen_cs,
    rst=screen_rst,
    busy=screen_busy,
)

Preparing the Images

Here’s an image of me showing off some shelves I made:

from PIL import Image
im = Image.open("/Users/math/Desktop/Screenshot 2026-11-27 at 09.31.10.png")
im

And here’s that same image cropped to the aspect ratio of the e-reader, scaled down to 800x480 and 1 bit dithered, PIL uses floyd-steinberg dithering by default:

new_aspect = 800 / 480
crop_width = im.height / new_aspect
gap = (im.width - crop_width)/2

im = im.crop((gap, 0, crop_width+gap, im.height))
im = im.resize((480,800)).convert("1")
im

I wanted to copy the image bytes directly to the screen on the e-reader so I had to massage the data a little more. I ended up both inverting and transposing the data so that it would display correctly when copied straight to the framebuffer on the device.

im = PIL.ImageOps.invert(
	im.transpose(method=Image.Transpose.ROTATE_90)
)

with open("image.bin" "wb") as fout:
    fout.write(im.tobytes())

I did this to about 1000 images from a blog we wrote about the trip and dumped them to the sd card.

Since each pixel is 1 bit, we can (and thankfully PIL automatically does) pack 8 pixels into a byte, meaning each image weighs in at 480 * 800 / 8 or about 47kB.

On the e-reader itself I wrote some code to display a random image whenever it gets woken from sleep and then go back to sleep. I put the code I showed before in a companion file called board.py.

# companion file defined above
import board
from board import screen 

import random
import framebuf
import machine
import esp32
import os

# Tell the esp32 to wake from deeplseep if the power button is pressed
esp32.wake_on_gpio((board.power_button,), esp32.WAKEUP_ALL_LOW)

# mount the sdcard
vfs.mount(board.sd, "/sd")

# Choose a random image
# If you had fewer image you could use os.lsdir here instead
i = random.randrange(1116)
img = f"/sd/raw/{i}.bin"
file = open(img, "rb")

# Read the image bytes directly into the screen buffer
file.readinto(board.screen.buffer)

# Also write some debug text
screen.rect(0, 0, 80, 20, 0, True)
screen.text(
    f"{board.battery_percentage()}% {i}",
    10,
    10,
    1,
)
screen.show()
machine.deepsleep(5 * 60 * 1000)

IMG_5876 Large

The one thing that I couldn’t get to work was waking from deep sleep on a timer. In principle that line machine.deepsleep(5 * 60 * 1000) should mean the board wakes up on it’s own every five minutes, however for that only ever works when the board is plugged in, if I unplug it, the power button still wakes it from sleep but it won’t wake by itself.

I wonder is that’s related to some brownout issue on the way the power domains of the ESP32C3 are set up on this device, I’m not sure.

Appendix

Here are the efuses and security settings for my device should it prove useful to someone else.

>>>esptool --chip esp32c3 --port /dev/cu.usbmodem101 --baud 115200  get-security-info
esptool v5.3.0
Connected to ESP32-C3 on /dev/cu.usbmodem101:
Chip type:          ESP32-C3 (QFN32) (revision v0.4)
Features:           Wi-Fi, BT 5 (LE), Single Core, 160MHz
Crystal frequency:  40MHz
USB mode:           USB-Serial/JTAG
MAC:                38:44:be:98:9a:34

Stub flasher running.

Security Information:
=====================
Flags: 0x00000000 (0b0)
Key Purposes: (0, 0, 0, 0, 0, 0, 12)
  BLOCK_KEY0 - USER/EMPTY
  BLOCK_KEY1 - USER/EMPTY
  BLOCK_KEY2 - USER/EMPTY
  BLOCK_KEY3 - USER/EMPTY
  BLOCK_KEY4 - USER/EMPTY
  BLOCK_KEY5 - USER/EMPTY
Chip ID: 5
API Version: 3
Secure Boot: Disabled
Flash Encryption: Disabled
SPI Boot Crypt Count (SPI_BOOT_CRYPT_CNT): 0x0

Hard resetting via RTS pin...
espefuse --chip esp32c3 --port /dev/cu.usbmodem101 summary       
espefuse v5.3.0
Connecting...

=== Run "summary" command ===
EFUSE_NAME (Block) Description  = [Meaningful Value] [Readable/Writeable] (Hex Value)
----------------------------------------------------------------------------------------
Calibration fuses:
K_RTC_LDO (BLOCK1)                                 BLOCK1 K_RTC_LDO                                   = -8 R/W (0b1000010)
K_DIG_LDO (BLOCK1)                                 BLOCK1 K_DIG_LDO                                   = -44 R/W (0b1001011)
V_RTC_DBIAS20 (BLOCK1)                             BLOCK1 voltage of rtc dbias20                      = 20 R/W (0x05)
V_DIG_DBIAS20 (BLOCK1)                             BLOCK1 voltage of digital dbias20                  = -32 R/W (0x88)
DIG_DBIAS_HVT (BLOCK1)                             BLOCK1 digital dbias when hvt                      = -24 R/W (0b10110)
THRES_HVT (BLOCK1)                                 BLOCK1 pvt threshold when hvt                      = 1800 R/W (0b0111000010)
TEMP_CALIB (BLOCK2)                                Temperature calibration data                       = -19.6 R/W (0b111000100)
OCODE (BLOCK2)                                     ADC OCode                                          = 80 R/W (0x50)
ADC1_INIT_CODE_ATTEN0 (BLOCK2)                     ADC1 init code at atten0                           = 1644 R/W (0b0110011011)
ADC1_INIT_CODE_ATTEN1 (BLOCK2)                     ADC1 init code at atten1                           = -180 R/W (0b1000101101)
ADC1_INIT_CODE_ATTEN2 (BLOCK2)                     ADC1 init code at atten2                           = -280 R/W (0b1001000110)
ADC1_INIT_CODE_ATTEN3 (BLOCK2)                     ADC1 init code at atten3                           = -756 R/W (0b1010111101)
ADC1_CAL_VOL_ATTEN0 (BLOCK2)                       ADC1 calibration voltage at atten0                 = -460 R/W (0b1001110011)
ADC1_CAL_VOL_ATTEN1 (BLOCK2)                       ADC1 calibration voltage at atten1                 = -244 R/W (0b1000111101)
ADC1_CAL_VOL_ATTEN2 (BLOCK2)                       ADC1 calibration voltage at atten2                 = -460 R/W (0b1001110011)
ADC1_CAL_VOL_ATTEN3 (BLOCK2)                       ADC1 calibration voltage at atten3                 = -596 R/W (0b1010010101)

Config fuses:
WR_DIS (BLOCK0)                                    Disable programming of individual eFuses           = 0 R/W (0x00000000)
RD_DIS (BLOCK0)                                    Disable reading from BlOCK4-10                     = 0 R/W (0b0000000)
DIS_ICACHE (BLOCK0)                                Set this bit to disable Icache                     = False R/W (0b0)
DIS_TWAI (BLOCK0)                                  Set this bit to disable CAN function               = False R/W (0b0)
DIS_DIRECT_BOOT (BLOCK0)                           Disable direct boot mode                           = False R/W (0b0)
UART_PRINT_CONTROL (BLOCK0)                        Set the default UARTboot message output mode       = Enable R/W (0b00)
ERR_RST_ENABLE (BLOCK0)                            Use BLOCK0 to check error record registers         = with check R/W (0b1)
BLOCK_USR_DATA (BLOCK3)                            User data                                         
   = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 R/W 
BLOCK_SYS_DATA2 (BLOCK10)                          System data part 2 (reserved)                     
   = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 R/W 

Flash fuses:
FLASH_TPUW (BLOCK0)                                Configures flash waiting time after power-up; in u = 0 R/W (0x0)
                                                   nit of ms. If the value is less than 15; the waiti
                                                   ng time is the configurable value; Otherwise; the 
                                                   waiting time is twice the configurable value      
FORCE_SEND_RESUME (BLOCK0)                         Set this bit to force ROM code to send a resume co = False R/W (0b0)
                                                   mmand during SPI boot                             
FLASH_CAP (BLOCK1)                                 Flash capacity                                     = None R/W (0b000)
FLASH_TEMP (BLOCK1)                                Flash temperature                                  = None R/W (0b00)
FLASH_VENDOR (BLOCK1)                              Flash vendor                                       = None R/W (0b000)

Identity fuses:
DISABLE_WAFER_VERSION_MAJOR (BLOCK0)               Disables check of wafer version major              = False R/W (0b0)
DISABLE_BLK_VERSION_MAJOR (BLOCK0)                 Disables check of blk version major                = False R/W (0b0)
WAFER_VERSION_MINOR_LO (BLOCK1)                    WAFER_VERSION_MINOR least significant bits         = 4 R/W (0b100)
PKG_VERSION (BLOCK1)                               Package version                                    = 0 R/W (0b000)
BLK_VERSION_MINOR (BLOCK1)                         BLK_VERSION_MINOR                                  = 3 R/W (0b011)
WAFER_VERSION_MINOR_HI (BLOCK1)                    WAFER_VERSION_MINOR most significant bit           = False R/W (0b0)
WAFER_VERSION_MAJOR (BLOCK1)                       WAFER_VERSION_MAJOR                                = 0 R/W (0b00)
OPTIONAL_UNIQUE_ID (BLOCK2)                        Optional unique 128-bit ID                        
   = 99 3d cc 43 bb b8 b3 49 e2 c3 26 f2 b9 a2 78 0d R/W 
BLK_VERSION_MAJOR (BLOCK2)                         BLK_VERSION_MAJOR of BLOCK2                        = With calibration R/W (0b01)
WAFER_VERSION_MINOR (BLOCK0)                       calc WAFER VERSION MINOR = WAFER_VERSION_MINOR_HI  = 4 R/W (0x4)
                                                   << 3 + WAFER_VERSION_MINOR_LO (read only)         

Jtag fuses:
SOFT_DIS_JTAG (BLOCK0)                             Set these bits to disable JTAG in the soft way (od = 0 R/W (0b000)
                                                   d number 1 means disable ). JTAG can be enabled in
                                                    HMAC module                                      
DIS_PAD_JTAG (BLOCK0)                              Set this bit to disable JTAG in the hard way. JTAG = False R/W (0b0)
                                                    is disabled permanently                          

Mac fuses:
MAC (BLOCK1)                                       MAC address                                       
   = 38:44:be:98:9a:34 (OK) R/W 
CUSTOM_MAC (BLOCK3)                                Custom MAC address                                
   = 00:00:00:00:00:00 (OK) R/W 

Security fuses:
DIS_DOWNLOAD_ICACHE (BLOCK0)                       Set this bit to disable Icache in download mode (b = False R/W (0b0)
                                                   oot_mode[3:0] is 0; 1; 2; 3; 6; 7)                
DIS_FORCE_DOWNLOAD (BLOCK0)                        Set this bit to disable the function that forces c = False R/W (0b0)
                                                   hip into download mode                            
DIS_DOWNLOAD_MANUAL_ENCRYPT (BLOCK0)               Set this bit to disable flash encryption when in d = False R/W (0b0)
                                                   ownload boot modes                                
SPI_BOOT_CRYPT_CNT (BLOCK0)                        Enables flash encryption when 1 or 3 bits are set  = Disable R/W (0b000)
                                                   and disables otherwise                            
SECURE_BOOT_KEY_REVOKE0 (BLOCK0)                   Revoke 1st secure boot key                         = False R/W (0b0)
SECURE_BOOT_KEY_REVOKE1 (BLOCK0)                   Revoke 2nd secure boot key                         = False R/W (0b0)
SECURE_BOOT_KEY_REVOKE2 (BLOCK0)                   Revoke 3rd secure boot key                         = False R/W (0b0)
KEY_PURPOSE_0 (BLOCK0)                             Purpose of Key0                                    = USER R/W (0x0)
KEY_PURPOSE_1 (BLOCK0)                             Purpose of Key1                                    = USER R/W (0x0)
KEY_PURPOSE_2 (BLOCK0)                             Purpose of Key2                                    = USER R/W (0x0)
KEY_PURPOSE_3 (BLOCK0)                             Purpose of Key3                                    = USER R/W (0x0)
KEY_PURPOSE_4 (BLOCK0)                             Purpose of Key4                                    = USER R/W (0x0)
KEY_PURPOSE_5 (BLOCK0)                             Purpose of Key5                                    = USER R/W (0x0)
SECURE_BOOT_EN (BLOCK0)                            Set this bit to enable secure boot                 = False R/W (0b0)
SECURE_BOOT_AGGRESSIVE_REVOKE (BLOCK0)             Set this bit to enable revoking aggressive secure  = False R/W (0b0)
                                                   boot                                              
DIS_DOWNLOAD_MODE (BLOCK0)                         Set this bit to disable download mode (boot_mode[3 = False R/W (0b0)
                                                   :0] = 0; 1; 2; 3; 6; 7)                           
ENABLE_SECURITY_DOWNLOAD (BLOCK0)                  Set this bit to enable secure UART download mode   = False R/W (0b0)
SECURE_VERSION (BLOCK0)                            Secure version (used by ESP-IDF anti-rollback feat = 0 R/W (0x0000)
                                                   ure)                                              
BLOCK_KEY0 (BLOCK4)
  Purpose: USER
               Key0 or user data                                 
   = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 R/W 
BLOCK_KEY1 (BLOCK5)
  Purpose: USER
               Key1 or user data                                 
   = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 R/W 
BLOCK_KEY2 (BLOCK6)
  Purpose: USER
               Key2 or user data                                 
   = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 R/W 
BLOCK_KEY3 (BLOCK7)
  Purpose: USER
               Key3 or user data                                 
   = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 R/W 
BLOCK_KEY4 (BLOCK8)
  Purpose: USER
               Key4 or user data                                 
   = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 R/W 
BLOCK_KEY5 (BLOCK9)
  Purpose: USER
               Key5 or user data                                 
   = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 R/W 

Spi Pad fuses:
SPI_PAD_CONFIG_CLK (BLOCK1)                        SPI PAD CLK                                        = 0 R/W (0b000000)
SPI_PAD_CONFIG_Q (BLOCK1)                          SPI PAD Q(D1)                                      = 0 R/W (0b000000)
SPI_PAD_CONFIG_D (BLOCK1)                          SPI PAD D(D0)                                      = 0 R/W (0b000000)
SPI_PAD_CONFIG_CS (BLOCK1)                         SPI PAD CS                                         = 0 R/W (0b000000)
SPI_PAD_CONFIG_HD (BLOCK1)                         SPI PAD HD(D3)                                     = 0 R/W (0b000000)
SPI_PAD_CONFIG_WP (BLOCK1)                         SPI PAD WP(D2)                                     = 0 R/W (0b000000)
SPI_PAD_CONFIG_DQS (BLOCK1)                        SPI PAD DQS                                        = 0 R/W (0b000000)
SPI_PAD_CONFIG_D4 (BLOCK1)                         SPI PAD D4                                         = 0 R/W (0b000000)
SPI_PAD_CONFIG_D5 (BLOCK1)                         SPI PAD D5                                         = 0 R/W (0b000000)
SPI_PAD_CONFIG_D6 (BLOCK1)                         SPI PAD D6                                         = 0 R/W (0b000000)
SPI_PAD_CONFIG_D7 (BLOCK1)                         SPI PAD D7                                         = 0 R/W (0b000000)

Usb fuses:
DIS_USB_JTAG (BLOCK0)                              Set this bit to disable function of usb switch to  = False R/W (0b0)
                                                   jtag in module of usb device                      
DIS_USB_SERIAL_JTAG (BLOCK0)                       USB-Serial-JTAG                                    = Enable R/W (0b0)
USB_EXCHG_PINS (BLOCK0)                            Set this bit to exchange USB D+ and D- pins        = False R/W (0b0)
DIS_USB_SERIAL_JTAG_ROM_PRINT (BLOCK0)             USB printing                                       = Enable R/W (0b0)
DIS_USB_SERIAL_JTAG_DOWNLOAD_MODE (BLOCK0)         Disable UART download mode through USB-Serial-JTAG = False R/W (0b0)

Vdd fuses:
VDD_SPI_AS_GPIO (BLOCK0)                           Set this bit to vdd spi pin function as gpio       = False R/W (0b0)

Wdt fuses:
WDT_DELAY_SEL (BLOCK0)                             RTC watchdog timeout threshold; in unit of slow cl = 40000 R/W (0b00)
                                                   ock cycle