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

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

    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:
        os.system('mpg123 -q yarimmp3.mp3 &')
        GPIO.output(ledpin, GPIO.LOW)
        toprint = 0

     if (var1 > 15000) & (toprint==0):
        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

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.

| improve this answer | |

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.