The Can't connect to pigpio error you are seeing on startup, even after adding sudo pigpiod to your autostart script, is a common timing issue. Your Python script is likely trying to connect to the pigpiod daemon before it has fully started.
While you have confirmed your autostart script is running, the order of operations within that script, especially concerning xrandr and pigpiod, might be the problem. The check for graphics using xrandr introduces a delay. Even after this delay, pigpiod might not be ready the instant it is called.
Since your Python script works perfectly when run manually after everything boots, it confirms the script itself is correct. The problem is specific to the startup environment within lxsession/LXDE-pi/autostart.
Consider these alternative approaches to ensure pigpiod is fully initialized before your Python script attempts to use it:
Introduce a delay in your Python script: Add a short time.sleep() at the beginning of your Python script (e.g., sleep(5)). This gives pigpiod more time to start up. While not ideal, it's a simple test to confirm this is a timing issue.
Systemd Service: Create a systemd service for your Python script. Systemd services offer more control over startup order and dependencies. You can configure the service to start after pigpiod is active. This is a more robust solution for managing processes on startup.
RC.local: While older, rc.local can still be used on some Raspberry Pi OS versions for simple startup commands. You could add sudo pigpiod and then your Python script command to /etc/rc.local. Remember to add exit 0 at the end of the rc.local file.
Modify your Bash script: Instead of just running sudo pigpiod, add a short sleep command directly after it in your autostart script. For example:
Replace /path/to/your/script.py with the actual path to your input script.
The autostart method in lxsession/LXDE-pi is suitable for many tasks. However, for services with dependencies like pigpiod, a more controlled startup method like a systemd service is often better. This ensures pigpiod is fully online before your script tries to connect to it.
While you have confirmed your autostart script is running, the order of operations within that script, especially concerning xrandr and pigpiod, might be the problem. The check for graphics using xrandr introduces a delay. Even after this delay, pigpiod might not be ready the instant it is called.
Since your Python script works perfectly when run manually after everything boots, it confirms the script itself is correct. The problem is specific to the startup environment within lxsession/LXDE-pi/autostart.
Consider these alternative approaches to ensure pigpiod is fully initialized before your Python script attempts to use it:
Introduce a delay in your Python script: Add a short time.sleep() at the beginning of your Python script (e.g., sleep(5)). This gives pigpiod more time to start up. While not ideal, it's a simple test to confirm this is a timing issue.
Systemd Service: Create a systemd service for your Python script. Systemd services offer more control over startup order and dependencies. You can configure the service to start after pigpiod is active. This is a more robust solution for managing processes on startup.
RC.local: While older, rc.local can still be used on some Raspberry Pi OS versions for simple startup commands. You could add sudo pigpiod and then your Python script command to /etc/rc.local. Remember to add exit 0 at the end of the rc.local file.
Modify your Bash script: Instead of just running sudo pigpiod, add a short sleep command directly after it in your autostart script. For example:
Code:
sudo pigpiodsleep 3 # Add a short delay herepython3 /path/to/your/script.py # Or whatever command runs your scriptThe autostart method in lxsession/LXDE-pi is suitable for many tasks. However, for services with dependencies like pigpiod, a more controlled startup method like a systemd service is often better. This ensures pigpiod is fully online before your script tries to connect to it.
Statistics: Posted by epgtechtalk — Fri Jul 25, 2025 6:24 am