This repository demonstrates a simple use case of micro-ROS with an ESP32 board (specifically the ESP32-S3) to publish Wi-Fi scan data. Additionally, it provides a service to control the board's LED.
Follow the official micro-ROS installation guide to set up micro-ROS. Below is a summary of the steps:
# Source the ROS 2 installation
source /opt/ros/$ROS_DISTRO/setup.bash
# Create a workspace and download the micro-ROS tools
mkdir microros_ws
cd microros_ws
git clone -b $ROS_DISTRO https://github.com/micro-ROS/micro_ros_setup.git src/micro_ros_setup
# Update dependencies using rosdep and pip
sudo apt update && rosdep update
rosdep install --from-paths src --ignore-src -y
sudo apt-get install python3-pip
# Build micro-ROS tools and source them
colcon build
source install/local_setup.bash
# Download micro-ROS-Agent packages
ros2 run micro_ros_setup create_agent_ws.sh
ros2 run micro_ros_setup build_agent.sh
source install/local_setup.bash
Install the Arduino IDE using the following commands:
sudo apt install flatpak -y
sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
flatpak install flathub cc.arduino.arduinoide -y
- Download the micro_ros_arduino library and place it in
~/Arduino/libraries
. - Create custom interfaces for the
esp32_msgs
package:
# Copy the message package to the extra_packages directory
cp -r esp32_msgs ~/Arduino/libraries/micro_ros_arduino/extras/library_generation/extra_packages
# Modify the colcon.meta file to use the parameter server in micro_ros_arduino
# You have to increase the max services to 6
# Take a look at the provided colcon.meta file in this repository
nano ~/Arduino/libraries/micro_ros_arduino/extras/library_generation/colcon.meta
# Create the code for Arduino
cd ~/Arduino/libraries/micro_ros_arduino
docker run -it --rm -v $(pwd):/project --env MICROROS_LIBRARY_FOLDER=extras microros/micro_ros_static_library_builder:humble
# Optional: Copy the ESP32 library for the ESP32-S3 board
cd ~/Arduino/libraries/micro_ros_arduino/src
cp -r esp32 esp32s3
- Open the Arduino IDE.
- Install the Adafruit_NeoPixel library via
Tools > Manage Libraries
. - Install the ESP32 board support package via
Tools > Board > Board Manager
. - Select the correct port (
/dev/ttyACM0
) and the board (ESP32S3 DEV Module
).
- Load the code from the
esp32_node
directory onto the ESP32 board using the Arduino IDE. - Start the micro-ROS agent:
ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/ttyACM0
- Check the
/wifi_scan
topic:
ros2 topic echo /wifi_scan
- Test the
/set_led_color
service:
ros2 service call /set_led_color esp32_msgs/srv/SetLedColor "{'color': {'r': 1, 'g': 0, 'b': 1}}"
- The
esp32_msgs
package defines the custom message and service types used in this project. - Ensure all dependencies are properly installed to avoid build or runtime issues.
This project showcases the seamless integration of an ESP32-S3 board with ROS 2 using micro-ROS, providing an excellent starting point for robotics projects requiring lightweight and efficient communication between devices.