I saw many guides online to run a script at startup but all I found so far runs after logged in to the pi. In my case, I would like to run a script right after the splash screen. I saw some guides online on how to customise the splash screen but it's not exactly what I need. I'm not sure how to adapt my code and I'm afraid that if there's error in the code, my pi won't boot. Here's the script that I want to run. It plays sound through an active buzzer:

import sys
import RPi.GPIO as GPIO
import time
# Set trigger PIN according with your cabling
signalPIN = 26

# Set PIN to output
class soundGen:
    def soundFunc(self,function):
        default = "Not found"
        return getattr(self, 'case_' + str(function), lambda: default)()
    def case_1(self):#Startup boot      
        return [1,0,1,0],[0.2,0.1,0.5,0]
    def soundPLayer(self, select):
        pin, gap = self.soundFunc(select)
        for n in pin:
ss = soundGen()
function = 4
# cleanup will free PINS and exit will terminate code execution

  • 1
    I would like to run a script at the rainbow splash screen - impossible - I don't think the CPU is even initialised yet at that stage, let alone enough of the operating system to run python Mar 17 '21 at 0:17
  • @JaromandaX This one here shows how to customise the splash screen: link. I figured it would be possible to just adapt the code above?
    – zaraku27
    Mar 17 '21 at 0:28
  • you said "rainbow splash screen" - I assumed you meant the "rainbow" that appears when you first turn on the pi, not some splash screen that is added some time later by playing a video using omxplayer - just add audio to the video you play Mar 17 '21 at 0:35
  • @JaromandaX I was under the impression that they replaced that rainbow splash screen. So I thought i would be possible to play sound instead at that point in time. I'll modify my question.
    – zaraku27
    Mar 17 '21 at 0:46

Realistically, the earliest moment for the boot sound is right after the SystemD sound target:

Description=Boot Sound

ExecStart=/usr/bin/aplay /boot/sound.wav


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.