Skip to content
RoboticsOctober 3, 2026AdvancedUpdated

Micro-ROS on ESP32 and STM32: Publishing Real-Time Sensor Telemetry over XRCE-DDS

RTJ Editor
RoboTechJournal Contributor
Micro-ROS on ESP32 and STM32: Publishing Real-Time Sensor Telemetry over XRCE-DDS
ContentsIntroduction

Introduction

High-level planning and perception usually run on a Linux host, while a microcontroller handles sensor acquisition and local control. micro-ROS connects that firmware to the ROS 2 graph through an agent. This does not make network telemetry a hard real-time or safety-critical control loop: host scheduling, RTOS scheduling and transport delivery need separate validation.

This guide covers ESP32 and STM32 integration decisions with a ROS 2 Jazzy host. Check board, framework and transport support together; an MCU family name alone is not a compatibility guarantee.

Micro-ROS Architecture and the XRCE-DDS Transport Layer

The MCU runs a resource-constrained micro-ROS client using rcl/rclc APIs. An agent on the host represents its entities in the DDS-based ROS 2 graph. Available publishers, subscriptions and optional services depend on the firmware build and resource limits.

text
Sensor acquisition / local control on MCU                 |          micro-ROS client                 |       Serial or supported UDP transport                 |          micro-ROS Agent                 |          Host ROS 2 / DDS graph

Step 1: Match the Host, Agent and Firmware

Use ROS 2 Jazzy consistently in the host shell, agent and firmware configuration. The example below uses the PlatformIO Arduino integration, not an ESP-IDF component project. Install the upstream prerequisites and record the platform/package versions, library commit and agent image digest once you validate your combination.

Launching the Serial Agent

On a Linux ROS 2 host with Docker available, substitute the actual device path below. Close serial monitors before starting the agent. This maps the selected device and uses Linux host networking for ROS discovery.

bash
docker run -it --rm --net=host \  --device=/dev/ttyUSB0 \  microros/micro-ros-agent:jazzy \  serial --dev /dev/ttyUSB0 -b 115200 -v6

A source-built agent is also an option. When running it directly, the host user needs permission for the serial device; the correct device group depends on the OS. Container device access is configured separately.

Step 2: Configure a Documented ESP32 Target

The upstream PlatformIO support table lists esp32dev with Arduino and serial/Wi-Fi transports. It does not establish universal ESP32-S3 support. For ESP32-S3, verify the exact board, framework version and USB/UART implementation before adapting this configuration; native USB CDC and a USB-to-UART bridge are different paths.

text
[env:esp32dev]platform = espressif32board = esp32devframework = arduinomonitor_speed = 115200board_microros_distro = jazzyboard_microros_transport = seriallib_deps =    https://github.com/micro-ROS/micro_ros_platformio.git

Illustrative Scalar Publisher

This sketch requests a 10 ms timer and sends a placeholder, not measured encoder data. Arduino supplies the task context here; the code does not create a dedicated FreeRTOS task. The timer period is not a measured delivery rate. Start the agent before resetting the board; this minimal example stops on error rather than reconnecting automatically.

cpp
#include <Arduino.h>#include <micro_ros_platformio.h>#include <rcl/rcl.h>#include <rclc/rclc.h>#include <rclc/executor.h>#include <std_msgs/msg/float32.h> rcl_node_t node;rcl_publisher_t publisher;rcl_timer_t timer;rclc_support_t support;rclc_executor_t executor;std_msgs__msg__Float32 message; void require_ok(rcl_ret_t result) {  if (result != RCL_RET_OK) {    while (true) { delay(100); } // No automatic recovery in this example  }} void publish_sample(rcl_timer_t *timer_handle, int64_t) {  if (!timer_handle) return;  message.data = 0.0f; // Placeholder: replace with actual sampled position  require_ok(rcl_publish(&publisher, &message, nullptr));} void setup() {  Serial.begin(115200);  set_microros_serial_transports(Serial);  delay(2000);  // The executor retains this allocator pointer after setup() returns.  static rcl_allocator_t allocator = rcl_get_default_allocator();  require_ok(rclc_support_init(&support, 0, nullptr, &allocator));  require_ok(rclc_node_init_default(&node, "encoder_example", "", &support));  require_ok(rclc_publisher_init_default(    &publisher, &node,    ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Float32), "encoder/position"));  require_ok(rclc_timer_init_default(    &timer, &support, RCL_MS_TO_NS(10), publish_sample));  executor = rclc_executor_get_zero_initialized_executor();  require_ok(rclc_executor_init(&executor, &support.context, 1, &allocator));  require_ok(rclc_executor_add_timer(&executor, &timer));} void loop() {  const auto rc = rclc_executor_spin_some(&executor, RCL_MS_TO_NS(5));  if (rc != RCL_RET_OK && rc != RCL_RET_TIMEOUT) { require_ok(rc); }}

Step 3: Budget Transport, Memory and Time

  • Transport capacity: estimate serialized message size times rate, then account for framing, acknowledgements, retransmission and other topics. There is no universal message-rate threshold at which 115200 baud fails. Raise baud rate only after checking both endpoints, wiring and measured losses. Wi-Fi adds interference, contention and disconnection risks.
  • Memory ownership: allocate strings and sequence buffers with generated message APIs or micro-ROS utilities, define capacities, and keep storage and the allocator object alive while the executor uses them. Avoid unbounded allocation in acquisition callbacks. The scalar Float32 example has no dynamic string or sequence fields.
  • Time synchronization: rmw_uros_sync_session(1000) requests session time synchronization; check the return value and synchronization state before using epoch time. The timeout argument is not a bound on timestamp error. Revisit synchronization after outages and timestamp at acquisition, not merely publication. The Float32 example has no header or synchronized timestamp.

Verification and Testing

Compile and flash for your board, start the matching agent and inspect the graph from a sourced Jazzy host shell:

bash
source /opt/ros/jazzy/setup.bashros2 node listros2 topic info /encoder/position --verboseros2 topic echo /encoder/position# In another terminal: observe delivery, not a real-time guaranteeros2 topic hz /encoder/position

Check message type and QoS before interpreting missing data. In a real sensor implementation, log sequence gaps, acquisition-to-reception delay and agent restarts. These commands are a procedure, not recorded test results.

STM32 Integration and Production Requirements

For STM32, select an integration that explicitly supports your board and framework. PlatformIO's Arduino target list and an STM32Cube/FreeRTOS port are different paths. A Cube project needs its documented transport, allocator, task stack and build settings; the ESP32 Arduino sketch is not a drop-in STM32 project.

Keep local motor control and safe-state handling independent of agent connectivity. Assign clear ownership to buffers and executor access. A nominal 100 Hz timer does not prove deterministic end-to-end delivery, especially over Wi-Fi.

Next Steps: From First Message to Sensor Fusion

Primary Documentation and Limitations

Consult the official PlatformIO board, distribution and transport matrix, micro-ROS publisher/subscriber APIs, executor and timer semantics, time synchronization and agent-ping utilities, and STM32Cube integration requirements. Select documentation branches matching your release. Examples are illustrative and have not been compiled or physically tested by RoboTechJournal. They establish neither universal board compatibility nor latency, throughput or safety guarantees.

More from Robotics

micro-ROS on ESP32: First Publisher and Subscriber
Build GuidesNov 2, 2026Intermediate

micro-ROS on ESP32: First Publisher and Subscriber

Bring up an ESP32 micro-ROS publisher and subscriber over serial, with a Jazzy agent, a small Int32 echo example and host-side verification steps.

ROS 2 Telemetry on ESP32: Debugging Serial, Wi-Fi and Agent Connections
Build GuidesNov 2, 2026Intermediate

ROS 2 Telemetry on ESP32: Debugging Serial, Wi-Fi and Agent Connections

Diagnose ESP32 micro-ROS telemetry layer by layer: firmware build, serial ownership, UDP reachability, agent sessions, ROS 2 graph discovery and QoS.

Fusing IMU, Wheel Odometry, and GPS with ROS 2 robot_localization: A Dual EKF Guide
Build GuidesSep 19, 2026Intermediate

Fusing IMU, Wheel Odometry, and GPS with ROS 2 robot_localization: A Dual EKF Guide

Fuse wheel odometry, IMU, and GPS with robot_localization. Configure dual EKFs, heading conventions, navsat transforms, covariance, and TF ownership.