
1. 从一块MAX7219点阵屏说起Tobers Multidisplay到底想解决什么问题如果你手上正好有一块ESP8266或者ESP32又碰巧翻出来几块MAX7219的8x8 LED点阵模块那你大概率动过一个念头——能不能让这几块屏拼在一起显示点有用的东西比如滚动显示天气、时间、股票或者干脆做个桌面信息看板。Tobers Multidisplay这个项目就是冲着这个需求去的。它的核心定位很明确在ESP8266和ESP32上驱动多块MAX7219点阵屏实现多屏级联显示。注意这里的关键词是“Multidisplay”不是单屏驱动。单块MAX7219点阵的驱动代码网上到处都是随便搜一个库几行代码就能点亮。但当你把两块、三块甚至四块屏串起来的时候问题就来了——屏幕顺序对不对刷新率够不够内存扛不扛得住ESP8266和ESP32的引脚资源怎么分配这些才是真正让人头疼的地方。我最初接触这个方向是因为
想做一个放在书桌上的小看板左边显示时间右边滚动显示当天天气。单块8x8点阵只能显示一个字符完全不够用。于是买了几块MAX7219模块打算级联起来。结果第一版代码跑起来屏幕闪烁严重字符错位ESP8266还时不时重启。后来才慢慢摸清楚多屏级联和单屏驱动完全是两码事涉及SPI时序、缓冲区管理、任务调度等一系列问题。这篇文章适合谁看如果你已经会用Arduino IDE给ESP8266或ESP32烧录程序知道基本的GPIO操作但还没尝试过多块MAX7219级联那这篇内容就是为你准备的。如果你已经做过单屏驱动想扩展到多屏同样能从中找到需要避开的坑。我会从硬件接线、库的选择、代码结构、性能调优几个层面把Tobers Multidisplay这个方向上的核心问题拆开讲清楚。需要提前说明的是Tobers Multidisplay本身是一个开源项目名称但它的技术路线和实现思路具有通用性。我下面讲的内容既包括对
这个项目思路的解读也包括我在实际搭建类似系统时积累的经验。所有代码和配置都基于Arduino IDE环境使用常见的MD_MAX72xx和MD_Parola库这些库在ESP8266和ESP32上都有良好的支持。2. MAX7219级联的硬件逻辑与ESP芯片的引脚分配策略2.1 MAX7219的级联原理数据是怎么从第一块流到第四块的MAX7219这颗芯片本身是串行输入、并行输出的LED驱动芯片。每块模块上有8x8共64个LED芯片内部有8个寄存器和64位的显示缓冲区。当你把多块模块级联时数据并不是同时发给所有模块的而是像排队一样从第一块依次往后传。具体来说MAX7219的DIN引脚接收数据DOUT引脚把数据传给下一块的DIN。每块芯片需要16位数据一个地址字节加一个数据字节才能完成一次写入。如果你级联了4块模块那么你需要连续发送64位数据第一块芯片会截取最后16位第二块截取倒数第二个16位以此
类推。这意味着你在代码里写的“第0块屏”和物理上最左边那块屏可能正好是反的。这个细节听起来简单但实际调试时非常容易搞混。我见过不少人接线完全正确代码也没问题但显示出来的字符就是左右颠倒的。原因就是没有搞清楚数据流向和屏幕索引的对应关系。MD_MAX72xx库提供了一个MD_MAX72XX::setDeviceAddr或者通过构造函数指定硬件类型的方式来解决这个问题但前提是你得知道自己用的是哪种接线方式。常见的MAX7219模块有两种引脚排列一种是DIN在左边、DOUT在右边另一种是DOUT在左边、DIN在右边。前者适合从左到右级联后者适合从右到左。如果你买的是不同批次的模块混在一起用那索引混乱几乎是必然的。我的建议是尽量用同一批次的模块并且在接线前先用万用表确认DIN和DOUT的位置。2.2 ESP8266与ESP32的SPI资源差异为什么ESP32更从容ESP8266和ESP32虽然都支
持SPI但两者的硬件资源差距很大。ESP8266只有一个硬件SPI接口而且这个SPI接口还被Flash占用了一部分引脚。你能用的自由引脚其实很有限通常只有GPIO12MISO、GPIO13MOSI、GPIO14SCK、GPIO15CS这一组。如果你还想接其他外设比如温湿度传感器、按钮引脚就会非常紧张。ESP32的情况好很多。它有三个SPI接口SPI0、SPI1、SPI2其中SPI0和SPI1内部使用SPI2也叫HSPI可以自由映射到几乎任何GPIO上。这意味着你可以把MAX7219的DIN、CLK、CS分别接到ESP32的任意三个可用引脚上不用死守默认的SPI引脚。对于多屏级联项目来说这个灵活性非常重要因为你可以把SPI引脚安排在PCB板边缘方便接线。但这里有一个坑ESP32的SPI引脚映射虽然灵活但并不是所有引脚都能用作SPI。比如GPIO6到GPIO11通常连接内部Flash绝对不能使
用。GPIO34到GPIO39是输入-only引脚也不能用作SPI输出。我在第一次用ESP32驱动MAX7219时随手选了GPIO34作为DIN结果怎么都不亮排查了半天才发现是引脚方向的问题。下面这张表是我在实际项目中总结的引脚分配建议适用于ESP8266和ESP32芯片型号DIN数据CLK时钟CS片选备注ESP8266GPIO13GPIO14GPIO15使用硬件SPIGPIO15需下拉ESP8266GPIO13GPIO14GPIO12CS改用GPIO12避开GPIO15的启动要求ESP32GPIO23GPIO18GPIO5默认VSPI引脚兼容性最好ESP32GPIO13GPIO14GPIO15可自定义映射适合引脚紧张时ESP32GPIO32GPIO33GPIO25适合与I2C传感器共用总线时避开冲突注意ESP8266的GPIO15在启动时必须为低电平否则芯片无法正常启动。如果你把CS接在
GPIO15上务必加一个下拉电阻通常10kΩ否则会出现上电后程序不跑的情况。这个坑我在早期项目中踩过不止一次。2.3 供电问题多块点阵屏同时亮起时的电流陷阱MAX7219模块在全部LED点亮时每块模块的电流消耗大约在100mA到150mA之间。如果你级联了4块模块并且经常显示全亮的图案总电流可能超过500mA。ESP8266开发板上的3.3V稳压芯片通常只能提供300mA到500mA的电流ESP32开发板稍好一些但也很有限。我遇到过最典型的情况是单块屏测试完全正常接上第二块屏后开始闪烁接上第三块屏后ESP8266直接重启。一开始以为是代码问题后来用万用表一测发现3.3V电压在屏幕全亮时跌到了2.8V以下芯片当然会复位。解决方案有两个一是给MAX7219模块单独供电用一块独立的5V电源同时把电源的地和ESP芯片的地连在一起二是降低屏幕亮度通过软件设置MAX7219的亮度寄存器把亮度降到最低档
电流消耗会大幅下降。MD_MAX72xx库提供了setIntensity函数取值范围是0到15我通常设置在2到4之间既看得清又不会给电源太大压力。如果你打算做的是桌面看板屏幕不需要太亮低亮度反而更舒服。但如果你要做户外显示那就必须上独立电源并且考虑加散热措施。MAX7219芯片本身有一定的发热多块级联时热量叠加夏天长时间运行需要注意通风。3. 库的选择与代码架构MD_MAX72xx和MD_Parola怎么配合3.1 为什么不用Adafruit_GFX而选MD_MAX72xxArduino生态里驱动MAX7219的库有好几个最常见的是LedControl、Adafruit_GFX加MAX7219驱动、以及MD_MAX72xx。LedControl太老了功能有限不支持硬件SPI刷新率上不去。Adafruit_GFX的优势是图形绘制函数丰富但它的MAX7219后端在多屏级联时性能一般而且内存占用
较大。MD_MAX72xx是专门为MAX7219设计的库支持硬件SPI和软件SPI两种模式内置了缓冲区管理可以单独控制每一块屏的每一个LED。更重要的是它的MD_MAX72XX类支持指定级联数量并且提供了transform函数来处理屏幕方向问题。MD_Parola则是在MD_MAX72xx基础上封装了文本滚动、对齐、特效等功能适合做信息展示类项目。我选择MD_MAX72xx加MD_Parola的组合主要原因是内存效率高、刷新稳定、社区支持好。在ESP8266上MD_MAX72xx的缓冲区占用是每块屏8字节4块屏总共32字节完全可以接受。MD_Parola的文本缓冲区也可以根据实际需要调整大小不会一下子吃掉太多RAM。3.2 初始化代码的关键参数硬件类型和级联数量下面这段代码是我在ESP32上驱动4块MAX7219模块的初始化部分基于MD_MAX72xx库#include MD_MAX72x
x.h #include SPI.h #define HARDWARE_TYPE MD_MAX72XX::FC16_HW #define MAX_DEVICES 4 #define CLK_PIN 18 #define DATA_PIN 23 #define CS_PIN 5 MD_MAX72XX mx MD_MAX72XX(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES); void setup() { mx.begin(); mx.control(MD_MAX72XX::INTENSITY, 3); mx.clear(); }这里有几个关键点需要解释。HARDWARE_TYPE决定了库如何映射LED坐标到芯片寄存器。常见的类型有FC16_HW、GENERIC_HW、PAROLA_HW等。如果你用的是最常见的FC-16模块背面
印着FC-16那就选FC16_HW。如果显示出来的字符是镜像的或者上下颠倒的可以换GENERIC_HW试试。这个参数选错后面怎么调代码都没用。MAX_DEVICES是级联的模块数量。注意这个数量必须和实际物理连接的数量一致多一块少一块都会导致显示异常。我曾经因为多数了一块导致最后一块屏显示乱码排查了很久才发现是数量对不上。mx.control(MD_MAX72XX::INTENSITY, 3)设置亮度。取值范围0到15我一般从3开始调太亮了刺眼太暗了看不清。如果你用的是独立供电可以适当调高。3.3 多屏文本滚动的实现逻辑MD_Parola的zone机制MD_Parola最强大的功能是支持多个显示区域zone。你可以把4块屏分成两个zone左边两块显示时间右边两块滚动显示天气。每个zone可以独立设置对齐方式、滚动速度和特效。#include MD_Parola.h #include MD_
MAX72xx.h #define HARDWARE_TYPE MD_MAX72XX::FC16_HW #define MAX_DEVICES 4 MD_Parola P MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES); void setup() { P.begin(2); // 两个zone P.setZone(0, 0, 1); // zone 0 使用第0和第1块屏 P.setZone(1, 2, 3); // zone 1 使用第2和第3块屏 P.setIntensity(3); P.displayZoneText(0, 12:30, PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT); P.displayZoneText(1, Weather: Sunny 25C, PA_LEFT, 50, 0, PA_
SCROLL_LEFT, PA_SCROLL_LEFT); } void loop() { P.displayAnimate(); }P.begin(2)表示启用两个zone。setZone的参数是zone编号、起始模块索引、结束模块索引。注意索引是从0开始的而且和物理屏幕的顺序有关。如果你发现zone 0显示在了右边的屏幕上那就是索引反了把起始和结束对调一下就行。displayZoneText的参数比较多我逐个解释第一个是zone编号第二个是文本内容第三个是对齐方式第四个是滚动速度毫秒每帧第五个是暂停时间第六个是进入特效第七个是退出特效。对于静态显示用PA_PRINT和PA_NO_EFFECT对于滚动显示用PA_SCROLL_LEFT。displayAnimate()必须放在loop里不断调用它负责更新每个zone的显示状态。如果你在loop里还有别的耗时操作比如读传感器要注意不要让lo
op阻塞太久否则滚动会卡顿。4. 实际调试中遇到的五个典型问题与排查路径4.1 屏幕顺序颠倒数据流向和索引的对应关系这是最常见的问题。你接好线烧录程序发现第一块屏显示的内容跑到了最后一块屏上。原因在于MAX7219的级联数据是从最后一块芯片往前传递的。库在初始化时默认把索引0分配给最靠近CS引脚的那块芯片但物理上最靠近CS的可能是最右边那块。排查方法很简单写一个测试程序依次点亮每一块屏的第一个LED观察哪块屏亮了。然后调整setZone的起始和结束索引或者在初始化时使用mx.setDeviceAddr重新映射。MD_MAX72xx库还提供了一个transform函数可以对整个显示缓冲区做镜像或旋转但那个会影响所有屏幕不适合单独调整某一块。我的经验是在接线阶段就用标签纸标记好每块屏的物理位置和索引比如从左到右标为0、1、2、3然后在代码里按照这个顺序设置zone。如果发现反了不要急着改代码先
检查接线顺序是不是和标记一致。4.2 刷新闪烁与ESP8266看门狗复位ESP8266有一个硬件看门狗如果loop函数执行时间过长或者有长时间的中断禁用看门狗就会触发复位。MD_Parola的displayAnimate()在滚动文本时计算量不小如果同时还在做WiFi通信或者读传感器很容易超时。我遇到过一次典型情况ESP8266连接WiFi获取网络时间同时用MD_Parola滚动显示。每次WiFi重连时屏幕就会闪烁几下然后ESP8266重启。串口日志显示“wdt reset”。解决办法是把WiFi相关操作放在单独的定时任务里或者用yield()函数主动让出CPU时间。在ESP32上这个问题不那么明显因为ESP32是双核的你可以把显示任务和网络任务分配到不同核心上。但ESP32也有看门狗只是超时时间更长。如果你在loop里用了delay()记得用vTaskDelay()代替或者至少加上yie
本文来源:http://www.lpqz.cn/news/107914
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。

1. Starting with a single MAX7219 dot matrix display: what problem is Tobers Multidisplay actually trying to solve? If you happen to have an ESP8266 or ESP32 on hand, and also happen to dig up a few MAX7219 8x8 LED dot matrix modules, chances are you have had the idea of chaining these displays together to show something useful — scrolling weather, time, stock quotes, or simply building a desktop information dashboard. The Tobers Multidisplay project was created precisely for this need. Its core positioning is clear: driving multiple MAX7219 dot matrix displays on the ESP8266 and ESP32 to achieve multi-screen cascaded display. Note that the keyword here is "Multidisplay", not single-display driving. Drive code for a single MAX7219 dot matrix is everywhere online — just grab any library and a few lines of code will light it up. But when you chain two, three, or even four displays together, problems arise — whether the screen order is correct, whether the refresh rate is sufficient, whether memory can handle it, and how to allocate the GPIO pins on the ESP8266 and ESP32. These are the things that really cause headaches. I first got into this direction because
I wanted to build a small dashboard for my desk, with the time on the left and the day's weather scrolling on the right. A single 8x8 dot matrix can only show one character, which is nowhere near enough. So I bought several MAX7219 modules and planned to cascade them. As a result, when the first version of the code ran, the screens flickered badly, the characters were misaligned, and the ESP8266 kept restarting from time to time. Only later did I gradually figure out that multi-screen cascading and single-screen driving are two completely different matters, involving SPI timing, buffer management, task scheduling, and a whole series of issues. Who is this article for? If you already know how to use the Arduino IDE to flash programs onto an ESP8266 or ESP32, understand basic GPIO operations, but have not yet tried cascading multiple MAX7219 modules, then this content is for you. If you have already done single-screen driving and want to expand to multiple screens, you can likewise find the pitfalls to avoid here. I will break down the core problems in the Tobers Multidisplay direction from several angles: hardware wiring, library selection, code structure, and performance tuning. One thing to note in advance: Tobers Multidisplay is itself the name of an open-source project, but its technical approach and implementation ideas are general-purpose. What I discuss below includes both
an interpretation of this project's ideas and the experience I accumulated while actually building similar systems. All the code and configuration are based on the Arduino IDE environment, using the common MD_MAX72xx and MD_Parola libraries, both of which have good support on the ESP8266 and ESP32. 2. The hardware logic of MAX7219 cascading and pin allocation strategies for ESP chips 2.1 How MAX7219 cascading works: how data flows from the first module to the fourth The MAX7219 chip itself is a serial-input, parallel-output LED driver chip. Each module has 8x8, a total of 64 LEDs, and the chip internally has 8 registers and a 64-bit display buffer. When you cascade multiple modules, the data is not sent to all modules at once; instead it is passed from the first module backward one by one, like a queue. Specifically, the MAX7219's DIN pin receives data and the DOUT pin passes the data to the next module's DIN. Each chip needs 16 bits of data — one address byte plus one data byte — to complete a single write. If you cascade 4 modules, you need to send 64 bits of data continuously; the first chip takes the last 16 bits, the second takes the second-to-last 16 bits, and so
on. This means that "display 0" as you write it in code may be exactly the opposite of the physically leftmost display. This detail sounds simple, but it is very easy to get confused during actual debugging. I have seen many people whose wiring was completely correct and whose code had no problems, yet the displayed characters were still reversed left and right. The reason is that they did not understand the correspondence between data flow direction and screen indexes. The MD_MAX72xx library provides MD_MAX72XX::setDeviceAddr, or a way to specify the hardware type through the constructor, to solve this problem — but the prerequisite is that you know which wiring method you are using. Common MAX7219 modules come in two pin layouts: one with DIN on the left and DOUT on the right, and the other with DOUT on the left and DIN on the right. The former is suitable for left-to-right cascading, the latter for right-to-left. If you buy modules from different batches and mix them together, index confusion is almost inevitable. My advice is to use modules from the same batch whenever possible and, before wiring, use a multimeter to confirm the positions of DIN and DOUT. 2.2 Differences in SPI resources between ESP8266 and ESP32: why the ESP32 is more composed Although both the ESP8266 and ESP32 supp
ort SPI, there is a big gap between the two in hardware resources. The ESP8266 has only one hardware SPI interface, and part of that SPI interface's pins are occupied by the Flash. The free pins you can actually use are quite limited — usually just this group: GPIO12 (MISO), GPIO13 (MOSI), GPIO14 (SCK), GPIO15 (CS). If you also want to connect other peripherals such as a temperature and humidity sensor or buttons, pins will be very tight. The ESP32 is much better off. It has three SPI interfaces, SPI0, SPI1, and SPI2; SPI0 and SPI1 are used internally, while SPI2, also called HSPI, can be freely mapped to almost any GPIO. This means you can connect the MAX7219's DIN, CLK, and CS to any three available pins on the ESP32, without being stuck with the default SPI pins. For multi-screen cascade projects, this flexibility is very important because you can place the SPI pins at the edge of the PCB for easier wiring. But there is a pitfall here: although the ESP32's SPI pin mapping is flexible, not every pin can be used for SPI. For example, GPIO6 through GPIO11 are usually connected to the internal Flash and absolutely must not be us
ed. GPIO34 to GPIO39 are input-only pins and also cannot be used as SPI outputs. When I first used an ESP32 to drive a MAX7219, I casually picked GPIO34 as DIN; it wouldn't light up at all, and after a long time troubleshooting I discovered it was a pin-direction issue. The table below summarizes the pin allocation recommendations I worked out in real projects, applicable to both ESP8266 and ESP32. Chip model | DIN (data) | CLK (clock) | CS (chip select) | Notes. ESP8266 | GPIO13 | GPIO14 | GPIO15 | Use hardware SPI; GPIO15 needs a pull-down. ESP8266 | GPIO13 | GPIO14 | GPIO12 | CS switched to GPIO12 to avoid GPIO15's boot requirement. ESP32 | GPIO23 | GPIO18 | GPIO5 | Default VSPI pins, best compatibility. ESP32 | GPIO13 | GPIO14 | GPIO15 | Custom mapping, suitable when pins are tight. ESP32 | GPIO32 | GPIO33 | GPIO25 | Suitable for avoiding conflicts when sharing the bus with I2C sensors. Note that the ESP8266's GPIO15 must be at a low level at boot, otherwise the chip cannot start normally. If you connect CS to
GPIO15, be sure to add a pull-down resistor, typically 10kΩ; otherwise you may find the program not running after power-on. I have fallen into this pit more than once in early projects. 2.3 Power supply issues: the current trap when multiple dot matrix displays light up at once When all LEDs are lit, each MAX7219 module consumes roughly 100mA to 150mA. If you cascade 4 modules and often display fully lit patterns, the total current may exceed 500mA. The 3.3V regulator on an ESP8266 development board can usually supply only 300mA to 500mA; ESP32 boards are a bit better but still quite limited. The most typical situation I encountered was that a single display tested perfectly, after connecting a second display it began to flicker, and after connecting a third the ESP8266 simply rebooted. At first I thought it was a code problem, but later a multimeter measurement showed the 3.3V voltage dropping below 2.8V when the displays were fully lit — of course the chip would reset. There are two solutions: one is to power the MAX7219 modules separately, using an independent 5V supply while tying the supply's ground to the ESP chip's ground; the other is to reduce the screen brightness by setting the MAX7219's brightness register in software, lowering it to the minimum level
and the current consumption will drop significantly. The MD_MAX72xx library provides a setIntensity function with a range of 0 to 15; I usually set it between 2 and 4, which is clear enough to read without putting too much strain on the power supply. If you are building a desktop dashboard, the screen does not need to be very bright — lower brightness is actually more comfortable. But if you are doing an outdoor display, you must use an independent power supply and consider adding cooling measures. The MAX7219 chip itself generates some heat, and when multiple units are cascaded the heat adds up; for long running times in summer, pay attention to ventilation. 3. Library selection and code architecture: how MD_MAX72xx and MD_Parola work together 3.1 Why choose MD_MAX72xx instead of Adafruit_GFX In the Arduino ecosystem there are several libraries for driving the MAX7219, the most common being LedControl, Adafruit_GFX plus a MAX7219 driver, and MD_MAX72xx. LedControl is too old, has limited features, does not support hardware SPI, and its refresh rate cannot go high. Adafruit_GFX's advantage is a rich set of graphics drawing functions, but its MAX7219 back end performs only average with multi-screen cascading, and its memory usage is
relatively large. MD_MAX72xx is a library designed specifically for the MAX7219; it supports both hardware SPI and software SPI modes, has built-in buffer management, and can control each individual LED on each display. More importantly, its MD_MAX72XX class supports specifying the cascade count and provides a transform function to handle screen orientation issues. MD_Parola, built on top of MD_MAX72xx, wraps features such as text scrolling, alignment, and effects, making it suitable for information-display projects. The main reasons I chose the MD_MAX72xx plus MD_Parola combination are high memory efficiency, stable refresh, and good community support. On the ESP8266, MD_MAX72xx's buffer usage is 8 bytes per display, so 4 displays total 32 bytes, which is perfectly acceptable. MD_Parola's text buffer can also be resized according to actual needs, so it won't eat up too much RAM at once. 3.2 Key parameters in the initialization code: hardware type and cascade count The following code is the initialization part for driving 4 MAX7219 modules on an ESP32, based on the MD_MAX72xx library: #include MD_MAX72x
x.h #include SPI.h #define HARDWARE_TYPE MD_MAX72XX::FC16_HW #define MAX_DEVICES 4 #define CLK_PIN 18 #define DATA_PIN 23 #define CS_PIN 5 MD_MAX72XX mx MD_MAX72XX(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES); void setup() { mx.begin(); mx.control(MD_MAX72XX::INTENSITY, 3); mx.clear(); } There are a few key points to explain here. HARDWARE_TYPE determines how the library maps LED coordinates to chip registers. Common types include FC16_HW, GENERIC_HW, PAROLA_HW, and others. If you are using the most common FC-16 module, the back
is printed with FC-16, then choose FC16_HW. If the displayed characters are mirrored or upside down, try switching to GENERIC_HW. If this parameter is wrong, no amount of code tweaking later will help. MAX_DEVICES is the number of cascaded modules. Note that this number must match the actual number of physical connections; one more or one less will cause display abnormalities. I once counted one extra module, which made the last display show garbled characters, and it took a long time to discover that the count was off. mx.control(MD_MAX72XX::INTENSITY, 3) sets the brightness. The range is 0 to 15; I usually start at 3 — brighter is dazzling, dimmer is hard to read. If you are using an independent power supply, you can raise it a bit. 3.3 How multi-screen text scrolling works: MD_Parola's zone mechanism MD_Parola's most powerful feature is support for multiple display zones. You can split 4 displays into two zones: the left two show the time, and the right two scroll the weather. Each zone can independently set its alignment, scroll speed, and effects. #include MD_Parola.h #include MD_
MAX72xx.h #define HARDWARE_TYPE MD_MAX72XX::FC16_HW #define MAX_DEVICES 4 MD_Parola P MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES); void setup() { P.begin(2); // two zones P.setZone(0, 0, 1); // zone 0 uses display 0 and display 1 P.setZone(1, 2, 3); // zone 1 uses display 2 and display 3 P.setIntensity(3); P.displayZoneText(0, 12:30, PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT); P.displayZoneText(1, Weather: Sunny 25C, PA_LEFT, 50, 0, PA_
SCROLL_LEFT, PA_SCROLL_LEFT); } void loop() { P.displayAnimate(); } P.begin(2) means enabling two zones. The parameters of setZone are the zone number, the starting module index, and the ending module index. Note that indexes start at 0 and are related to the physical order of the screens. If you find zone 0 showing on the right-hand screen, then the indexes are reversed — just swap the start and end. displayZoneText has quite a few parameters, so I will explain them one by one: the first is the zone number, the second is the text content, the third is the alignment, the fourth is the scroll speed in milliseconds per frame, the fifth is the pause time, the sixth is the entry effect, and the seventh is the exit effect. For static display use PA_PRINT and PA_NO_EFFECT; for scrolling display use PA_SCROLL_LEFT. displayAnimate() must be placed in loop() and called continuously; it is responsible for updating the display state of each zone. If you have other time-consuming operations in the loop, such as reading sensors, be careful not to let the lo
op block for too long, otherwise the scrolling will stutter. 4. Five typical problems encountered in real debugging and their troubleshooting paths 4.1 Screen order reversed: the correspondence between data flow and indexes This is the most common problem. You finish wiring, flash the program, and find that what the first display shows has ended up on the last display. The reason is that MAX7219 cascade data is passed forward from the last chip. When the library initializes, it assigns index 0 by default to the chip closest to the CS pin, but physically the one closest to CS may be the rightmost one. The troubleshooting method is simple: write a test program that lights up the first LED of each display in turn and observe which display lights up. Then adjust the start and end indexes of setZone, or use mx.setDeviceAddr during initialization to remap. The MD_MAX72xx library also provides a transform function that can mirror or rotate the entire display buffer, but that affects all screens and is not suitable for adjusting a single one. My experience is to label each display's physical position and index with sticky notes during the wiring stage — for example, mark them 0, 1, 2, 3 from left to right — and then set the zones in the code according to that order. If you find it reversed, do not rush to change the code; first
check whether the wiring order matches your labels. 4.2 Refresh flicker and ESP8266 watchdog reset The ESP8266 has a hardware watchdog; if the loop function takes too long to execute, or if interrupts are disabled for a long time, the watchdog will trigger a reset. MD_Parola's displayAnimate() does a fair amount of computation when scrolling text, and if you are also doing WiFi communication or reading sensors at the same time, it is easy to time out. I once ran into a typical case where the ESP8266 connected to WiFi to fetch network time while also scrolling text with MD_Parola. Every time WiFi reconnected, the screen would flicker a few times and then the ESP8266 would reboot. The serial log showed "wdt reset". The solution is to put WiFi-related operations in a separate scheduled task, or use the yield() function to actively give up CPU time. On the ESP32 this problem is less obvious because the ESP32 is dual-core and you can assign the display task and the network task to different cores. But the ESP32 also has a watchdog; it just has a longer timeout. If you use delay() in the loop, remember to replace it with vTaskDelay(), or at least add yie
本文来源:http://www.lpqz.cn/news/107914
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。