Rpi 4B 8Gb, Pitop4 DIY, Pitop OS
Hi there
I Wrote a simple program to play a sound file when motion is detected using a PIR sensor.
Its running fine when run on Mu and online through Further (load your own code).
But once I load the program to the Project.cfg dir, there is no audio.
I want to be able to run the project by selecting it from the Projects list.
I tried internal speaker, headphones, external speaker on the AV Jack, Bluetooth speaker. All of them is playing the sound when run on Mu and online on Further, but no audio when loading the program to the pitop and selecting the program from the projects list on either of them.
Code below:
When motion is detected, play sound file
from gpiozero import MotionSensor
from time import sleep
from pitop import Pitop
import pygame
path = “/home/pi/sounds/robot_sounds_named/”
sound_files =[“gobble.mp3”]
pygame.mixer.init()
speaker_volume = 1
pygame.mixer.music.set_volume(speaker_volume)
for sound_file in sound_files:
pygame.mixer.music.load(path + sound_file)
Define PIR
pir = MotionSensor (4)
initialise the Mini Screen, set the frames-per-second rate and font size
mini_screen = Pitop().miniscreen
while True:
pir.wait_for_motion()
print(“motion detected”)
mini_screen.display_multiline_text(“Motion Detected”, font_size = 20)
pygame.mixer.music.play()
pir.wait_for_no_motion()
print(“Motion Stopped!!”)
mini_screen.display_multiline_text(“No Motion”, font_size = 20)
Any help would be appreciated