VnRoboVnRobo
AboutPricingBlogContact
πŸ‡»πŸ‡³VISign InStart learning
πŸ‡»πŸ‡³VI
VnRobo logoVnRobo logo

Learn Physical AI and experiment in your browser. Connect your fleet when you have real robots.

Product

  • Features
  • Pricing
  • Knowledge Base
  • Services

Company

  • About Us
  • Blog
  • Contact

Legal

  • Privacy Policy
  • Terms of Service

Β© 2026 VnRobo. All rights reserved.

Made withβ™₯in Vietnam
VnRoboVnRobo
AboutPricingBlogContact
πŸ‡»πŸ‡³VISign InStart learning
πŸ‡»πŸ‡³VI
  1. Home
  2. Blog
  3. Micro-ROS: Connecting Microcontrollers to ROS 2 Ecosystem
otherroboticsros2embedded

Micro-ROS: Connecting Microcontrollers to ROS 2 Ecosystem

Micro-ROS brings ROS 2 to microcontrollers like ESP32 and STM32, extending ROS 2 ecosystem down to embedded layer.

Nguyen Anh TuanSeptember 15, 20254 min readUpdated: Nov 14, 2026
Micro-ROS: Connecting Microcontrollers to ROS 2 Ecosystem

What is Micro-ROS?

Micro-ROS brings ROS 2 to microcontroller world. Instead of running ROS 2 on Linux, create ROS 2 nodes directly on ESP32, STM32, or Arduino β€” microcontrollers with only few hundred KB RAM.

Micro-ROS uses DDS-XRCE (DDS for eXtremely Resource Constrained Environments) β€” lightweight DDS version that ROS 2 uses. A micro-ROS agent running on Linux acts as bridge between microcontroller and ROS 2 system.

Architecture

code
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      Serial/WiFi/USB      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Microcontroller β”‚ ◄──────────────────────► β”‚  micro-ROS      β”‚
β”‚  (ESP32/STM32)   β”‚      DDS-XRCE             β”‚  Agent (Linux)  β”‚
β”‚  micro-ROS clientβ”‚                            β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                         β”‚ DDS
                                                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
                                                β”‚  ROS 2 System   β”‚
                                                β”‚  (Nav2, MoveIt) β”‚
                                                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Circuit board and ESP32 microcontroller for robotics application
Circuit board and ESP32 microcontroller for robotics application

Installing Micro-ROS for ESP32

1. Install Micro-ROS Agent

bash
# Create ROS 2 workspace
mkdir -p ~/microros_ws/src && cd ~/microros_ws/src
git clone -b humble https://github.com/micro-ROS/micro_ros_setup.git
cd ~/microros_ws

colcon build
source install/setup.bash

# Create agent
ros2 run micro_ros_setup create_agent_ws.sh
ros2 run micro_ros_setup build_agent.sh

2. ESP32 Firmware with PlatformIO

ini
; platformio.ini
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
    https://github.com/micro-ROS/micro_ros_platformio
board_microros_transport = wifi

3. ESP32 Code β€” Publish Sensor Data

cpp
#include <micro_ros_arduino.h>
#include <rcl/rcl.h>
#include <rclc/rclc.h>
#include <sensor_msgs/msg/imu.h>

rcl_publisher_t imu_publisher;
sensor_msgs__msg__Imu imu_msg;
rclc_executor_t executor;
rcl_timer_t timer;

void timer_callback(rcl_timer_t *timer, int64_t last_call_time) {
    // Read IMU (example MPU6050)
    imu_msg.linear_acceleration.x = read_accel_x();
    imu_msg.linear_acceleration.y = read_accel_y();
    imu_msg.linear_acceleration.z = read_accel_z();
    imu_msg.angular_velocity.x = read_gyro_x();
    imu_msg.angular_velocity.y = read_gyro_y();
    imu_msg.angular_velocity.z = read_gyro_z();

    // Publish to topic /imu/data
    rcl_publish(&imu_publisher, &imu_msg, NULL);
}

void setup() {
    // Connect WiFi to agent
    set_microros_wifi_transports("WIFI_SSID", "WIFI_PASS", "192.168.1.100", 8888);

    rcl_allocator_t allocator = rcl_get_default_allocator();
    rclc_support_t support;
    rclc_support_init(&support, 0, NULL, &allocator);

    rcl_node_t node;
    rclc_node_init_default(&node, "esp32_imu", "", &support);

    // Create IMU data publisher
    rclc_publisher_init_default(
        &imu_publisher, &node,
        ROSIDL_GET_MSG_TYPE_SUPPORT(sensor_msgs, msg, Imu),
        "/imu/data"
    );

    // Timer 100Hz
    rclc_timer_init_default(&timer, &support, RCL_MS_TO_NS(10), timer_callback);
    rclc_executor_init(&executor, &support.context, 1, &allocator);
    rclc_executor_add_timer(&executor, &timer);
}

void loop() {
    rclc_executor_spin_some(&executor, RCL_MS_TO_NS(10));
}

Subscribe to Control Commands from ROS 2

cpp
rcl_subscription_t cmd_subscriber;
geometry_msgs__msg__Twist cmd_msg;

void cmd_callback(const void *msgin) {
    const geometry_msgs__msg__Twist *msg = (const geometry_msgs__msg__Twist *)msgin;
    float linear = msg->linear.x;   // m/s
    float angular = msg->angular.z; // rad/s

    // Convert to PWM for motors
    int left_pwm = (int)((linear - angular * WHEEL_BASE / 2) * PWM_SCALE);
    int right_pwm = (int)((linear + angular * WHEEL_BASE / 2) * PWM_SCALE);
    set_motors(left_pwm, right_pwm);
}

Running Agent and Connecting

bash
# Run agent over WiFi (UDP)
ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888

# Or over Serial
ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/ttyUSB0

# Check topic from ESP32
ros2 topic list
ros2 topic echo /imu/data

Embedded device and microcontroller connected in ROS 2 system
Embedded device and microcontroller connected in ROS 2 system

Which MCU to Choose?

MCU RAM Flash WiFi Price Rating
ESP32 520KB 4MB Yes ~80K VND Best for prototype, WiFi built-in
STM32F4 192KB 1MB No ~120K VND Better real-time, FreeRTOS
STM32H7 1MB 2MB No ~250K VND High performance, many peripherals
Teensy 4.1 1MB 8MB No ~700K VND 600MHz clock, USB host

Important Notes

  1. WiFi connection unstable β€” use Serial/USB for safety-critical applications
  2. Limited memory β€” each publisher/subscriber consumes ~2-5KB RAM, calculate carefully
  3. No callback queue β€” spin_some must be called frequently, avoid blocking code
  4. QoS must match: micro-ROS node QoS must be compatible with Linux ROS 2 node

Micro-ROS is important bridge between embedded world and ROS 2, allowing you to build complete robot systems from lowest sensor layer to top-level Nav2 navigation, all within one ecosystem. With Python and serial communication, you can also communicate with microcontroller without micro-ROS.

Related Articles

  • Introduction to ROS 2: Next-Generation Robot Programming Framework
  • SLAM and Navigation: How Robots Localize and Move
  • Deploying IoT Applications with Docker and Docker Compose
NT

Nguyα»…n Anh TuαΊ₯n

Robotics & AI Engineer. Building VnRobo β€” sharing knowledge about robot learning, VLA models, and automation.

Explore VnRobo

Fleet MonitoringROS 2 IntegrationAMR Solutions
← Previous
Edge AI with NVIDIA Jetson: Deploy AI on Embedded Devices
Next β†’
Digital Twin in Manufacturing: Smart Factory Simulation

Related Posts

Tutorial
Robotics
ros2roboticstutorial
other

Writing Hardware Interface for ros2_control

Guide to creating custom hardware interface β€” connecting ros2_control to motor driver via serial/CAN bus.

3/18/202610 min read
NT
Robotics
roboticsros2
other

Introduction to ROS 2: Next-Generation Robot Programming Framework

ROS 2 provides powerful distributed architecture, real-time support, and security β€” ideal for industrial and autonomous robots.

6/15/20255 min read
NT
Tutorial
Robotics
ros2monitoringrobot-fleet
other

How to Monitor ROS 2 Robots Remotely: Complete 2026 Guide

Step-by-step tutorial to monitor ROS 2 robots from anywhere β€” battery, CPU, status, heartbeat, alerts. Working code, 10-minute setup. Free for 3 robots.

4/14/20267 min read
NT
VnRobo logoVnRobo logo

Learn Physical AI and experiment in your browser. Connect your fleet when you have real robots.

Product

  • Features
  • Pricing
  • Knowledge Base
  • Services

Company

  • About Us
  • Blog
  • Contact

Legal

  • Privacy Policy
  • Terms of Service

Β© 2026 VnRobo. All rights reserved.

Made withβ™₯in Vietnam