I was going put my thoughts to lightshowpi community but will put them here. I really like the idea of using the pirate radio instead of an external fm transmitter for the lightshowpi display.
From what I understand of the pirate radio it uses GPIO 7 (pin 4) of the Model B rev 2.0. Your lightshowpi program also uses the same GPIO 7 as well. Could we just change using another GPIO for the lightshowpi program. That would fix one issue. For the model B+, not a real big deal, as you would have 17 GPIO's to use.
The second issue is getting both lightshowpi and pirate radio to play in sync.
Yohan, have you had any luck with this. I have gotten the pirate radio to play at the same time as the light show but the audo comes out as if it is playing at 2x speed. If i run just the pirateradio.py file included with the pirateradio it works fine, but combining it with the light show code makes it play fast for me.
i finally got this working! I had some time to sit down and really look at it and it is far simpler than we all thought. I have uploaded my code to my fork. Its the FMSynchronized_lights.py in the py folder. The reason it was playing at double speed is because i forgot the os.fork part of the code.
All that is needed is to do an os.fork and
fm_process = subprocess.Popen(["./pifm","-",str(frequency),"44100", "stereo" if play_stereo else "mono"], stdin=music_pipe_r, stdout=dev_null)
This lets you pipe anything you write to the music_pipe_w out of the pin 4 and over fm. so intsead of output.write(data) just do
This is pretty awesome, when I finally got it to work I was pretty impressed.
I did find a few issues however (minor)
Starting the show from outside of the program directory will cause an error because it can not locate pifm.
use our HOME_DIR var to specify pifm location.
Line 338 in synchronized_lights.py fm_process = subprocess.Popen(["../bin/pifm","-",str
to this: Line 338 in synchronized_lights.py fm_process = subprocess.Popen(["sudo",cm.HOME_DIR + "../bin/pifm","-",str
after installing the program from scratch, I found that bin/pifm does not have execute privs.
change directory to bin and execute: sudo chmod +x pifm
ISSUE 3: (feedback needed)
It appears that if a user decides to run the stop_music_and_lights script, the process for pifm never gets killed. Another issue with this is that the pifm process never dies, so for each song a process is generated and left running for each and every song. Im not sure what type of impact this will have over time, but I think it would be a good idea to clean up after we are done transmitting a song. Any ideas on a good place to add that in? We can add a killall command to the stop_music_and_lights script but that won't take care of the processes being left out there. Here is the output of running "ps -ef" after playing a few songs....
Chris, I didn't notice that it was not stopping the process when the parent process stopped. When i run my setup it just starts with my web service and continues to use that one instance for everything. So my bad on that one. I think the kill all command is a good idea, but i would make sure that you only kill the pifm processes that have a parent proc id of 1. You dont want to kill any that are actively being used.
I made a minor modification to the code to cleanup the process after the song is done playing. We may need to modify this once we merge more of your changes in Stephen. We'll see... from what I hear from Chris though this works great! Looking forward to testing it myself!
Trying to save myself from buying a Raspberry Pi B+ and use the model B to run the lightshowpi with FM enable. But because both programs use GPIO 7 it is impossible to do. Is there way that this can be done just using the model B 26-pin?
Thanks for responding back. But what should use for the last GPIO of lightshowpi as GPIO 7 is where the antenna will be on. Below is my current config, I did not show the pifm being enabled, pretty self-explained.
Using 8 pins of GPIO on the pi:
gpio_pins = 0,1,2,3,4,5,6,(7) --> what should this be changed to
Using 8 pins of GPIO with FM transmitting on the pi b+:
pin 7 cannot be used in FM mode because that is used for the antenna