Introduction to ROS Part 12: Talking to Microcontrollers
In this final episode of the ROS 2 tutorial series, we bridge the gap between simulation and the real world by integrating ROS 2 with actual robot hardware. A common point of confusion for newcomers is why ROS does not include many seemingly obvious hardware libraries for controlling robots (e.g. motors and sensors). The reason is that ROS is designed as a middleware: it works best as a modular, scalable multiprocessing communication platform. It’s not meant for hard, real-time control. In this video, we’ll look at why time-critical tasks (like PWM motor control) and interrupt handing are better handled by a microcontroller and how ROS 2 nodes can communicate with that microcontroller to control a physical robot. The written guide for this episode can be found here: https://www.digikey.com/en/maker/projects/intro-to-ros-part-12-talking-to-microcontrollers/d6b8d95a44f845cc87f640aee6f3f3c7 The GitHub repository containing the Docker image and example code for this series can be found here: https://github.com/ShawnHymel/introduction-to-ros The demo uses a Raspberry Pi 4B running Ubuntu 24.04 and ROS 2 Jazzy as the high-level computer, paired with a Raspberry Pi RP2350-based controller on the XRP educational robotics platform for low-level motor control. We walk through setting up serial communication over USB, writing simple Arduino firmware to parse motor commands, and building a Python ROS 2 node that sends those commands in real time. Along the way, you’ll see practical considerations like Linux’s non-deterministic scheduling, why microcontrollers are essential for real-time robotics, and how this SBC + MCU architecture scales to more complex systems. We’ll briefly cover installing ROS 2 on a Raspberry Pi, configuring SSH and VS Code for remote development, setting up a Python virtual environment, and creating a custom ROS 2 package with colcon. The example driver node implements a small state machine that drives, turns, and stops the robot by sending serial commands, which demonstrates a clean separation between high-level robot logic in ROS 2 and low-level hardware control on the microcontroller. To close out the series, the video shows how this architecture enables more advanced robotics features like computer vision and autonomy. Using OpenCV, a ROS 2 vision node tracks a colored object and publishes bounding box data, while a driver node subscribes to that data and steers the robot toward the target in real time. This final project highlights the real power of ROS 2: combining perception, decision-making, and hardware control into a scalable system.