This project is a ROS2 LED Strip controller written in C++ using pigpio with button input for switching colors, running with pigpio
on a Raspberry Pi Model 3B+.
- The
led_strip_output
node defines a subscriber for"led_controller1/new_color"
, astd_msgs::msg::ColorRGBA
object. Upon receipt of a new color by any publisher, the node will set the LED strip to that color. - The
button_pub
node defines a publisher for"led_controller1/new_color"
according to GPIO input from a pushbutton. Depending on which color is next in the queue, a button press will immediately publish a new color. The color rotation goes as follows:White → Red → Blue → Purple → Medium Slate Blue → Off → White
. New colors can be added in thebutton_pub.cpp
file in the node's constructor.
- 24V LED strip and power supply with RGB input
- 3 logic-level mosfets for LED strip control
- Raspberry Pi 3B+ running Ubuntu Server 20.04 (Ubuntu is recommended for ROS2 installation)
- Pushbutton
pigpio
uses Broadcom numbers for addressing the Raspberry Pi's GPIO outputs. The GPIO arrangement diagram for each Raspberry Pi distribution is available here.
The following GPIO constants can be changed in their corresponding header files.
- LED Strip:
- Red: GPIO 2
- Green: GPIO 3
- Blue: GPIO 4
- Pushbutton: GPIO 17
- Make sure ROS2 Galactic and pigpio are installed onto your Raspberry Pi.
pigpio-master
should be in yourhome/user
directory (~/
), as the CMakeLists.txt configuration searches for it there. - Clone this repository and after sourcing your ROS2 installation (
source /opt/ros/galactic/setup.bash
), runcolcon build
in theROS2CPP/led_strip_controller
repository folder. - Open a new terminal.
- Enter your root shell using
sudo -i
. This is required forpigpio
GPIO setting. - Navigate to the repository directory in the new shell.
- In a new terminal, install the newly built package using
. install/setup.bash
from within theROS2CPP/led_strip_controller
repository folder. - Before running the program, kill all currently running
pigpio
processes:killall pigpiod
- Run the program with
ros2 launch led_strip_controller led_launch.py
.
- In both
startup_script.sh
, andcontroller_startup.service
, change the references to this repository's files to match where you downloaded this repository. - Give the system permissions to run
startup_script.sh
:sudo chmod 775 [your_path]/ros2-pi-leds/startup_script.sh
- Copy
controller_startup.service
to/etc/systemd/system/
(e.g:sudo cp controller_startup.service /etc/systemd/system/
). - Enable the service from the terminal with
sudo systemctl enable controller_startup.service
. To start the service at the same time, runsudo systemctl --now enable controller_startup.service