5inch_P4_IDF_14_SX1262_LoRa: ESP32-P4 SX1262 LoRa Transceiver Communication¶
1. Course Introduction¶
This lesson uses two projects to jointly demonstrate SX1262 LoRa communication: the TX project sends an incrementing TX_Hello World:n every second, while the RX project polls the receive flag, reads the data, and displays the message, RSSI, and SNR on the screen. Both ends initialize the LCD, backlight, and SX1262; the RX end additionally registers a callback and creates a receive task.
2. Learning Objectives¶
- Understand the initialization differences between the SX1262 transmitter and receiver.
- Master the TX-side message counting, scheduled tasks, and LVGL label refresh mechanism.
- Master the RX-side receive flag, data length, callback, and RSSI/SNR display.
- Be able to use two development boards to verify LoRa messages and link quality metrics.
3. Preparation¶
- Applicable development boards: CrowPanel Advanced 5-inch ESP32-P4 HMI AI Display development board (two units), and two SX1262 LoRa modules.
- Software: VS Code, ESP-IDF Extension (ESP-IDF v5.5.4 or later).
- Project dependencies: Keep
main/main_tx.cfrom the TX project,main/main_rx.cfrom the RX project, as well as theperipheral/bsp_wirelessandperipheral/bsp_illuminatecomponents and theRadioLibmanaged component. - Configuration: target chip
esp32p4;
Code download link:
4. Software Operation Steps¶
Open the ESP-IDF Extension panel in VS Code, click Open ESP-IDF Project, and select the Lesson14_TX_SX1262_Wireless_Module folder (transmitter).
First, select the code runtime environment ESP-IDF v5.5.4, set the flashing method to UART, and then select the serial port that corresponds to the development board. Next, in the ESP-IDF Extension panel, click Set Espressif Device Target and select esp32p4. After the setup is complete, the status bar should display ESP-IDF v5.5.4, UART, the required COM port, and ESP32-P4.
Click SDK Configuration Editor in the VS Code bottom status bar or the ESP-IDF extension panel, and wait for the configuration page to fully load before modifying parameters. If the page is still loading, do not execute Build immediately.
Enter flash in the search box and ensure Flash SPI mode: QIO; Flash Sampling Mode: STR Mode; Flash SPI speed: 80 MHz; Flash size: 16 MB. These parameters should match the on-board Flash of the Advance-P4.
Enter wireless in the search box, check only Enable SX1262 config, and disable the wireless module configurations for nRF2401, ESP32-C6, ESP32-H2, etc., which are not used in this lesson. This setting must be completed separately for both the TX and RX projects.
Next, refer to "4. Software Operation Steps" in
Lesson07_Turn_on_the_Screento complete the detailed SDK configuration; the relevant configuration methods were covered in Lesson 7.Note: The LVGL font size used in this lesson is 42; please modify it accordingly.
After verifying that the configuration is correct, click Save in the top-right corner; confirm that the changes have been saved before executing Build to compile.
Click Full Clean to clear the cache left over from the previous compilation. Perform this operation after the first compilation, after switching project configurations, or after modifying SDK parameters, to prevent old configurations from affecting new compilation results.
Click Build to compile the TX project.
Connect the first development board, click Select Port to Use to select the corresponding serial port, and then click Flash to flash the TX firmware.
Open the project again and select Lesson14_RX_SX1262_Wireless_Module (receiver). Reconfigure the ESP-IDF version, UART serial port, target chip, Flash, and SX1262 settings by following steps 2–7, then click Full Clean and Build to compile the RX project.
Connect the second development board, click Select Port to Use to select the corresponding serial port, and then click Flash to flash the RX firmware.
Select the serial ports corresponding to the TX and RX development boards respectively, and click Monitor to open the serial monitor. Confirm that the transmitter continuously outputs sending logs and the receiver continuously outputs receiving logs; press Ctrl + ] to exit the monitor.
Finally, you can use the one-click operation button in the ESP-IDF status bar to sequentially execute compilation, flashing, and opening the serial monitor. Use it only after the project configuration, serial port, and code have all been confirmed correct; if you need to locate a problem, you should still follow the steps above one by one.
5. Hardware Operation Steps¶
Confirm that the SX1262 modules and antennas on both development boards are correctly connected, and that the USB cables are also properly connected.
Remember to provide an additional power cable for the product to ensure the development board has sufficient current and the display works without issues.
Then, switch the toggle switch on the 5-inch Advance-P4 to the Wireless Module position.
This is the design on the hardware side.
Switch to UART1 port:
Among the three interfaces shown in the figure, only the UART1 interface can be used at this time.
Alternatively, the expansion header at the bottom can also be used.
That is, either the UART1 interface or the expansion header can be used, but not both.
Switch to Wireless Module port:
Among the three interfaces shown in the figure, only the wireless module can be used at this time.
Alternatively, the expansion header at the bottom can also be used.
That is, either the wireless module or the expansion header can be used, but not both.
Summary:
The UART1 interface and the Wireless Module can only be used when switched to the corresponding port.
The expansion header at the bottom can be used regardless of the position of the mode switch, but it cannot be used simultaneously with the above interfaces. (When used simultaneously, only one of the three interfaces can be selected.)
After resetting the TX board, observe whether the screen displays TX_Hello World:0 and increments the count every second.
After resetting the RX board, observe whether the screen displays the LoRa RX Receiver title and the initial value RX_Hello World:0. 
Place the two boards at close range (e.g., within 1 meter) and observe whether the RX board's count increments as the TX sends, and whether RSSI and SNR update in real time.
Observe whether the TX board's serial port prints TX msg: TX_Hello World:N to confirm it sends once per second.
Observe whether the RX board's serial port prints RX: ... (RSSI: ..., SNR: ...) to confirm successful reception.
6. Key Code Explanation¶
uint32_t i = sx1262_get_tx_counter();
snprintf(text, sizeof(text), "TX_Hello World:%lu", (unsigned long)i);
...
bool lora_tx_OK = send_lora_pack_radio();
After Hardware_Init() initializes I2C, STC8, display, backlight, and sx1262_tx_init(), two periodic tasks are created. The core-0 UI task reads the BSP transmit counter and refreshes the LVGL label; the core-1 TX task calls send_lora_pack_radio() once per second and logs transmission failures. Both use vTaskDelayUntil() for a stable one-second period.
if (sx1262_is_data_received()) {
size_t len = sx1262_get_received_len();
received_lora_pack_radio(len);
}
The RX project initializes sx1262_rx_init(), registers rx_data_callback through sx1262_set_rx_callback(), and pins the receive task to core 1. The task checks the receive flag every 10 ms and passes the actual packet length to the BSP. The callback increments the packet count and updates the RX, RSSI, and SNR labels while holding the LVGL lock.
7. Experimental Observations¶
The TX screen and serial port display an incrementing TX_Hello World:n every second; the RX screen displays RX_Hello World:n and shows RSSI: ... dBm and SNR: ... dB in real time. When the distance, antenna, or frequency band configuration between the two ends does not match, the RX count does not increase or the link metrics do not update.















