Hey Folks,
I'm not sure if this has been done for the PI5 (Apologises if it has), I thought I would share how I did it, if anyone finds it useful:
1. Ensure SSH is enabled in the device and log in using "root"and your SSH password.
2. Check python 3 is installed:
"python3 --version"
You should have the up-to-date version, something like Python 3.11.2 or better. (If you don't have it, you'll need to install it)
3. Ensure you're in the storage folder using: "cd /storage"
4. Create a new file using "nano led_control.py" (I've called mine led_control, but you can call it anything you like)
5. In the nano editor, paste the following:
import RPi.GPIO as GPIO
import time
# Set up GPIO mode GPIO.setmode(GPIO.BCM)
# Set up GPIO pin for LED GPIO_PIN = 18 # Replace with your desired GPIO pin number GPIO.setup(GPIO_PIN, GPIO.OUT)
try: # Turn LED on GPIO.output(GPIO_PIN, GPIO.HIGH) while True: time.sleep(1) # Keep the script running
except KeyboardInterrupt: # Turn LED off and clean up GPIO on script exit GPIO.output(GPIO_PIN, GPIO.LOW) GPIO.cleanup()
You can change the GPIO pin to whichever you like, or add more pins as you wish.
6. Press Ctrl + X | y | enter (this will save and exit the editor).
7. Make the script executable: "chmod +x /storage/led_control.py"
8. Now we need to tell the system to start the script when the system starts up. Use
"cd /storage/.config/system.d" and enter the nano editor using "nano led_control.service"
9. Paste the following into the file:
[Unit]
Description=LED Control Service
After=network-online.service
Wants=network-online.service
[Service]
ExecStart=/storage/led_control.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
10. Press Ctrl + X | y | enter (this will save and exit the editor).
11. Enable the service using:
"systemctl enable /storage/.config/system.d/led_control.service"
12. Reboot the system using "reboot"
This will allow the selected pin(s) to lift to 3.3 volts when the system is running and off when the system shuts down. Just remember the GPIO pins can put out around 50mA on the PI5.
Hope you folks find this useful