A Raspberry Pi 5 VT100 Cyberdeck build - Part 4 - Startup script
With all systems now working and the Cyberdeck assembled but not yet sealed up, it was time to organize a startup script.
The process for Debian trixie has changed and editing ~/.config/lxsession/LXDE-pi/autostart no longer works properly for me. The right way to do it now is to use systemd which turns out to also be a lot easier.
For now, I just want to play a nostalgic sound on startup. Later on, this script will be used to start my desktop widget app I wrote a while ago called viridian.
Find the USB audio device
Pipewire is the default audio system on Raspberry Pi Desktop now, so ignore all chatGPT suggestions to start fiddling with ALSA.
We need to set the volume for our USB speaker on boot as step one in playing sound, so use wpctl to list the audio devices on your system:
wpctl status
The USB speaker identifies itself as UACDemoV1 and its ID number changes often.
PipeWire 'pipewire-0' [1.4.2, geoff@vt100, cookie:499785674]
└─ Clients:
33. WirePlumber [1.4.2, geoff@vt100, pid:1117]
34. pipewire [1.4.2, geoff@vt100, pid:1118]
47. WirePlumber [export] [1.4.2, geoff@vt100, pid:1117]
74. xdg-desktop-portal [1.4.2, geoff@vt100, pid:1324]
75. xdg-desktop-portal-wlr [1.4.2, geoff@vt100, pid:1412]
76. unknown [1.4.2, geoff@vt100, pid:1276]
77. wpctl [1.4.2, geoff@vt100, pid:1872]
Audio
├─ Devices:
│ 48. UACDemoV1.0 [alsa]
│ 49. Built-in Audio [alsa]
│ 50. Built-in Audio [alsa]
│
├─ Sinks:
│ * 70. UACDemoV1.0 Analog Stereo [vol: 1.00]
Startup script
~/bin/startup.sh
#!/bin/bash
echo "it works" > $HOME/login.txt
sleep 5
# get the ID of the USB speaker since it changes often
SINK_ID=$(wpctl status | awk '/UACDemoV1.0 Analog Stereo/ {gsub("\.", "", $3) ; print $3}')
# set default
wpctl set-default "$SINK_ID"
echo "play $SINK_ID"
wpctl set-volume @DEFAULT_AUDIO_SINK@ 1.0
pw-play --volume 0.6 "$HOME/sounds/startup.wav" >/dev/null 2>&1
With volume on the USB speaker set to 100%, I found the device itself clips sounds with a few seconds of silence if specific sounds are too loud, so it sounded like the start of the file was being skipped and then other parts just refuse to play. The giveaway this is happening is a small “pop” sound from the speaker followed by a few seconds of silence.
It seems 60% is the highest useable volume level for this speaker but this is still quite loud.
Test the script works by just running it, and prove the script ran by checking the log file got created (we will tidy this up later):
# once
# chmod +x ~/bin/startup.sh
~/bin/startup.sh
Systemd user service
Create a directory for user units:
mkdir ~/.config/systemd/user -p
Create a service file (adjust as needed):
~/.config/systemd/user/startup.service
[Unit]
Description=Startup script
[Service]
ExecStart=/home/geoff/bin/startup.sh
[Install]
WantedBy=default.target
Enable and start the service
systemctl --user enable startup.service
systemctl --user start startup.service
To test, reboot.
The finished result
A “sleeper build”: spends most of the day as a cool desktop widget but also has plenty of room to run Kubernetes or random VMs.
Next
Thankfully all that’s left to do is is connect up the back USBs and close the case. Hopefully this doesn’t merit another blog post although at this point all bets are off.
After this, I never plan to open this “cursed” device again, and to be honest, I’m amazed its still even working. Perhaps with my employer Confluent now being an IBM company, I should be upgrading to a IBM 3270 for my desktop amusement.