基于ESP32和墨水屏的DIY电子阅读器制作全攻略Building a DIY E-Reader with ESP32 and E-Paper: A Complete Guide


AI free token/AI免费积分

基于ESP32和墨水屏的DIY电子阅读器制作全攻略

本文来源:https://www.hqwc.cn/a/1988241.html
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。

去年冬天翻抽屉,找出一台屏幕漏液的MP4,里面躺着几本年轻时没看完的电子书。我突然冒出个念头:现在主流阅读器动辄千元、功能堆得很多,但我真正需要的其实只是一块墨水屏、能传文件、能看书。于是就有了这个项目:用ESP32做主控、2.13寸墨水屏做显示,自己搭了一个支持局域网传书的电子阅读器,整套硬件成本控制在60元内,代码也开源了。

为什么选ESP32加墨水屏?很多人看到"电子阅读器"第一反应是STM32,毕竟低功耗、稳定。但这个项目要求"能传书",意味着要么有USB大容量存储,要么有网络,而STM32自身没有Wi-Fi,想联网就得外挂模块。ESP32则自带2.4GHz Wi-Fi和蓝牙、双核240MHz,跑一个Web服务器绰绰有余,开发板只要十几二十元。它还有520KB SRAM和4MB Flash,处理纯文本绰绰有余,相比之下ESP8266只有160KB SRAM。

屏幕是整个项目里最"叛逆"的选择。现在随便一台手机都是6.7寸、120Hz高刷,而2.13寸墨水屏只有约250×122像素。但它确实能看书:一屏大概能放10行中文、每行15个字左右,一本150页的书大约翻350到400页,对零散时间阅读完全够用。墨水屏有手机屏给不了的三个优势:类纸护眼、阳光下清晰、断电后画面依然保留。缺点是刷新要2到3秒,耐性要好;有条件建议换成2.9寸或4.2寸,代码逻辑完全不用改。

为什么不直接买台Kindle?我的回答是:DIY追求的不是"更好用",而是"可控"和"可玩"。Kindle传书多少依赖云服务,而自己做的阅读器完全本地、数据自主。把一块平平无奇的墨水屏模块和一粒ESP32芯片组合起来,变成一件每天愿意放在床头使用的物品,这种从零件到成品的过程,本身就是硬件DIY最大的乐趣。如果你只是为了读书,那直接买Kindle,省钱省心。

系统运行原理可以拆成四步:手机或电脑连接ESP32发出的Wi-Fi热点,在浏览器打开上传页,选择TXT文件通过HTTP POST上传,固件把文件保存到LittleFS或SD卡;墨水屏再读取文件内容、按页渲染,三个物理按键分别负责上一页、下一页和返回书库。这里面每一环都有细节:HTTP上传时WebServer库边收边写,不能等整个文件收完再写盘,因为ESP32内存放不下大文件;墨水屏显示也不能把整个TXT读进内存再排版,必须按行读取、按页渲染。

墨水屏的显示原理和手机屏完全不同。它内部有大量微胶囊,每个胶囊装着带正电的白色粒子和带负电的黑色粒子。施加电场时粒子朝不同方向移动,撤掉电场后粒子停在原地,形成稳定的黑白图像,这就是双稳态,也是断电后画面不消失的原因。驱动时先把图像按像素逐位写入驱动芯片的RAM,再发刷新命令,屏幕先清屏再逐行显示。SPI上传的是点阵数据,1bit代表一个像素。实际使用要分清全局刷新和局部刷新:全局刷新效果最好但每次要经历黑→白→出图,局部刷新快但久了会留残影。我的策略是翻页用局部刷新,每翻10页强制做一次全局刷新洗屏。

中文显示是这个项目里最容易被低估的坑。英文字母和数字用小点阵字库就能解决,但中文常用字有3000多个,全量字库体积不小,编码还得分UTF-8和GBK,处理不好就是满屏乱码。我踩了三个坎:第一必须统一编码,有些TXT是ANSI/GBK的,我写了脚本在电脑端统一转成UTF-8再上传;第二字库要选对,用u8g2的全中文字体效果好但占Flash,我把字体文件放在LittleFS里按需加载来省空间;第三渲染要逐字处理,把UTF-8字符串按字符解码、查点阵字库、拼到页面缓冲区,按行排满后交给驱动刷新。

硬件准备方面,物料清单包括ESP32 DevKitC V4开发板、2.13寸SSD1680驱动的墨水屏模块、轻触开关、可选的18650加TP4056供电,以及3D打印或亚克力外壳。采购时有个容易忽略的点:不同批次的屏幕分辨率甚至驱动芯片可能不一样,最好选明确标注同一款驱动的屏,否则GxEPD2库的驱动类要换。接线时墨水屏一般有8个引脚,VCC、GND、DIN、CLK、CS、DC、RST、BUSY,前4个和普通SPI设备一致,后3个是控制引脚,BUSY用来确认屏幕是否忙。VCC建议用3.3V,不要直接接5V。

供电我做了两版:第一版直接USB供电,充电宝插上就能用,简单但不便携;第二版换成18650锂电池加TP4056充电板,给ESP32的5V引脚供电。如果电池是2000mAh,理论续航很久,但墨水屏静态不耗电,ESP32一直开着Wi-Fi待机电流约80毫安,屏幕常亮大概能用一天多,解决办法是做深度睡眠。外壳我直接用3D打印做了个相框样的壳,没有打印机用亚克力板夹起来或硬纸板叠个空腔也行,毕竟是DIY。

写固件我用Arduino IDE,生态成熟、库好装。在开发板管理器地址里加入ESP32支持包JSON链接,安装后选择"ESP32 Dev Module"、Flash Size选4MB。因为传书需要文件系统、翻页要存进度,还要安装GxEPD2(墨水屏驱动)、U8g2_for_Adafruit_GFX(中文渲染)、ArduinoJson(保存进度)这些库。驱动墨水屏的核心是display.display(),它触发一次完整刷新;画图只是往缓冲区写数据,真正的电信号刷新由display()完成,所以要等2到3秒。传书的核心是ESP32上跑一个HTTP服务器,用WebServer库处理上传,关键点在UPLOAD_FILE_WRITE分支里必须立刻写入LittleFS,不能在RAM里攒着——我之前把一本800KB的书整个放进String,结果直接内存溢出重启。

状态管理上,我在LittleFS下建了/books目录存书,另建/settings.json保存当前书籍和页码。翻页时固件按当前页码去TXT里定位行号,因为每行长度不固定,只能从文件头逐行扫描计数,效率不高但偶尔翻页完全够用。renderPage函数把当前页的行文本渲染到缓冲区再调用display.display(),到文件末尾就限制页码。按键防抖用软件延时,不引入外部中断库。上传页面的HTML直接内联在固件里,一个小表单加文件选择框和提交按钮,再加已上传书籍列表,不需要外置HTML文件。

实战踩坑记录:第一版接线屏幕完全没反应,量电压3.3V正常、降SPI速度也不行,用放大镜看丝印才发现杜邦线在面包板上插偏了一格,CS和DC接反了。有一段时间屏幕刷新后有残影,根源是全程用局部刷新,电压波形比全局刷新弱,久了脏,解决思路是混合策略——平时局部刷新,每翻满一定页数强制全局刷新洗屏。中文乱码是因为有书是ANSI编码,最终在电脑端统一转UTF-8,固件里再做兼容:发现非法UTF-8字节就按GBK解码重编码。还有个大坑是一上传文件ESP32就反复重启,打印重启原因发现是Brownout detector触发——USB线太差,加上墨水屏刷新电流和Wi-Fi发射电流叠加把3.3V拉到阈值以下,换好线、给屏幕单独供电就解决了。

如果稳定性要求更高,可以给ESP32接LAN8720以太网模块走网线。我试过,方向可行但踩了三个坑:一是PHY地址默认由模块电阻决定,常见0或1,ETH.begin()没设对网络根本起不来;二是要连接复位引脚,把GPIO接到LAN8720的NRST,在ETH.begin()前先拉低再拉高;三是供电不足,LAN8720工作电流比想象大,最好单独一路3.3V稳压,不要和屏幕共用细杜邦线。代码开源在GitHub,核心文件包括主程序入口、墨水屏驱动配置、Web服务器逻辑、阅读器状态管理和文件系统工具;config.h放Wi-Fi热点名、密码和引脚定义,web.h是上传页和书籍列表的HTML模板,reader.h负责文本按页分割和翻页状态。

烧录时用Arduino IDE装好ESP32支持包和依赖库,打开.ino文件,在config.h里改成自己的屏幕型号和引脚,按住BOOT键插USB线,选对应串口点上传,完成后开串口监视器设波特率115200,看到IP或"AP Mode"就说明启动成功。要注意分区方案:因为要存书,文件系统至少1MB,我最终用的是"3MB No OTA / 1MB SPIFFS"。跑通后扩展方向很多:换2.9或4.2寸大屏体验质的提升;在settings.json多存几个书签加书签列表页;通过按键把选中句子写进notes.txt做摘录;或者外接MAX17048电量计芯片优化电源管理。最后体会是:这个项目一开始以为难点在墨水屏驱动,实际最花时间的是文本排版、文件管理和各种边缘情况——大文件、中文编码、断电重启,这些恰恰是嵌入式开发最考验人的部分。

Building a DIY E-Reader with ESP32 and E-Paper: A Complete Guide

本文来源:https://www.hqwc.cn/a/1988241.html
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。

Last winter, while rummaging through a drawer, I found an MP4 player with a cracked screen and a few ebooks I never finished. It occurred to me that mainstream e-readers cost a fortune and pile on features, while all I really wanted was an e-paper screen that could accept files and display text. That idea became this project: an ESP32 as the controller, a 2.13-inch e-paper display for output, and a home-built e-reader that supports LAN book uploads. The whole hardware build stayed under 60 yuan, and the code is open source.

Why ESP32 plus e-paper? Most people think of the STM32 first for an e-reader, given its low power and stability. But this project needs to "deliver books," which means either USB mass storage or networking, and the STM32 has no built-in Wi-Fi. The ESP32, by contrast, comes with 2.4GHz Wi-Fi and Bluetooth, a dual-core 240MHz CPU, and is more than capable of running a small web server, with boards costing just a couple of dollars. It also offers 520KB of SRAM and 4MB of Flash, plenty for plain text handling, while the ESP8266 has only 160KB of SRAM.

The screen was the most "rebellious" choice in the project. Any phone today is 6.7 inches with a 120Hz refresh, while a 2.13-inch e-paper panel has only about 250×122 pixels. Yet it works for reading: one screen holds roughly 10 lines of Chinese at 15 characters each, so a 150-page book takes about 350 to 400 page turns, plenty for fragmented reading. E-paper offers three advantages a phone screen cannot: paper-like eye comfort, clarity in sunlight, and an image that persists with power off. The downside is a 2-to-3-second refresh, so patience helps; if possible, upgrade to 2.9 or 4.2 inches without changing the code logic at all.

Why not just buy a Kindle? My answer is that DIY is not about being "more usable" but about being "controllable" and "fun." Getting books onto a Kindle depends somewhat on cloud services, whereas a home-built reader is entirely local and keeps your data yours. Combining an ordinary e-paper module and an ESP32 chip into something you actually keep by your bedside every day is, in itself, the greatest joy of hardware DIY. If you only want to read books, just buy a Kindle and save yourself the trouble.

The system works in four steps: your phone or laptop connects to the ESP32 Wi-Fi hotspot, you open an upload page in the browser, you select a TXT file to upload over HTTP POST, and the firmware saves it to LittleFS or an SD card. The e-paper display then reads the file, renders it page by page, and three physical buttons handle previous page, next page, and back to the bookshelf. Every step has its subtleties: the WebServer library writes chunks as they arrive rather than waiting for the whole file, since the ESP32 cannot hold a large book in memory; likewise the display must read and render line by line instead of loading the entire TXT at once.

E-paper works quite differently from a phone screen. It contains countless microcapsules, each holding positively charged white particles and negatively charged black ones. An electric field moves the particles in opposite directions, and once the field is removed they stay in place, forming a stable black-and-white image. This bistability is why the image survives power-off. To drive it, image bits are written into the controller RAM pixel by pixel, then a refresh command clears the screen and draws the new content row by row. SPI carries the bitmap data, one bit per pixel. In practice you must distinguish full refresh from partial refresh: full refresh gives the best quality but flashes black-white-image each time, while partial refresh is fast but leaves ghosting over time. My approach is partial refresh for page turns and a forced full refresh every ten pages to clean the screen.

Rendering Chinese is the most underestimated trap in this project. Latin letters and digits work with a tiny bitmap font, but there are over 3,000 common Chinese characters, a full font is large, and encoding must distinguish UTF-8 from GBK or you get gibberish. I hit three problems. First, unify encoding: some TXT files are ANSI/GBK, so I wrote a PC-side script to convert everything to UTF-8 before uploading. Second, choose the font carefully: u8g2 full Chinese fonts look great but consume Flash, so I stored the font file in LittleFS and load it on demand. Third, render character by character: decode the UTF-8 string, look up each glyph in the bitmap font, assemble it into the page buffer, and hand the filled lines to the driver for refresh.

On the hardware side, the bill of materials includes an ESP32 DevKitC V4 board, a 2.13-inch SSD1680-driven e-paper module, tactile switches, optional 18650 battery with a TP4056 charger, and a 3D-printed or acrylic case. One easily overlooked point: different batches of screens may have different resolutions or even driver chips, so buy a panel whose driver is clearly labeled, otherwise you must change the driver class in the GxEPD2 library. An e-paper module typically has eight pins: VCC, GND, DIN, CLK, CS, DC, RST, and BUSY. The first four match a normal SPI device, the rest are control pins, and BUSY tells the controller whether the screen is busy. Use 3.3V for VCC, never 5V directly.

I built two power versions: the first used plain USB, so a power bank worked immediately, simple but not portable; the second switched to an 18650 cell with a TP4056 charger feeding the ESP32 5V pin. A 2000mAh battery should theoretically last a long time, but while the panel consumes nothing statically, the ESP32 draws about 80mA with Wi-Fi on standby, so with the screen always updating it lasts a bit over a day. The fix is deep sleep. I 3D-printed a picture-frame-style case, but without a printer you can clamp two acrylic sheets or fold cardboard into a cavity; it is DIY after all.

I wrote the firmware in Arduino IDE, whose mature ecosystem and easy library installation win out. I added the ESP32 package JSON URL in the boards manager, then selected "ESP32 Dev Module" with 4MB Flash. Because book delivery needs a filesystem and page turns need saved progress, I installed GxEPD2 for the display, U8g2_for_Adafruit_GFX for Chinese rendering, and ArduinoJson for progress. The core of driving the panel is display.display(), which triggers a full refresh; drawing only writes to the buffer, and the actual electrical refresh happens in display(), hence the 2-to-3-second wait. Book delivery runs an HTTP server on the ESP32 using the WebServer library; the key is to write to LittleFS immediately in the UPLOAD_FILE_WRITE branch rather than buffering in RAM. I once put an entire 800KB book into a String and the chip promptly overflowed and rebooted.

For state management I created a /books directory in LittleFS for book files and a /settings.json for the current book and page number. On a page turn the firmware locates the target line in the TXT; since line lengths vary, it must scan from the start counting newlines, which is inefficient but fine for occasional turns. The renderPage function draws the current lines into the buffer and calls display.display(), clamping the page number at the end of the file. Button debouncing uses a software delay rather than an external interrupt library. The upload page HTML is inlined in the firmware: a small form, a file selector, a submit button, and a list of uploaded books, with no separate HTML file needed.

Debugging notes from the build: in the first wiring the screen showed nothing; voltage was a normal 3.3V and lowering SPI speed did not help, until a magnifier revealed a jumper wire one hole off on the breadcrumb board, swapping CS and DC. For a while the screen kept ghosting because I used partial refresh exclusively, whose waveform is weaker than full refresh; the fix was a hybrid strategy, partial refresh normally with a forced full refresh after a set number of turns. Chinese text came out garbled because some books were ANSI-encoded; I ended up converting everything to UTF-8 on the PC and adding firmware compatibility that decodes invalid UTF-8 bytes as GBK and re-encodes them. Another big trap was the ESP32 rebooting whenever a file upload started; the reset reason turned out to be a brownout detector, as a poor USB cable plus the display refresh current and Wi-Fi transmit current pulled 3.3V below threshold. A better cable and separate power for the screen solved it.

If you need more stability, you can add a LAN8720 Ethernet module and run a cable. I tried it; the direction works but has three traps. First, the PHY address is set by resistors on the module, commonly 0 or 1, and if ETH.begin() does not match it the network never comes up. Second, connect the reset pin: wire a GPIO to the LAN8720 NRST and pull it low then high before ETH.begin(). Third, power: the LAN8720 draws more current than expected, so give it a separate 3.3V regulator instead of sharing a thin jumper with the screen. The code is open source on GitHub, with core files for the main entry, display driver config, web server logic, reader state management, and filesystem utilities; config.h holds the hotspot name, password, and pin definitions, web.h the HTML templates for upload and book-list pages, and reader.h the page-splitting and turn-state logic.

To flash, install the ESP32 package and libraries in Arduino IDE, open the .ino file, edit config.h for your screen model and pins, hold BOOT while plugging in USB, pick the right serial port, and upload. Then open the serial monitor at 115200 baud; seeing an IP address or "AP Mode" means it booted. Watch the partition scheme: since you store books, the filesystem needs at least 1MB, and I settled on "3MB No OTA / 1MB SPIFFS." Once it runs, expansion options abound: swap in a 2.9 or 4.2-inch screen for a major upgrade; store several bookmarks in settings.json and add a bookmark list page; write selected sentences to notes.txt for excerpts via a button; or add a MAX17048 fuel gauge for better power management. My final takeaway: I expected the display driver to be the hard part, but the real time went into text layout, file management, and edge cases like large files, Chinese encoding, and power-loss restarts, exactly the parts that test an embedded developer most.

暂无评论,快来发表第一条评论吧!No comments yet. Be the first!

📮 需求咨询📮 Inquiry