0

I have a python code that runs an mp3 file. It works perfectly when I run it through python 3.5.3 shell on my pi-top, and I also managed to make the program run on startup, but then everything works except the audio file.

I have a feeling it relates to the fact that in the begining of the file I import some stuff (that I found on another manual).

here is my code:

import time
from time import sleep
import RPi.GPIO as GPIO
import os
DEBUG = 1
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

def RCtime (RCpin):
    reading = 0
    GPIO.setup(RCpin, GPIO.OUT)
    GPIO.output(RCpin, GPIO.LOW)
    time.sleep(0.1)

    GPIO.setup(RCpin, GPIO.IN)

    while (GPIO.input(RCpin) == GPIO.LOW):
        reading += 1
    return reading

toprint = 0
ledpin = 17
GPIO.setup(ledpin, GPIO.OUT)
GPIO.output(ledpin, GPIO.LOW)
blabla = 0

while True:
    var1 = RCtime(27)
    if (var1 < 4000) & toprint:
        print(var1)
        print("open")
        os.system('mpg123 -q yarimmp3.mp3 &')
        GPIO.output(ledpin, GPIO.LOW)
        toprint = 0

     if (var1 > 15000) & (toprint==0):
        print(var1)
        print("closed")
        GPIO.output(ledpin, GPIO.HIGH)
        toprint = 1

Thank you!

  • What operating system you are using? Raspbian? How do you run the program at startup? Please address me with @Ingo, otherwise I won't see your reply. – Ingo Dec 5 '18 at 9:36
0

Add the full path to mpg123 and the mp3 file.

os.system('/usr/bin/mpg123 -q /home/pi/yarimmp3.mp3 &')

Applications run as root user rather than pi user at startup.

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.