Hardware

STM32 Wireless UART to PC: HC-05, ESP32, nRF24L01 Options

HC-05, ESP8266/ESP32, and nRF24L01 options for STM32F373 UART-like PC communication. Covers wiring, UART/HAL/DMA setup, framing protocols and tradeoffs.

1 answer 1 view

What are the best methods for wireless bidirectional data exchange between STM32F373 microcontroller and a PC?

Currently using UART for a temperature sensor device, I want to implement wireless communication similar to wired UART: send commands from PC to STM32 (e.g., ‘Start measurement’ or ‘Change sensor settings’) and receive responses (measurement results or confirmation messages).

Considered Bluetooth modules like HC-05 or HC-06. What are reliable options, configuration steps, and alternatives (e.g., WiFi, NRF24L01)? Share experiences with implementation on STM32.

Bluetooth SPP modules (HC‑05/HC‑06), Wi‑Fi modules (ESP8266/ESP32) and 2.4 GHz transceivers (nRF24L01+) are the quickest, most practical paths for STM32 wireless communication that behave like a wired UART for PC bidirectional data exchange. HC‑05 gives a near plug‑and‑play virtual COM port on the PC; ESP modules let you bridge UART to TCP/HTTP (or implement a transparent socket) for networked control; nRF24L01+ is cheap and low‑power but needs a USB/ MCU bridge on the PC. Below I compare those options, list wiring and STM32F373 configuration steps, show example AT/HAL snippets, and share real‑world tips and tradeoffs.


Contents


Bluetooth modules (HC-05 / HC-06) for STM32 wireless communication

Why pick Bluetooth SPP? Because it’s the closest thing to “wireless UART” out of the box: the PC sees a virtual COM port (Windows), or you can bind /dev/rfcommX on Linux and talk serial. That makes sending commands like “START” and getting measurement results trivial.

What to use

  • HC‑05: Classic Bluetooth SPP, configurable as master or slave via AT mode. Good for pairable serial bridging and quick prototypes.
  • HC‑06: Simpler, usually slave‑only and less configurable (still fine if you only need one slave device).

Wiring checklist (STM32F373 → HC‑05)

  • Cross TX/RX: STM32 TX → HC‑05 RX, STM32 RX ← HC‑05 TX. Ground common.
  • Power: use 3.3 V for raw modules; many HC‑05 boards include a regulator and accept 5 V — check your board. Add a 10–100 µF decoupling cap near VCC.
  • Disconnect RX/TX when flashing STM32 (many boards block the bootloader) — common tip from community examples.

Basic AT examples (enter AT mode per module docs)

  • AT — should return OK
  • AT+NAME=STM32_TEMP
  • AT+PSWD=1234
  • AT+UART=115200,0,0 -> set baud to 115200

STM32 / PC notes

References & examples: HC‑05 with STM32CubeIDE / HAL guides and sample projects [https://microcontrollerslab.com/hc-05-bluetooth-module-stm32-blue-pill-stm32cubeide/], basic interfacing tutorials [https://embeddedthere.com/stm32-bluetooth-module-hc-05-interfacing-with-hal-code-example/], and Instructables setup notes [https://www.instructables.com/HC05-Bluetooth-Module-Interfacing-With-STM32F401CC/].


WiFi (ESP8266 / ESP32) for STM32 PC bidirectional data exchange

If you want your PC to reach the STM32 over a LAN (or remotely with port forwarding/VPN), Wi‑Fi is the right choice. ESP8266 modules (ESP‑01, etc.) are cheap and commonly used as UART‑to‑Wi‑Fi bridges; ESP32 gives more horsepower, native TLS, BLE, and better firmware options.

Common modes

  • AT‑firmware transparent bridge: STM32 talks UART → ESP converts to TCP/UDP. Example AT flow: AT+CWJAP="SSID","PASS" then AT+CIPSERVER=1,1234 (server) or AT+CIPSTART="TCP","1.2.3.4",1234 (client). See step‑by‑step guides [https://controllerstech.com/stm32-esp8266-wifi-ip/] and [https://controllerstech.com/esp8266-webserver-using-stm32-hal/].
  • Custom ESP firmware: write socket/HTTP/WebSocket server on the ESP (recommended for production). Use ESP‑IDF or Arduino framework on the ESP32 to implement robust reconnection, TLS, and JSON parsing.
  • ESP‑Now: very low‑latency peer‑to‑peer for ESP↔ESP, but not suitable if PC must connect directly.

Advantages vs Bluetooth

  • Higher throughput and network access from any PC on LAN.
  • Easier to implement logging, file upload, OTA, or HTTP API.
  • Slightly more complex initial setup and dependency on network/router.

Implementation tips

  • Use TCP server on ESP if you want a simple “telnet‑like” experience from a PC (netcat or telnet) — fast to test.
  • If using AT firmware, check and harden AT settings, then move to custom firmware for reliability.
  • For production, prefer ESP32 (more stable, hardware crypto support) and use sockets or MQTT for structured comms.

See practical writeups and options for adding Wi‑Fi to STM32 boards [https://pcbartists.com/design/embedded/stm32-wifi-options/] and examples bridging STM32 ↔ ESP32 [https://www.espboards.dev/blog/stm32-wifi-connectivity-with-esp32/]. For advanced scenarios (wireless programming/bootloading) see ST community threads about programming via ESP modules [https://community.st.com/t5/stm32-mcus-products/programming-stm32-mcu-using-esp8266-over-wifi/td-p/148260].


NRF24L01+ for STM32 wireless communication (micro‑to‑micro)

NRF24L01+ modules are cheap, low‑power 2.4 GHz transceivers that speak SPI to the STM32. They’re excellent for micro‑to‑micro links (low latency, configurable data rate: 250 kbps / 1 Mbps / 2 Mbps). But they’re not PC‑native — the PC needs a USB bridge (an Arduino/Nucleo or a dedicated USB dongle that forwards packets to a COM port or socket).

Key points

When to choose NRF24L01+

  • If you need low power and you control both ends (STM32 ↔ another MCU).
  • If you can add a small PC‑side bridge (USB MCU running driver/serial) to expose data to the PC.

If you need PC‑native WiFi or Bluetooth access, prefer ESP or HC‑05 instead.


Implementation steps & STM32F373 configuration (UART, HAL, DMA)

Step 1 — pick the module

  • Quick plug‑and‑play: HC‑05 (Bluetooth SPP).
  • Networked PC access: ESP8266 (cheap) or ESP32 (recommended for production).
  • Micro‑to‑micro low power: NRF24L01+ (needs PC bridge).

Step 2 — wiring & power

  • Cross TX/RX, common GND.
  • Use stable 3.3 V supply (modules can draw spikes). Add 10–100 µF bulk cap.
  • Verify logic levels — STM32F373 is 3.3 V, so direct connect is fine.

Step 3 — STM32 UART setup (CubeMX/HAL)

  • Create USART peripheral with matching baud (HC‑05 default 9600; ESP often 115200).
  • Use DMA circular RX for continuous streams; this avoids data loss. Example pattern:
/* start circular DMA receive */
HAL_UART_Receive_DMA(&huart1, dma_rx_buf, DMA_RX_SIZE);

/* in main loop, process buffer using dma pointer */
  • Implement a ring buffer and a parser that handles complete frames (e.g., newline terminated or length + CRC). Don’t rely on single‑byte reads for production.

Step 4 — framing / protocol

  • Keep commands small and simple: CMD:START\n, CMD:SET,INTERVAL=5\n.
  • Send responses as OK:MEAS,25.3,units\n.
  • Add simple CRC or sequence numbers if you need integrity.

Step 5 — PC side testing

  • For HC‑05: use PuTTY (Windows COM) or screen/nc (Linux).
  • For ESP Wi‑TCP mode: use telnet ip port or nc ip port.
  • For BLE GATT: use nRF Connect or write a small client (python Bleak).

Step 6 — robustness & production

  • Add ACK/timeout and retransmit at the application level.
  • Monitor module power — Wi‑Fi needs more headroom.
  • Use pairing/WPA and application auth tokens to prevent accidental control.

Real‑world tips from implementations

  • Always disconnect RX/TX when programming the STM32 (common cause of failed uploads) — multiple community tutorials stress this.
  • If you see resets, measure the 3.3 V rail under load; add a beefier regulator.
  • For high throughput, prefer ESP32 and hardware RTS/CTS if available.

Practical code and tutorials referenced above: HC‑05 HAL examples [https://microcontrollerslab.com/hc-05-bluetooth-module-stm32-blue-pill-stm32cubeide/], ESP8266 webserver patterns [https://controllerstech.com/esp8266-webserver-using-stm32-hal/].


Tradeoffs, common pitfalls and recommendations

Short comparison

  • HC‑05 (Bluetooth SPP): Easiest — virtual COM on PC, minimal code. Range ≈ 10 m, simple pairing. Not ideal if you need network access.
  • ESP8266 / ESP32 (Wi‑Fi): Networked, higher throughput, accessible from any PC on LAN, supports HTTPS/MQTT/OTA (ESP32 best). More setup complexity.
  • NRF24L01+: Cheap, low power, good for mesh/micro networks; requires bridge to PC.
  • BLE (STM32WB or nRF modules): Low energy, modern stacks — but GATT model is different from UART and often needs a custom PC app.

My pick for your temperature sensor (STM32F373)

  • For fastest route: HC‑05 — you’ll get a virtual COM and can reuse your UART code with minimal changes.
  • For LAN access, remote control, or integrating into dashboards: ESP32 — implement a TCP server or use MQTT to publish measurements.
  • For battery‑powered nodes needing long life: NRF24L01+ or BLE with off‑board gateway.

Common pitfalls

  • Wrong power rails or weak regulators.
  • Leaving serial pins connected during flashing.
  • Mismatched baud, parity, or flow control.
  • Assuming BLE provides an SPP‑like serial profile (it doesn’t — GATT is different).

Security notes

  • Change default pairing codes; use WPA2 for Wi‑Fi; consider at‑app authentication and short‑lived tokens for commands.

Sources


Conclusion

For a UART‑like wireless link between your STM32F373 temperature sensor and a PC, HC‑05 gives the fastest path: minimal code changes and a virtual COM port on the PC. If you need LAN access, higher throughput, or OTA, move to an ESP32/ESP8266 bridge and use TCP/MQTT/HTTP. Choose nRF24L01+ when you control both ends and care about power and cost — but plan a PC‑side bridge. Whichever path you pick, use a robust framing protocol, DMA RX on the STM32 UART, a stable 3.3 V supply, and test with simple terminal tools before adding complexity to your firmware.

Authors
Verified by moderation
Moderation
STM32 Wireless UART to PC: HC-05, ESP32, nRF24L01 Options