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