ESP32驱动墨水屏实战 GxEPD2库入门与避坑指南ESP32 Driving E-Paper Displays A Practical GxEPD2 Library Guide and Pitfalls


AI free token/AI免费积分

ESP32驱动墨水屏实战 GxEPD2库入门与避坑指南

1. 为什么选GxEPD2库来驱动墨水屏1.1 墨水屏和普通屏的驱动逻辑完全不一样刚开始从LCD转到墨水屏的时候我第一反应是这不就是个不怎么刷新的屏吗用以前那套SPI/FSMC驱动方式还不是照样跑结果翻了车。墨水屏的工作原理决定了它不能用逐行扫描的方式持续刷新而是要通过驱动芯片给每一个像素施加特定的电压波形让黑白粒子发生翻转而且翻转完成后不需要持续供电也能保持画面。这意味着控制逻辑里必须有刷新时序、波形查找表、BUSY忙状态等待这些环节。普通屏幕你往显存里写像素就完事了哪怕写慢点只要不断刷新屏幕就正常显示。墨水屏不行你得先告诉驱动IC我现在要开始刷新了IC会走一整段波形有的长达两秒中间你要是又发命令打断它画面直接花掉甚至永久性残影。用ESP32和Arduino环境开发时如果自己从寄存器层面去写这些流程光适配一款屏幕的驱动IC就要折腾好几天。1.2 GxEPD2库到底解决了什么问题GxEPD

2库是Jean-Marc Zingg一直在维护的开源库它把所有主流墨水屏驱动IC的初始化序列、刷新波形、命令设置全部封装好了。你不需要去翻SSD1680的寄存器手册也不需要自己去算LUT查找表只需要在代码里指定屏幕型号然后调用几个简单的API就能完成初始化、清屏、显示文字、显示图片。更重要的是GxEPD2不是只支持某一片特定型号它把当前市面上常见的黑白、三色、四灰度墨水屏几乎都收进来了。你换屏幕的时候往往只需要改一个驱动类宏定义代码结构完全不用动。我后来从2.9寸黑白屏换到4.2寸三色屏程序主体部分就改了十几行这比我预想的要省事太多了。1.3 对比U8g2和Adafruit_EPDGxEPD2的优势在哪国内很多Arduino玩家习惯用U8g2因为它在OLED这类屏上确实好用。但U8g2对墨水屏的支持比较有限它走的是像素点阵渲染的思路对墨水屏的部分刷新和全屏刷新模式区分不够细尤其是三色屏和四

灰度屏U8g2基本无能为力。Adafruit_EPD库也不错但它更多是围绕Adafruit自家模块设计的换成淘宝上几十块钱的通用墨水屏模组引脚定义和驱动芯片对不上就得自己改库挺遭罪的。GxEPD2走的是一个框架按屏幕选驱动类的路子。你买到的屏幕模块只要驱动芯片在支持列表里就能用同一套初始化流程。遇到不支持的型号也可以继承现有类或者新增一个驱动类社区里已经有不少人这么干过。1.4 支持范围与项目适配参考我目前用过的GxEPD2支持屏幕包括常见的1.54寸、2.13寸、2.9寸、4.2寸、7.5寸驱动芯片涵盖IL3829、SSD1680、SSD1675、UC8151等。颜色分类上有纯黑白、黑白红三色、黑白黄三色、四灰阶刷新方式上有全刷和局刷。做桌面温湿度计、日程提醒牌、电子标签、离屏时钟都比较合适。下面要讲的这个项目就是拿ESP32开发板配2.9寸黑白墨水屏完整走一遍GxEPD2的驱动流程。2

. 硬件准备与开发环境搭建2.1 硬件清单与选型建议ESP32开发板我用的是一块ESP32 DevKitC带CH340串口芯片的那种Arduino IDE识别为ESP32 Dev Module2.9寸黑白墨水屏模块驱动IC是SSD1680常见于微雪、合宙等模块杜邦线若干最好选母对母方便把屏幕模块直接插到ESP32开发板上面包板和3.3V稳压模块如果手头屏幕模块是5V逻辑供电版本建议先看规格书这里有个提醒很多墨水屏模块自带电平转换电路可以直接用3.3V供电和逻辑但有些便宜的模块是裸屏转接板逻辑电平可能是5V。ESP32的GPIO最高输出3.3V如果要驱动5V逻辑的模块建议加一块电平转换板否则可能出现画面乱码或者DC/CS引脚拉不低的情况。2.2 Arduino IDE里配置ESP32核心我用的是Arduino IDE 2.x开发板管理器里加ESP32支持。打开文件-首选项-附加开发板管理器网

址填入官方那个JSON地址然后在开发板管理器里搜索ESP32安装最新版。这个流程很多教程都有但我想重点说一句务必装稳定版或者较新的release版本实测有些老版本会导致GxEPD2在编译时报一些莫名其妙的SPI头文件错误。装好之后在开发板菜单里选ESP32 Dev ModuleFlash Size选4MB其余默认就行。2.3 安装GxEPD2库打开库管理器搜索GxEPD2认准作者Jean-Marc Zingg点击安装。同时建议顺手装一下Adafruit GFX库虽然GxEPD2不强制依赖它但显示文字时要用的字体文件就是从Adafruit GFX里带的装好能省一堆编译报错。GxEPD2库安装后会自带大量示例其中有一个文件夹叫examples/GxEPD2_Example里面用宏定义的方式列出了几十种屏幕型号新手可以直接在头文件里把对应的宏打开。2.4 引脚规划原则别让墨水屏占了串口和下载引脚

ESP32的引脚很多但并不是每个都能随便接。第一个要注意的坑是GPIO34到GPIO39只能做输入不能做输出所以CS、DC、RST、BUSY绝对不能接到这几个脚上。第二个坑是GPIO0、GPIO2、GPIO15这些影响启动模式的引脚虽然能作为普通输出用但接线稍长就可能影响下载和启动。为了避免麻烦我一般把墨水屏的四个控制脚放到GPIO4、GPIO5、GPIO16、GPIO17这些干净的引脚上。SPI的MOSI和SCK则用ESP32默认的VSPI引脚也就是GPIO23和GPIO18。MISO一般用不到墨水屏是单工通信但有些模块有BUSY反馈已经用独立GPIO处理了。3. 引脚配置详解与接线实战3.1 墨水屏模块引脚定义市面上常见的2.9寸墨水屏模块接口引脚基本是这几个引脚名作用VCC电源正极一般接3.3VGND电源地DIN / MOSISPI数据输入CLK / SCKSPI时钟CS片选信号低电

平有效DC数据/命令切换RST复位信号低电平有效BUSY忙状态输出高电平表示忙有些模块还会多一个PWR_CTRL或排针带NC不用管。屏幕模块上如果丝印写的是DIN、CLK那就对应ESP32的MOSI和SCK别傻乎乎找MISO。3.2 推荐接线表ESP32 DevKitC我的接线方案如下墨水屏引脚ESP32引脚VCC3V3GNDGNDDIN23 (MOSI)CLK18 (SCK)CS5DC17RST16BUSY4这个组合的好处是避开了下载时可能被占用的串口引脚和启动配置引脚同时和Arduino-ESP32的默认SPI定义完全一致代码里不用额外设置SPI引脚。如果你的开发板引脚丝印不方便可以把CS/DC/RST/BUSY换到其他输出引脚但代码里的构造函数参数必须同步换。3.3 代码中初始化GxEPD2对象打开Arduino IDE新建一个工程先把这段代码贴进去#include GxEPD2_B

W.h #include Fonts/FreeMonoBold9pt7b.h #include Fonts/FreeSans9pt7b.h #define EPD_CS 5 #define EPD_DC 17 #define EPD_RST 16 #define EPD_BUSY 4 GxEPD2_BWGxEPD2_290_T94_V2, GxEPD2_290_T94_V2::HEIGHT display( GxEPD2_290_T94_V2(/*CS*/ EPD_CS, /*DC*/ EPD_DC, /*RST*/ EPD_RST, /*BUSY*/ EPD_BUSY) ); void setup() { Serial.begin(115200); display.init(115200); } void loop() { }注意GxEPD2_BW的模板参数第一个是屏幕驱动类第二个是屏幕

的HEIGHT这个值在对应的驱动类里已经定义好了直接写GxEPD2_290_T94_V2::HEIGHT就行。对象构造时把四个控制引脚按顺序填进去接线不对或者对象参数写错后续的显示肯定出问题。如果手头屏幕和我不一样比如是1.54寸的就去GxEPD2库自带的GxEPD2_Example里把你那块屏幕对应的宏定义复制过来把对象声明替换掉。不同屏幕的构造参数个数是一样的只是驱动类名不同。3.4 供电和电平注意事项墨水屏刷新瞬间的电流比待机时要高不少有些模块峰值能到20-30mA虽然ESP32开发板的3.3V稳压器一般能顶住但如果同时接了其他外设比如温湿度传感器、OLED、蜂鸣器建议用外部3.3V稳压模块统一供电否则可能出现在屏幕刷新瞬间ESP32自动重启的情况。另外千万不要把5V接进VCC想当然供电更稳定很多墨水屏模块的VCC走的是逻辑电平转换芯片接了5V会把后级芯片烧掉。先看模块丝印如果写了3

.3V-5V兼容再考虑5V。4. 基础显示文本与图形4.1 初始化流程里的几个关键细节display.init()不仅是初始化驱动IC它还会调用reset复位屏幕所以执行init之前要确保CS/DC/RST/BUSY已经接好。init之后我习惯立刻调用display.setRotation(1)把屏幕旋转到横屏状态不然默认竖屏在2.9寸屏上看起来特别窄后面排版麻烦。display.firstPage()和display.nextPage()是GxEPD2特有的分页刷新机制看起来有点像状态机。每次都把要显示的东西全部画在缓冲区里然后nextPage()会真正把缓冲区推给屏幕驱动。以2.9寸为例屏幕分辨率是128x296全屏刷新如果不开分页ESP32的P SRAM可能不够用。这个分页机制对新手来说很抽象只要记得一个套路display.firstPage(); do { display.fill

Screen(GxEPD_WHITE); display.setCursor(...); display.print(...); // 画其他东西 } while (display.nextPage());do-while会一直分页刷新直到整屏画完千万不要在中间加delay或者长时间阻塞操作。4.2 显示文本字体、坐标与对齐GxEPD2通过Adafruit GFX的字体来绘制文字。默认不带任何字体时display.print()只会画一个字符占位框必须手动设置字体。比如display.setFont(FreeMonoBold9pt7b); display.setTextColor(GxEPD_BLACK); display.setCursor(10, 30); display.print(Hello ESP32);这里的坐标是字符左上角的基础线位置跟普通LCD的写法一样。但墨水屏不像LCD

那样有个普遍用的图形库GxEPD2的文字没有自动居中函数实际排版时得自己计算。比如要在宽度为128像素的屏幕上居中绘制TEMP: 25C先算一下字符像素宽度2.9寸的9pt字体差不多一个字符6像素自己手写一个居中算法最可靠。字体文件在Fonts/目录下常用的有FreeMonoBold9pt7b、FreeSans9pt7b、FreeSansBold12pt7b。文件名称里的数字是pt字号7b表示7位编码。如果显示中文自带的字体不支持需要用u8g2_font工具转中文字库或者自己用图片方式显示中文这一点后面会提到。我一般项目里的中文标题都是用图片处理。4.3 绘制图形矩形、圆、线墨水屏最实用的图形API就是fillScreen、drawRect、fillRect、drawCircle、drawLine。做一个简单的信息卡片时可以这样画边框display.drawRect(5, 5, displ

ay.width() - 10, display.height() - 10, GxEPD_BLACK); display.fillRect(20, 40, 50, 30, GxEPD_BLACK);这里有个细节display.width()和display.height()在setRotation之后会变化比如横屏后width是296height是128所以动态获取尺寸比写死数字更稳妥。画完图形后如果你不想整块区域全刷成黑色又想做一个反色效果可以手动对指定区域做像素遍历异或但GxEPD2_BW类本身没有提供xOr操作简单项目用填充矩形就够了。4.4 一个小例子做一个横向时间卡片我把这些基础API组合起来做了一个开机显示时间日期的小卡片完整代码如下void displayDateTime(const char* timeText, const char* dateText) { displ

)); }实际测试下来从调用到显示完大概要2到3秒屏幕会先闪一下然后慢慢出图。这是正常的全屏刷新过程GxEPD2默认用慢速刷新能有效减少残影。如果你想加快速度GxEPD2里有些屏幕驱动类支持display.epd2.setPaged之类的参数调整但提高刷新速度会增加残影风险后面会细说。5. 图像显示从数组到本地图片5.1 图像显示前必须搞清楚的三个约束墨水屏显示图片不像手机屏幕那么自由首先分辨率要匹配2.9寸屏是128x296你拿一张1920x1080的图直接塞进去肯定不行必须压缩到目标分辨率。其次是颜色深度黑白墨水屏只能显示两种颜色彩图需要经过二值化处理。最后是存储格式GxEPD2的drawBitmap接口接收的是const unsigned char*数组每个bit对应一个像素要么把图片转成这种数组直接编译进固件要么从SD卡读取BMP文件在运行时解析。5.2 用取模工具生成C数组我最常

本文来源:http://www.lpqz.cn/news/128313
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。

ESP32 Driving E-Paper Displays A Practical GxEPD2 Library Guide and Pitfalls

1. Why choose the GxEPD2 library to drive ePaper displays 1.1 The drive logic of ePaper is completely different from that of an ordinary display When I first switched from LCD to ePaper, my first reaction was: isn't this just a display that doesn't refresh very often? Couldn't I just use the old SPI/FSMC approach and have it work the same way? Well, I crashed and burned. The working principle of ePaper dictates that it cannot refresh continuously by row-by-row scanning; instead, the driver chip must apply specific voltage waveforms to each pixel to flip the black and white particles, and once the flip is complete, the image is retained without any continuous power. This means the control logic must include things like refresh timing, waveform lookup tables, and waiting for the BUSY state. With an ordinary display, you just write pixels into the framebuffer and you're done — even if you write a bit slowly, as long as you keep refreshing, the display shows normally. ePaper doesn't work that way: you have to tell the driver IC that you're about to start a refresh, and the IC runs through a whole waveform sequence, some lasting as long as two seconds; if you send another command in the middle and interrupt it, the image gets garbled, or you can even end up with permanent ghosting. When developing with ESP32 and the Arduino environment, if you write these flows yourself at the register level, just adapting to a single display's driver IC can take days. 1.2 What exactly does the GxEPD2 library solve GxEPD

2 is an open-source library that Jean-Marc Zingg has been maintaining. It packages up the initialization sequences, refresh waveforms, and command settings of all mainstream ePaper driver ICs. You don't need to dig through the SSD1680 register manual or calculate LUT lookup tables yourself; you just specify the display model in your code and call a few simple APIs to initialize, clear the screen, display text, and show images. More importantly, GxEPD2 doesn't only support one specific model — it covers nearly all the common black-and-white, three-color, and four-grayscale ePaper displays on the market today. When you switch displays, you usually only need to change one driver-class macro; the code structure doesn't need to change at all. When I later switched from a 2.9-inch black-and-white display to a 4.2-inch three-color display, I only changed a dozen or so lines in the main program — far less trouble than I had expected. 1.3 Where does GxEPD2 have advantages over U8g2 and Adafruit_EPD Many Arduino hobbyists in China are used to U8g2 because it really works well on displays like OLEDs. But U8g2's support for ePaper is fairly limited; it follows a pixel-matrix rendering approach and doesn't distinguish partial refresh from full refresh modes finely enough — especially on three-color and four-

grayscale displays, U8g2 is basically powerless. The Adafruit_EPD library is also good, but it's designed more around Adafruit's own modules; when you switch to a generic ePaper module that costs a few dozen yuan on Taobao, the pin definitions and driver chip don't match, so you have to modify the library yourself, which is quite a pain. GxEPD2 takes a framework approach where you pick a driver class according to the display. As long as the driver chip of the display module you bought is on the supported list, you can use the same initialization flow. If you run into an unsupported model, you can also inherit from an existing class or add a new driver class — quite a few people in the community have already done this. 1.4 Support range and project adaptation reference The GxEPD2 displays I've used so far include the common 1.54-inch, 2.13-inch, 2.9-inch, 4.2-inch, and 7.5-inch ones, with driver chips covering IL3829, SSD1680, SSD1675, UC8151, and others. In terms of color there are pure black-and-white, black/white/red three-color, black/white/yellow three-color, and four-grayscale; refresh modes include full refresh and partial refresh. They're well suited for desktop temperature and humidity meters, schedule reminder boards, electronic labels, and off-screen clocks. The project I'll describe below uses an ESP32 development board with a 2.9-inch black-and-white ePaper display to walk through the entire GxEPD2 driver flow. 2

. Hardware preparation and development environment setup 2.1 Hardware list and selection advice For the ESP32 development board I used an ESP32 DevKitC, the kind with a CH340 serial chip; Arduino IDE recognizes it as ESP32 Dev Module. The 2.9-inch black-and-white ePaper module has an SSD1680 driver IC, common in modules from Waveshare, Luat, and others. Several jumper wires — female-to-female are best so you can plug the display module directly onto the ESP32 board. A breadboard and a 3.3V regulator module; if your display module is a 5V logic-supply version, check the datasheet first. One note here: many ePaper modules have built-in level-shifting circuits and can be powered and driven directly at 3.3V, but some cheap ones are bare-panel adapter boards whose logic level may be 5V. The ESP32's GPIOs output at most 3.3V; if you need to drive a 5V-logic module, it's advisable to add a level-shifter board, otherwise you may get a garbled image or find that the DC/CS pins can't be pulled low. 2.2 Configuring the ESP32 core in Arduino IDE I used Arduino IDE 2.x and added ESP32 support in the Boards Manager. Open File - Preferences - Additional Boards Manager URLs

field and paste in the official JSON URL, then search for ESP32 in the Boards Manager and install the latest version. Many tutorials cover this flow, but I want to stress one point: be sure to install a stable release or a fairly recent release version. In my testing, some old versions cause GxEPD2 to throw baffling SPI header-file errors at compile time. After installation, select ESP32 Dev Module in the Boards menu, set Flash Size to 4MB, and leave the rest at defaults. 2.3 Installing the GxEPD2 library Open the Library Manager, search for GxEPD2, look for the author Jean-Marc Zingg, and click Install. I'd also recommend installing the Adafruit GFX library while you're at it — GxEPD2 doesn't strictly depend on it, but the font files you need for displaying text come bundled with Adafruit GFX, and having it installed saves you a bunch of compile errors. Once installed, GxEPD2 comes with plenty of examples; one folder is called examples/GxEPD2_Example, which lists dozens of display models via macro definitions. Beginners can simply uncomment the corresponding macro in the header file. 2.4 Pin planning principles: don't let the ePaper display take over the serial and download pins

The ESP32 has many pins, but not every one can be used freely. The first pitfall to watch for: GPIO34 to GPIO39 can only be used as inputs, not outputs, so CS, DC, RST, and BUSY must never be connected to these pins. The second pitfall: pins like GPIO0, GPIO2, and GPIO15 affect the boot mode — although they can be used as ordinary outputs, a slightly longer wire can interfere with downloading and booting. To avoid trouble, I generally put the display's four control pins on clean pins such as GPIO4, GPIO5, GPIO16, and GPIO17. For SPI, MOSI and SCK use the ESP32's default VSPI pins, namely GPIO23 and GPIO18. MISO is generally unnecessary — ePaper uses simplex communication — and on some modules the BUSY feedback is already handled by a separate GPIO. 3. Pin configuration details and wiring in practice 3.1 ePaper module pin definitions The interface pins on common 2.9-inch ePaper modules are basically these: pin name / function — VCC power positive, usually connected to 3.3V; GND power ground; DIN / MOSI SPI data input; CLK / SCK SPI clock; CS chip select, active-lo

w DC data/command switch; RST reset signal, active-low; BUSY busy-state output, high means busy. Some modules also have an extra PWR_CTRL pin or a header with NC — just ignore those. If the silkscreen on the display module says DIN and CLK, those correspond to the ESP32's MOSI and SCK; don't go silly hunting for MISO. 3.2 Recommended wiring table (ESP32 DevKitC) My wiring scheme is as follows — ePaper pin / ESP32 pin: VCC / 3V3; GND / GND; DIN / 23 (MOSI); CLK / 18 (SCK); CS / 5; DC / 17; RST / 16; BUSY / 4. The benefit of this combination is that it avoids the serial pins that may be occupied during downloading and the boot-configuration pins, and it matches the Arduino-ESP32 default SPI definitions exactly, so you don't need to configure the SPI pins separately in code. If the pin silkscreen on your board is inconvenient, you can move CS/DC/RST/BUSY to other output pins, but the constructor arguments in the code must be changed accordingly. 3.3 Initializing the GxEPD2 object in code Open Arduino IDE, create a new project, and first paste in this code: #include GxEPD2_B

W.h #include Fonts/FreeMonoBold9pt7b.h #include Fonts/FreeSans9pt7b.h #define EPD_CS 5 #define EPD_DC 17 #define EPD_RST 16 #define EPD_BUSY 4 GxEPD2_BWGxEPD2_290_T94_V2, GxEPD2_290_T94_V2::HEIGHT display( GxEPD2_290_T94_V2(/*CS*/ EPD_CS, /*DC*/ EPD_DC, /*RST*/ EPD_RST, /*BUSY*/ EPD_BUSY) ); void setup() { Serial.begin(115200); display.init(115200); } void loop() { } Note that the first template parameter of GxEPD2_BW is the display driver class, and the second is the display

's HEIGHT — this value is already defined in the corresponding driver class, so just write GxEPD2_290_T94_V2::HEIGHT. When constructing the object, fill in the four control pins in order; if the wiring is wrong or the object parameters are mistaken, the display will definitely misbehave later on. If your display is different from mine — say a 1.54-inch one — go to the GxEPD2_Example that ships with the GxEPD2 library, copy the macro definition for your display, and replace the object declaration. Different displays have the same number of constructor parameters; only the driver class name differs. 3.4 Power supply and logic-level notes The current drawn at the moment of an ePaper refresh is much higher than in standby; some modules peak at 20-30mA. Although the 3.3V regulator on the ESP32 board can usually handle it, if you've also connected other peripherals such as a temperature and humidity sensor, an OLED, or a buzzer, it's advisable to use an external 3.3V regulator module to power everything; otherwise the ESP32 may reboot automatically at the instant the screen refreshes. Also, never connect 5V to VCC assuming it will give a more stable supply — on many ePaper modules, VCC feeds a logic-level shifting chip, and connecting 5V will burn out the downstream chip. Check the module's silkscreen first; only consider 5V if it says 3

.3V-5V compatible. 4. Basic text and graphics display 4.1 A few key details in the initialization flow display.init() not only initializes the driver IC — it also calls reset to reset the display, so before running init make sure CS/DC/RST/BUSY are all connected. Right after init, I like to immediately call display.setRotation(1) to rotate the display to landscape; otherwise the default portrait orientation looks especially narrow on a 2.9-inch screen and makes layout annoying later. display.firstPage() and display.nextPage() are GxEPD2's signature paged refresh mechanism, which looks a bit like a state machine. Each time, you draw everything you want to display into the buffer, and then nextPage() actually pushes the buffer to the display driver. Taking the 2.9-inch as an example, the resolution is 128x296; for a full refresh, if paging isn't enabled, the ESP32's PSRAM may not be enough. This paging mechanism can be abstract for beginners, but just remember one pattern: display.firstPage(); do { display.fill

Screen(GxEPD_WHITE); display.setCursor(...); display.print(...); // draw other stuff } while (display.nextPage()); The do-while keeps paging refreshes going until the whole screen is drawn — never add a delay or a long blocking operation in the middle. 4.2 Displaying text: fonts, coordinates, and alignment GxEPD2 draws text using Adafruit GFX fonts. With no font set by default, display.print() will only draw a character placeholder box, so you must set a font manually. For example: display.setFont(FreeMonoBold9pt7b); display.setTextColor(GxEPD_BLACK); display.setCursor(10, 30); display.print(Hello ESP32); The coordinates here are the baseline position of the top-left of the character, written the same way as on an ordinary LCD. But ePaper, unlike LCD

s, doesn't have a commonly used graphics library, and GxEPD2's text has no auto-centering function — you have to calculate it yourself when laying out. For example, to center-draw TEMP: 25C on a 128-pixel-wide screen, first figure out the character pixel width; with the 9pt font on a 2.9-inch display, one character is about 6 pixels, so writing a centering routine yourself is the most reliable approach. Font files are in the Fonts/ directory; commonly used ones are FreeMonoBold9pt7b, FreeSans9pt7b, and FreeSansBold12pt7b. The number in the filename is the pt size, and 7b means 7-bit encoding. If you want to display Chinese, the bundled fonts don't support it, so you need to convert a Chinese font with the u8g2_font tool or display Chinese as images — I'll mention this later. In my projects I usually handle Chinese titles as images. 4.3 Drawing shapes: rectangles, circles, lines The most practical graphics APIs for ePaper are fillScreen, drawRect, fillRect, drawCircle, and drawLine. When making a simple information card, you can draw a border like this: display.drawRect(5, 5, displ

ay.width() - 10, display.height() - 10, GxEPD_BLACK); display.fillRect(20, 40, 50, 30, GxEPD_BLACK); Here's a detail: display.width() and display.height() change after setRotation — for example in landscape, width is 296 and height is 128 — so getting the dimensions dynamically is safer than hardcoding numbers. After drawing shapes, if you don't want an entire area filled solid black but still want an inverted effect, you can manually do a pixel-by-pixel XOR over a specified area, but the GxEPD2_BW class itself doesn't provide an xOr operation — for simple projects, filled rectangles are enough. 4.4 A small example: making a horizontal time card I combined these basic APIs to make a little card that shows the time and date on startup. The complete code is as follows: void displayDateTime(const char* timeText, const char* dateText) { displ

)); } In actual testing, from calling it to finishing the display takes about 2 to 3 seconds; the screen flashes once and then the image gradually appears. This is the normal full-refresh process — GxEPD2 uses slow refresh by default, which effectively reduces ghosting. If you want to speed things up, some display driver classes in GxEPD2 support parameter tweaks like display.epd2.setPaged, but increasing the refresh speed raises the risk of ghosting, which I'll discuss in detail later. 5. Image display: from arrays to local images 5.1 Three constraints you must understand before displaying images Displaying images on ePaper isn't as free as on a phone screen. First, the resolution must match — the 2.9-inch screen is 128x296, so you can't just shove a 1920x1080 image in; it must be compressed to the target resolution. Second is color depth — a black-and-white ePaper display can only show two colors, so color images need binarization. Third is the storage format — GxEPD2's drawBitmap interface takes a const unsigned char* array in which each bit corresponds to one pixel; either convert the image into such an array and compile it into the firmware directly, or read a BMP file from an SD card and parse it at runtime. 5.2 Generating a C array with a bitmap tool I most often

本文来源:http://www.lpqz.cn/news/128313
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。

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

📮 需求咨询📮 Inquiry