ESP-NOW 触屏遥控小车ESP-NOW Touchscreen Remote Control Car


AI free token/AI免费积分

本文来源:https://mp.weixin.qq.com/s/mTIRI-bxoBCy3zn54ih8fA
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。

这个项目最开始没有想得很复杂,我只是买了一块 2.8 英寸触摸屏,想试试lvgl库。屏幕点亮以后,事情就慢慢变得有意思了:按钮可以切换页面,那就做一个遥控器页面;既然有触摸屏,那就放一个虚拟摇杆;既然 ESP32 自带无线功能,那就再做一块小车端开发板,用 ESP-NOW 把摇杆数据发过去。最后做出来的成品,就是下面这套触屏遥控小车。遥控器主界面是竖屏,点击“遥控器”后会切换成横屏。左边是虚拟摇杆,右边四个按钮分别控制蜂鸣器、灯带开关、灯带亮度增加和灯带亮度降低。小车端收到摇杆数据后,用 L298N 控制左右两个电机的方向和速度。

ESP-NOW 触屏遥控小车
 
 

这套小车现在能做什么

遥控器主界面竖屏显示,遥控页面自动切换为横屏。虚拟摇杆同时输出 X、Y 两路 0-255 的模拟量,中心值为 128。小车支持前进、后退、左转、右转和 PWM 调速。第一个按钮开关有源蜂鸣器。第二个按钮开关 5 颗 WS2812 灯珠。第三个、第四个按钮调节灯带亮度。ESP-NOW 每 50ms 发送一次控制数据。小车超过 500ms 收不到遥控数据时,会自动停下电机并关闭蜂鸣器和灯带。这里没有使用路由器,也不需要填写 Wi-Fi 名称和密码。两块 ESP32 通过 ESP-NOW 直接通信,开机以后就能连接。

一、需要准备的硬件

遥控端

| 硬件 | 数量 | 说明 |

| ESP32 DevKit 开发板 | 1 | 普通 ESP32 双排开发板 |

| LCDWIKI 2.8 英寸 IPS SPI 触摸屏 | 1 | ILI9341 显示芯片,FT6336G 电容触摸 |

| 3.7V 聚合物锂电池 | 1 | 长 30mm、宽 20mm、高 9mm |

| 5V/2A 充放电一体模块 | 1 | Type-C 输入,给 ESP32 和屏幕提供 5V |

| 5.8×5.8mm 六脚自锁开关 | 1 | 遥控器总电源开关 |

| 3D 打印底盒、顶盖 | 各 1 | STL 文件已经放进开源仓库 |

| 导线、螺丝、绝缘材料 | 若干 | 固定和连接使用 |

小车端

| 硬件 | 数量 | 说明 |

| ESP32 DevKit 开发板 | 1 | 负责接收 ESP-NOW 数据 |

| L298N 电机驱动板 | 1 | 控制两路直流电机 |

| TT马达| 2 |

| 小车底盘、车轮 | 1 套 | 两路电机底盘即可 |

| 有源蜂鸣器 | 1 | 高电平鸣叫,信号接 GPIO13 |

| WS2812 灯带 | 5 颗 | 数据输入接 GPIO23 |

|18650锂电池 | 2 颗 | 串联后接入l298N |

小车上的ESP32、蜂鸣器、灯带使用的电源使用的是l298n模块上的5V输出。

屏幕显示部分

图片

锂电池、充放电模块和开关

供电路径可以理解成:

  •  
  •  
3.7V 锂电池 → 5V/2A 充放电模块 → 自锁开关 → ESP32 5V/VIN └→ 屏幕 VCC

不同厂家的充放电模块丝印可能不一样。接线前先确认 B+、B-、OUT+、OUT-,不要只看板子长得像就直接焊。六脚自锁开关也建议先用万用表通断档测出公共端和开关端,再把它串在 5V 输出正极上。锂电池不能反接、短路、挤压或使用破损电芯。装进 3D 打印外壳前,焊点和模块底部要做好绝缘。连接用的导线用的是硅胶线。

三、小车端怎么接线

图片

ESP32 到 L298N

这里有两个很容易踩的坑。第一,ESP32 的 GPIO34、GPIO35 是输入专用引脚,不能输出高低电平,所以不能用来接 L298N 的 IN3、IN4。项目里已经把右轮方向控制改成 GPIO25 和 GPIO14。第二,很多 L298N 模块的 ENA、ENB 默认插着跳帽。我们要用 ESP32 输出 PWM 调速,所以要把这两个跳帽拔掉,再分别接 GPIO27 和 GPIO26。

电机和外设

L298N 的 OUT1、OUT2 接左侧电机。L298N 的 OUT3、OUT4 接右侧电机。有源蜂鸣器 SIG 接 GPIO13。WS2812 的 DIN 接 GPIO23,数量为 5 颗。ESP32 GND、L298N GND、灯带 GND、蜂鸣器 GND 和电机电源负极必须共地。如果小车执行“前进”时某一侧轮子反转,不用改程序,交换那一侧电机的两根输出线即可。

四、电脑上需要安装什么

这个项目使用 Arduino IDE 开发。当前代码已经在下面这组版本上实际编译通过:

| 软件或库 | 已验证版本 | 用途 |

| Arduino IDE | 2.x | 编译和烧录程序 |

| ESP32 Arduino Core | 3.0.4 | ESP32 开发板支持、Wi-Fi 和 ESP-NOW |

| LVGL | 8.3.10 | 遥控端图形界面 |

| Adafruit NeoPixel | 1.15.4 | 小车端 WS2812 灯带 |

遥控端代码已经直接驱动 ILI9341 和 FT6336G,不依赖 TFT_eSPI,因此不用再修改 TFT_eSPI 的 User_Setup.h。

1. 安装 ESP32 开发板支持

打开 Arduino IDE,进入“文件 → 首选项”,在“其他开发板管理器地址”中加入:

  •  
https://espressif.github.io/arduino-esp32/package_esp32_index.json

如果国内网络下载很慢,可以使用 Espressif 官方文档提供的国内镜像地址:

  •  
https://jihulab.com/esp-mirror/espressif/arduino-esp32/-/raw/gh-pages/package_esp32_index_cn.json

然后打开“工具 → 开发板 → 开发板管理器”,搜索 esp32,安装 Espressif Systems 提供的 ESP32 平台。安装完成后选择:

  •  
工具 → 开发板 → ESP32 Arduino → ESP32 Dev Module

再选择开发板对应的 COM 端口。如果上传一直停在 Connecting...,按住开发板 BOOT 键,等开始写入后再松开。

2. 安装 Arduino 库

打开“工具 → 管理库”,分别搜索并安装:

  •  
  •  
lvgl 8.3.10Adafruit NeoPixel 1.15.4

LVGL 一定要选 8.x。LVGL 9.x 的接口已经变化,直接安装最新版会导致这套代码无法编译。项目自带的 lv_conf.h 已经放在遥控端草图目录中,不要删除。它关闭了不需要的功能并把 LVGL 内存控制在 ESP32 可承受的范围内。中文使用项目自带的 font_cn_16.c,不需要再打开 LVGL 的完整中文字体。

五、下载项目代码

项目地址:https://gitee.com/zhoutao10086/esp32chumopingyaokongxiaoche进入 Gitee 页面后点击“克隆/下载 → 下载 ZIP”,解压后会看到两个主要程序目录:

  •  
  •  
LCDWIKI_LVGL_LED 遥控端程序ESP32_L298N_CAR 小车端程序

遥控端打开:

  •  
LCDWIKI_LVGL_LED/LCDWIKI_LVGL_LED.ino

小车端打开:

  •  
ESP32_L298N_CAR/ESP32_L298N_CAR.ino

建议先烧录小车端,因为遥控端需要填写小车 ESP32 的 MAC 地址。

六、先烧录小车端

  1. 用 USB 连接小车上的 ESP32。
  2. Arduino IDE 打开 `ESP32_L298N_CAR.ino`。
  3. 选择 `ESP32 Dev Module` 和正确的 COM 端口。
  4. 点击“验证”,确认编译通过。
  5. 点击“上传”。
  6. 上传完成后打开串口监视器,波特率选择 `115200`。

正常情况下会看到类似输出:

  •  
  •  
Car ESP32 MAC: 88:13:BF:0B:58:ACESP-NOW car receiver ready

每块 ESP32 的 MAC 地址都不同,把自己串口里显示的地址记下来。如果显示 00:00:00:00:00:00,通常是读取 MAC 前没有正确启动 Wi-Fi STA 模式。仓库里的当前版本已经处理了这个问题,不需要另外改代码。

七、修改并烧录遥控端

打开 LCDWIKI_LVGL_LED.ino,在文件开头找到:

  •  
static uint8_t CAR_MAC[] = {0x88, 0x13, 0xBF, 0x0B, 0x58, 0xAC};

把它替换成刚才读到的小车 MAC。写法不是冒号分隔,而是六个 0x 开头的十六进制数字。例如小车 MAC 是:

  •  
24:6F:28:11:22:33

代码就写成:

  •  
static uint8_t CAR_MAC[] = {0x24, 0x6F, 0x28, 0x11, 0x22, 0x33};

然后连接遥控端 ESP32,选择开发板和端口,依次点击“验证”和“上传”。遥控端和小车端当前都使用 ESP-NOW 信道 1,不要只改其中一端的信道。遥控端程序包含 LVGL 和中文字体,编译时间会比小车端长一些。当前版本实际编译后,Flash 使用约 84%,动态内存使用约 25%,普通 ESP32 Dev Module 可以运行。

八、第一次联调

第一次上电建议把车轮架空,不要直接放在地上。摇杆不是只有“开”和“关”。离中心越远,输出值变化越大,电机 PWM 占空比也越高,所以可以控制速度。中心附近设置了死区,避免手指松开后数值轻微抖动导致小车慢慢爬行。

九、装进 3D 打印外壳

仓库根目录中有两个模型:

  •  
  •  
底盒.stl顶盖.stl

打印前确认切片软件使用毫米作为单位。先空装 ESP32、屏幕、电池、充放电模块和开关,确认 Type-C 接口、开关和 USB 烧录口都能从外壳开孔处正常使用,再进行焊接和固定。电池不要被螺丝、焊点或板脚顶住。模块底部可以贴青稞纸或其他可靠绝缘材料,导线留出少量活动余量,但不要压到屏幕排针。

十、常见问题

屏幕有背光,但没有画面

先检查 CS、DC、RST、MOSI、SCK,尤其是 GPIO2、GPIO13、GPIO14、GPIO15 和 GPIO27。确认屏幕型号确实是 ILI9341,并且使用仓库中的完整遥控端目录编译,不要只复制 .ino 而漏掉 lv_conf.h 和中文字体文件。

编译时提示 .dram0.bss will not fit

这通常是 LVGL 配置、绘图缓冲或中文字体占用太大。不要开启完整 CJK 字库,也不要把绘图缓冲改成整屏。仓库当前版本使用 8 行绘图缓冲和精简中文字体,已经解决这类内存溢出。

中文只显示一个字,或者出现方框

确认 font_cn_16.c 与 .ino 在同一个 Arduino 草图目录中。这个字体只包含界面实际用到的汉字,后续新增中文按钮时,也要重新把新汉字加入字体。

摇杆圆点跑到右下角或不跟手

不要把触摸原始坐标直接当成横屏坐标。当前代码已经按照竖屏触摸坐标进行横屏映射,并根据摇杆控件的实际中心计算圆点位置。

遥控有界面,但小车没有反应

依次检查:遥控端 CAR_MAC 是否真的是这块小车 ESP32 的 MAC。两端 ESP-NOW 信道是否一致,当前默认都是 1。小车串口是否显示收到 X、Y、buttons 和 brightness 数据。ESP32、L298N 和电机电源是否共地。IN3、IN4 是否还错误地接在 GPIO35、GPIO34。

电机只能全速,不能调速

检查 L298N 的 ENA、ENB 跳帽是否已经拔掉,并确认 ENA 接 GPIO27、ENB 接 GPIO26。

小车前进方向相反

如果两边都反,可以在程序里反转方向;如果只有一边反,最简单的方法是交换那一侧电机的两根输出线。

项目代码和模型

完整代码、演示视频、中文字体、接线说明以及遥控器外壳 STL 文件都放在 Gitee:https://gitee.com/zhoutao10086/esp32chumopingyaokongxiaoche项目还会继续增加功能。现在这套结构已经把屏幕界面、触摸输入、ESP-NOW 通信、电机 PWM、蜂鸣器、灯带和便携供电串了起来,后面无论加舵机、传感器还是更多页面,都可以在这个基础上继续做。

 

This article is sourced from: https://mp.weixin.qq.com/s/mTIRI-bxoBCy3zn54ih8fA If there are copyright issues, please contact us at: 13951431913#139.com or submit a comment on the right.

At the beginning of this project, I didn’t have complex plans — I just bought a 2.8-inch touchscreen to try out the LVGL library. Once the screen lit up, things started getting interesting: buttons could switch pages, so I made a remote control page; since it’s a touchscreen, I added a virtual joystick; given ESP32’s built-in wireless, I created a car-side development board and used ESP-NOW to send joystick data. The final product is the touchscreen-controlled car shown below. The remote’s main interface is in portrait, which switches to landscape when “Remote” is clicked. On the left is the virtual joystick; on the right are four buttons for buzzer, LED strip on/off, and brightness control. The car receives joystick data and uses an L298N to control motor direction and speed.

What can this car do now?

The remote’s main interface is in portrait; the control page automatically switches to landscape. The virtual joystick outputs two 0–255 analog signals (X, Y) with center value 128. The car supports forward, backward, left, right, and PWM speed control. Button 1 toggles the active buzzer. Button 2 toggles 5 WS2812 LEDs. Buttons 3 and 4 adjust LED brightness. ESP-NOW sends control data every 50 ms. If the car doesn’t receive data for >500 ms, it stops motors and turns off buzzer/LEDs. No router or Wi-Fi password is needed — the two ESP32s communicate directly via ESP-NOW after power-on.

Hardware required

For the remote side:

| Component | Quantity | Notes |

| ESP32 DevKit board | 1 | Standard dual-row ESP32 |

| LCDWIKI 2.8" IPS SPI touchscreen | 1 | ILI9341 display, FT6336G capacitive touch |

| 3.7V polymer lithium battery | 1 | 30×20×9 mm |

| 5V/2A charge-discharge module | 1 | Type-C input, supplies 5V to ESP32 and screen |

| 5.8×5.8 mm 6-pin self-locking switch | 1 | Main power switch for remote |

| 3D-printed case (bottom+top) | 1 ea. | STL files in repo |

| Wires, screws, insulation | As needed | for mounting and connection |

For the car side:

| Component | Quantity | Notes |

| ESP32 DevKit board | 1 | Receives ESP-NOW data |

| L298N motor driver | 1 | Controls two DC motors |

| TT motors | 2 | |

| Car chassis and wheels | 1 set | For dual-motor drive |

| Active buzzer | 1 | High-level activates, connected to GPIO13 |

| WS2812 LED strip | 5 LEDs | Data input at GPIO23 |

| 18650 lithium batteries | 2 | In series, power L298N |

The car’s ESP32, buzzer, and LEDs are powered from the L298N’s 5V output.

Display features

图片

Battery and power handling

The power flow: lithium battery → charge-discharge module → switch → ESP32 and screen. The switch allows cutting off power cleanly. Charge-discharge modules vary by vendor; verify B+, B-, OUT+, OUT- labels before soldering. Test the 6-pin switch with multimeter to identify common and switched pins. Protect battery from reverse polarity, short circuit, or physical damage. Insulate all connections and components within the case.

Car wiring

图片

图片

ESP32 to L298N

There are two common pitfalls here. First, ESP32's GPIO34 and GPIO35 are input-only pins that cannot output high or low levels, so they cannot be used to drive L298N's IN3 and IN4. The project has already updated the right wheel direction control to use GPIO25 and GPIO14. Second, many L298N modules have jumper caps on ENA and ENB by default. Since we need ESP32 to output PWM for speed control, these jumpers must be removed, and ENA and ENB should be connected to GPIO27 and GPIO26 respectively.

Motors and Peripherals

L298N's OUT1 and OUT2 are connected to the left motor. L298N's OUT3 and OUT4 are connected to the right motor. An active buzzer's signal pin is connected to GPIO13. The DIN of the WS2812 LED strip is connected to GPIO23, with a total of 5 LEDs. The grounds of ESP32, L298N, LED strip, buzzer, and motor power source must be connected together. If one wheel spins in the opposite direction during a "forward" command, you do not need to change the software — simply swap the two output wires for that motor.

What is needed on the computer?

This project uses Arduino IDE for development. The current code has been successfully compiled with the following versions:

| Software or Library | Verified Version | Purpose |

| Arduino IDE | 2.x | Compilation and uploading of programs |

| ESP32 Arduino Core | 3.0.4 | Support for ESP32 board, Wi-Fi, and ESP-NOW |

| LVGL | 8.3.10 | Graphical interface for the remote control |

| Adafruit NeoPixel | 1.15.4 | Control of the WS2812 LED strip on the car |

The remote control code directly drives the ILI9341 and FT6336G without relying on TFT_eSPI, so there is no need to modify User_Setup.h.

1. Installing ESP32 Board Support

Open Arduino IDE, go to "File → Preferences", and add the following URL to "Additional Board Manager URLs":

If downloading is slow due to network conditions in China, you can use the domestic mirror address provided in the Espressif official documentation:

Then, open "Tools → Board → Board Manager", search for esp32, and install the ESP32 platform provided by Espressif Systems. After installation, select:

Also choose the correct COM port corresponding to the development board. If the upload gets stuck at "Connecting...", press the BOOT button on the board, and release it once the writing process begins.

2. Installing Arduino Libraries

Open "Tools → Manage Libraries" and search for and install:

It is crucial to select LVGL 8.x, as the interfaces in LVGL 9.x have changed, which would make this specific code incompatible. The project includes a custom lv_conf.h file in the remote control sketch directory; do not delete this, as it disables unnecessary features and limits LVGL's memory usage to within the capacity of the ESP32. The project uses its own font_cn_16.c for Chinese characters, so there is no need to enable the full Chinese font support in LVGL.

Downloading the Project Code

Project Address: https://gitee.com/zhoutao10086/esp32chumopingyaokongxiaocheOn the Gitee page, click "Clone/Download → Download ZIP". After extracting, you will find two main program directories:

Open the remote control sketch:

Open the car sketch:

It is recommended to upload the car's firmware first, as the remote control program requires the MAC address of the car's ESP32.

Uploading the Car Firmware First

Connect the car's ESP32 to your computer via USB.

Open ESP32_L298N_CAR.ino in Arduino IDE.

Select "ESP32 Dev Module" and the appropriate COM port.

Click "Verify" and make sure the compilation passes.

Click "Upload".

After the upload is complete, open the serial monitor and set the baud rate to `115200`.

You should see output similar to:

Each ESP32 has a different MAC address. Write down the address shown in your serial output. If it displays 00:00:00:00:00:00, it usually means the Wi-Fi STA mode was not properly initialized before reading the MAC. The current version in the repo has fixed this, so no additional code changes should be necessary.

VII. Modify and Burn the Remote Control End

Open LCDWIKI_LVGL_LED.ino. At the beginning of the file, you will find:

Replace this with the MAC address of the car you just recorded. The format is not colon-separated; it uses six hexadecimal numbers preceded by 0x. For example, if the car MAC is:

The code should be written as:

Then, connect the remote control ESP32 board, select the development board and port, and click "Verify" and "Upload" in sequence. Both the remote control and the car are currently using ESP-NOW channel 1. Do not change the channel on only one side. The remote control program includes LVGL and Chinese fonts, so the compilation time will be longer than the car side. The current version uses approximately 84% of the Flash and 25% of the dynamic memory, which is manageable for a standard ESP32 Dev Module.

VIII. First Tune-up

For the first power-on test, it is recommended to lift the car wheels off the ground rather than placing them directly on the floor. The joystick is not a simple "on/off" switch; moving it further from the center increases the output value, which in turn increases the PWM duty cycle of the motors, allowing for speed control. There is a "dead zone" near the center to prevent the car from creeping due to slight finger movements when the joystick is released.

IX. Assembly into the 3D Printed Case

The root directory of the repository contains two models:

Before printing, ensure the slicing software is using millimeters as the unit. First, perform a dry fit with the ESP32, screen, battery, charger module, and switch to confirm that the Type-C interface, switch, and USB programming port align correctly with the case openings. Then, proceed with soldering and securing the components. Make sure the battery is not pinched by screws, solder points, or board edges. You can stick insulating paper to the bottom of the modules and leave some slack in the wiring to avoid putting pressure on the screen's ribbon cable.

X. Common Issues

The screen is backlit but shows no image.

Check the CS, DC, RST, MOSI, and SCK lines, particularly GPIO2, GPIO13, GPIO14, GPIO15, and GPIO27. Verify that the screen is indeed an ILI9341 model and that the full remote control directory from the repo (including lv_conf.h and the Chinese font file) was used during compilation, rather than just copying the .ino.

The compilation error ".dram0.bss will not fit".

This indicates that the LVGL configuration, drawing buffer, or Chinese fonts are occupying too much memory. Avoid using the full CJK character set or setting the drawing buffer to a full screen. The current repo version uses an 8-row buffer and a compact font, eliminating this overflow.

Chinese text displays as a single character or as boxes.

Confirm that font_cn_16.c is in the same Arduino sketch directory as the .ino. This font contains only the characters used in the interface; if new Chinese buttons are added later, the font must be updated to include those characters.

The joystick circle is stuck in the bottom-right or is unresponsive.

Do not use the raw touch coordinates directly as screen coordinates. The current code already maps vertical touch coordinates to a horizontal layout and calculates the center of the joystick control accordingly.

The remote has a working interface, but the car does not respond.

Verify the following: Check if the CAR_MAC in the remote matches the actual MAC of the car board. Ensure both ends are using the same ESP-NOW channel (currently 1). Check the car's serial monitor to see if data (X, Y, buttons, brightness) is being received. Confirm that the ground lines for the ESP32, L298N, and motor power are connected. Finally, ensure IN3 and IN4 are not mistakenly connected to GPIO35 and GPIO34.

The motor runs at full speed and cannot slow down.

Check the L298N module. Ensure the ENA and ENB jumper caps are removed and that ENA is connected to GPIO27 and ENB is connected to GPIO26.

The car is moving in the opposite direction.

If both wheels move in the wrong direction, you can invert the direction in the program. If only one side is reversed, the easiest fix is to swap the two output wires for that specific motor.

Project code and model

The complete code, demonstration video, Chinese font, wiring instructions, and remote control shell STL file are all located on Gitee: https://gitee.com/zhoutao10086/esp32chumopingyaokongxiaoche. The project will continue to add features. Currently, this setup connects the screen interface, touch input, ESP-NOW communication, motor PWM, buzzer, LED strip, and portable power supply. In the future, components like servos, sensors, or additional pages can be added based on this foundation.

ESP-NOW Touchscreen Remote Control Car

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

📮 需求咨询📮 Inquiry