Eyewool International

Some Things I Learned Banging My Head Against The Linux Wall While Making a Silly Little Jukebox

IMG_3205

A little less than a month ago I posted about how I was procrastinating by starting what felt like a simple project to create a Raspberry Pi based Jukebox thingy for my studio space to play my bespoke "Jukebox" Plex playlist. Just a little box with two buttons and two lights to just turn on a playlist I like and let it run while I'm working. How hard could it be?

Well, now, with the exception of waiting for the standoffs to arrive (Digi-Key shipping is forever delayed and I fear McMaster Carr), and figuring out how to fix the 3D print of my case that I somehow jacked up (why aren't the holes that I clearly put in the step file actually present in the print??), I'm pretty much done. The buttons work. The API calls work. The audio is routing to the right place on the Pi hardware. The code side in particular was much harder than I expected, but I got there. Here's some random things I learned. At the end of this playlist I'll plop a little tracklist of a sample shuffle through 15 songs just for some flavor.

Three Things I Learned:

1. The headphone jack output on a Raspberry Pi does in fact have a software volume control and it's not set at full volume by default

Years ago I used this Pi as an Airplay receiver connected to my stereo and I was fighting it CONSTANTLY because the volume was low and as a result the signal to noise into my stereo was bad. I assumed this was becuase I needed one of those DAC hats, which surely would've helped. But you know what else would've helped? This command:

amixer set BCM 100%

That shit right there just turns the headphone jack output up to line level which, sure it's not as good as the DAC hat output probably is, but it works just fine for my purposes.

2. If you put "amixer set BCM 100%" in your PreExec line of a systemd file, The Pi OS may randomly screw up the index of your audio outputs and break everything you thought you had fixed

So per the previous thing I learned, I thought I'd be smart and put the amixer command in my .service file. Unfortunately, that triggered the Pi OS to do something goofy and move the headphone jack and the HDMI audio output around and screw everything beautiful up. See, becuase I'd been fighting the headphone jack already, I had previously modified my "/etc/asound.conf" file to the following to hard code and force the output to the audio device at index 0 (thus "hw:0,0").

pcm.!default {
    type plug
    slave.pcm "hw:0,0"
}

ctl.!default {
    type hw
    card 0
}

However, once I put my amixer command in the .service file, the results of:

aplay -l

switched from:

card 0: Headphones [bcm2835 Headphones]
card 1: vc4hdmi [vc4-hdmi]

to

card 0: vc4hdmi [vc4-hdmi]
card 1: Headphones [bcm2835 Headphones]

This happened for reasons I cannot explain based on the forum posts I read!! However, the fix was just to tell the Pi "please, always put the headphone jack at position card 0" by creating /etc/modprobe.d/alsa-base.conf with the following:

options snd_bcm2835 index=0
options snd_vc4 index=1

Thank god for the internet. I would have never solved that. I would've straight up wiped my SD card and started over.

3. It's not so bad to run terminal commands from Python after all

I had it in my hand I was going to have to write bash scripts and have Python trigger their execution, but no, there's a module called subprocess you can import and just run any old terminal command with like so:

subprocess.run(["amixer", "-c", "0", "set", "PCM", "100%"])

Cool. Helpful. I'm learning.

You can, by the way, also use this to shut the Pi down from inside a python script as long as you give the user running the script passwordless sudo privileges. You just run the command:

sudo visudo

And plop:

{your user} ALL=(ALL) NOPASSWD: /sbin/shutdown

at the end. Is this secure and recommended? I do not know. Do not ask me. Whether or not it is safe is not on the list of things I learned this go around. Fortunately this thing is going to be turned off most of the time and I like to live dangerously.

Anyway, here's a little 15 song snippet of a shuffle path through the playlist from today:

15 Tracks of Jukebox:

  1. "Norman" - Max Romeo & the Upsetters - War Ina Babylon (1976)
  2. "Pale Blue Eyes" - Moe Tucker - Life in Exile After Abdication (1989)
  3. "Up the Down Escalator" - The Chameleons - Script of the Bridge (1983)
  4. "Daddy Kane" - Roc Marciano & the Alchemist - The Elephant Man's Bones (2022)
  5. "The Oncoming Day" - The Chills - Submarine Bells (1990)
  6. "When I Get to the Border" - Richard & Linda Thompson - I Want to See the Bright Lights Tonight (1974)
  7. "Drop in the Ocean" - Moonshake - Eva Luna (1992)
  8. "The Courts" - Jam City - Classical Curves (2012)
  9. "Vincent Van Gogh" - Jonathan Richman and the Modern Loves - Rockin' & Romance (1985)
  10. "Queen of the Silver Dollar" - Emmylou Harris - Pieces of the Sky (1975)
  11. "Range Life" - Pavement - Crooked Rain, Crooked Rain (1994)
  12. "Stay All Night (Stay a Little Longer)" - Willie Nelson - Shotgun Willie (1973)
  13. "Deep Well" - Boy Harsher - Yr Body is Nothing (2016)
  14. "Past Majesty" - Demdike Stare - Testpressings (2016)
  15. Shutout - The Walker Brothers - Nite Flights (1978)