1

Okay, so I am building a sweet vintage style boombox for my nana using a RCA Victor X551 case, a Rpi3, running runeaudio. I have most of everything figured out, but could use some help with the programming end. I have a python file which will play/pause the audio, but I don't have it actually working. I don't understand where to place the file, or what it needs to run as a "service"?

Here is my file:

    !/usr/bin/env python
    import RPi.GPIO as GPIO
    import time
    import subprocess
    GPIO.setmode(GPIO.BOARD)

    # Select unused GPIO header pin to be used to toggle play/pause
    InputPin = 13

    # Set selected pin to input, and enable internal pull-up
    GPIO.setup(InputPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

    # Wait for a button press on the selected pin (pulled to ground, falling edge)
    GPIO.wait_for_edge(InputPin, GPIO.FALLING)

    # When pressed, toggle play/pause
    mpc toggle

note: I stole this from someone who posted it on the runeaudio forums. I don't understand it. Is like 1 what I am looking for? subprocess?

I also have a rotary encoder which I would like to use as volume control. I am new to all this maker stuff, and any help sure would be appreciated. I do know the mpc commands I would like to use... but that's about it.

1 Answers1

1

If your code is working fine and you just need it to be run whenever after each boot process, you can create a systemd service:

  1. Create a file called something like "/etc/systemd/system/pyscriptstarter.service" which should contain the following:

    [Unit]
    Description=Fancy Bash script to start fancy Python script
    
    [Service]
    ExecStart=/usr/bin/bashscript.sh
    
    [Install]
    WantedBy=multi-user.target 
    
  2. Create the file "/usr/bin/bashscript.sh" which should contain:

    python /path_to_python_script/pyscript.py
    
  3. Make "/usr/bin/bashscript.sh" executable with:

    sudo chmod 755 /usr/bin/bashscript.sh
    
  4. Enable the service with:

    sudo systemctl enable pyscriptstarter.service
    

Of course, you have to edit the line to match your path and the script's filename. Good luck!

Domme
  • 375
  • 2
  • 11