First one is: how can I make the choice by default of the soundcard to “Headphones bcm2835_headphones” permanent? It seems to start with vc4HDMI. I changed it via “patchbox” in the jack service settings but i had to change at each reboot…
Second one: I got a python script that I want to start automatically at the reboot of the pi.
I added the following line in crontab, via crontab -e:
This is is stored in /etc/jackdrc. Check whether the file contents are correct.
Also check the logs of Jack to see what it is trying to do:
journalctl -u jack
For starting a script automatically, try setting it up as a Patchbox module:
Otherwise, try setting it up as a systemd service, it gives better control like dependency management, so it only attempts to start up once Jack backend is running.
#!/bin/sh
# exec is used to 'morph' the shell interpreter process into jackd process, saving some system resources.
exec /usr/bin/jackd -t 2000 -R -P 95 -d alsa -d hw:Headphones -r 44100 -p 512 -n 3 -X seq -s -S
It seems to be ok.
Now, the last logs from
journalctl -u jack
-- Boot 456e7fd399274f0ea524f9d047db8718 --
May 17 08:49:24 patchbox systemd[1]: Started jack.service - JACK Server.
May 17 08:49:26 patchbox jackdrc[599]: Failed to create secure directory (/nonexistent/.config/pulse): No such file or directory
May 17 08:49:26 patchbox jackdrc[599]: jackdmp 1.9.21
May 17 08:49:26 patchbox jackdrc[599]: Copyright 2001-2005 Paul Davis and others.
May 17 08:49:26 patchbox jackdrc[599]: Copyright 2004-2016 Grame.
May 17 08:49:26 patchbox jackdrc[599]: Copyright 2016-2022 Filipe Coelho.
May 17 08:49:26 patchbox jackdrc[599]: jackdmp comes with ABSOLUTELY NO WARRANTY
May 17 08:49:26 patchbox jackdrc[599]: This is free software, and you are welcome to redistribute it
May 17 08:49:26 patchbox jackdrc[599]: under certain conditions; see the file COPYING for details
May 17 08:49:26 patchbox jackdrc[599]: JACK server starting in realtime mode with priority 95
May 17 08:49:26 patchbox jackdrc[599]: self-connect-mode is "Don't restrict self connect requests"
May 17 08:49:27 patchbox jackdrc[599]: creating alsa driver ... hw:Headphones|hw:Headphones|512|3|44100|0|0|nomon|swmeter|soft-mode|16bit
May 17 08:49:27 patchbox jackdrc[599]: ALSA: Cannot open PCM device alsa_pcm for capture. Falling back to playback-only mode
May 17 08:49:27 patchbox jackdrc[599]: configuring for 44100Hz, period = 512 frames (11.6 ms), buffer = 3 periods
May 17 08:49:27 patchbox jackdrc[599]: ALSA: final selected sample format for playback: 16bit little-endian
May 17 08:49:27 patchbox jackdrc[599]: ALSA: use 3 periods for playback
May 17 08:49:27 patchbox jackdrc[599]: port created: Midi-Through:midi/playback_1
May 17 08:49:27 patchbox jackdrc[599]: port created: Midi-Through:midi/capture_1
May 17 08:49:38 patchbox jackdrc[599]: port created: RtMidiIn-Client:midi/capture_1
May 17 08:49:38 patchbox jackdrc[599]: port created: RtMidiOut-Client:midi/playback_1
lines 647-681/681 (END)
@Giedrius in fact it’s very strange.
Here’s what I do:
everything is via SSH
Start the Pi
Start the python script → the script starts but when I press a button, nothing happens and it should start the reading of a sound file
Quit the script (Ctrl + C)
Restart jack via Patchbox command
Restart my pyhton script and now it’s ok
So, one of my hypothesis is : as I use pyGame.mixer in my script, could it be possible that the settings I gave in the script are in conflict with the jack settings?
What happens if you restart your script without restarting Jack? Does the Jack restart actually succeed? Make sure your script is set up to use Jack, as other options might not be able to share the audio resources. Or if you don’t need Jack at all, you could disable it and use ALSA from your script directly, especially if you don’t need other programs to use the audio at the same time.
The script doesn’t start at the boot, I start it manually (cli). Nothing more happens when I start the script twice wthout restarting Jack.
I’m not sure my script is set up to use Jack. And here it seems to be the problem.
That’s my case! I don’t need others programs to use the audio at the same time. Could I disable jack at the start of PatchboxOs ? And if it is possible, how can I do that?
Thankx for your time and your answers!
NB: I stopped jack with jack_control stop , started my script but nothing happened. I stopped the script.
I restarted jack via patchbox.
I restarted the script and then everything was fine.
@Giedrius
So I tried to create a systemd service for my script. Here is the result of systemctl status waxmonde.service
waxmonde@patchbox:~ $ systemctl status waxmonde.service
× waxmonde.service - Lecteur de samples Waxmonde v1.0
Loaded: loaded (/etc/systemd/system/waxmonde.service; enabled; preset: enabled)
Active: failed (Result: exit-code) since Sun 2025-05-25 22:32:55 CEST; 44s ago
Duration: 18.772s
Process: 605 ExecStart=/usr/bin/python3 /home/waxmonde/samples/gpio_music_box08.py (code=exited, status=1/FAILURE)
Main PID: 605 (code=exited, status=1/FAILURE)
CPU: 2.005s
May 25 22:32:54 patchbox python3[605]: pygame 2.1.2 (SDL 2.26.5, Python 3.11.2)
May 25 22:32:54 patchbox python3[605]: Hello from the pygame community. https://www.pygame.org/contribute.html
May 25 22:32:54 patchbox python3[605]: Traceback (most recent call last):
May 25 22:32:54 patchbox python3[605]: File "/home/waxmonde/samples/gpio_music_box08.py", line 9, in <module>
May 25 22:32:54 patchbox python3[605]: mixer.init() #créé une instance de la classe "mixer" de la b>
May 25 22:32:54 patchbox python3[605]: ^^^^^^^^^^^^
May 25 22:32:54 patchbox python3[605]: pygame.error: ALSA: Couldn't open audio device: Unknown error 524
May 25 22:32:55 patchbox systemd[1]: waxmonde.service: Main process exited, code=exited, status=1/FAILURE
May 25 22:32:55 patchbox systemd[1]: waxmonde.service: Failed with result 'exit-code'.
May 25 22:32:55 patchbox systemd[1]: waxmonde.service: Consumed 2.005s CPU time.
It seems that my script start but Alsa can’t open the audio device (in my case: the headphones)…
So…what can I do???
Here is my waxmonde.service file:
GNU nano 7.2 /etc/systemd/system/waxmonde.service
[Unit]
Description=Lecteur de samples Waxmonde v1.0
After=alsa-restore.service
[Service]
ExecStart=/usr/bin/python3 /home/waxmonde/samples/gpio_music_box08.py
WorkingDirectory=/home/waxmonde/samples
User=waxmonde
[Install]
WantedBy=multi-user.target
It sounds like the default config is not found, it might be visible from your user (like if it’s in ~/.alsarc), but unavailable in system-wide location.
Alternatively, you could make your systemd unit run as your user, by specifying user, group values (set both to waxmonde) and set HOME environment variable to /home/waxmonde
Could you share your final .service file contents? I’m sure it might be useful as a reference to someone else trying to get their audio scripts to start automatically.