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_outputnode defines a subscriber for"led_controller1/new_color", astd_msgs::msg::ColorRGBAobject. Upon receipt of a new color by any publisher, the node will set the LED strip to that color. - The
button_pubnode 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.cppfile 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-mastershould be in yourhome/userdirectory (~/), 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 buildin theROS2CPP/led_strip_controllerrepository folder. - Open a new terminal.
- Enter your root shell using
sudo -i. This is required forpigpioGPIO setting. - Navigate to the repository directory in the new shell.
- In a new terminal, install the newly built package using
. install/setup.bashfrom within theROS2CPP/led_strip_controllerrepository folder. - Before running the program, kill all currently running
pigpioprocesses: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.serviceto/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