1. Todd Giles
  2. lightshowPi
  3. Issues
Issue #40 resolved

Add FM transmission support

Todd Giles
repo owner created an issue

Comments (30)

  1. yohan_bohan


    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.

  2. yohan_bohan


    The pirate radio broadcast FM over Raspberry PI pin 4 (GPIO 7) in which lightshowpi uses GPIO 7.

    The pirate radio is configurable to broadcast over any frequency, but should use one in spectrum not being used by your local stations.

    Basically looking at how to get both lightshowpi and pirate radio (RadioPi) to both play at the same time. Basically taking out the need of a separate FM transmitter to broadcast the show music.

  3. Stephen Burning

    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.

  4. yohan_bohan

    What I suspect is happening is that both lightshowpi and radio pi are trying to play same mp3 file at the same time causing a lag in memory. Just a theory and i am just a noob programer.

  5. Stephen Burning

    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 os.write(music_pipe_w, data).

  6. Stephen Burning

    i haven't made an antenna yet, but sitting2 or 3 feet from it, i can pick up the signal. I havent tried further than that. I am going to take a 40cm 12 gauge solid core wire and try that.

  7. yohan_bohan


    Found issue with trying to use master branch with pifm added. I was getting errors until I change this:

    Line 338 in synchronized_lights.py fm_process = subprocess.Popen(["../bin/pifm","-",str

    to this: fm_process = subprocess.Popen(["sudo", "../bin/pifm","-",str

    Once I made the change, I had no further issues and ran as expected.

  8. chris usey

    This is pretty awesome, when I finally got it to work I was pretty impressed.

    I did find a few issues however (minor)

    ISSUE 1:

    • Starting the show from outside of the program directory will cause an error because it can not locate pifm.

    SOLUTION: use our HOME_DIR var to specify pifm location.

    CHANGE: 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

    ISSUE 2:

    after installing the program from scratch, I found that bin/pifm does not have execute privs.

    SOLUTION: 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....

    pi        2661     1  0 14:20 pts/0    00:00:00 /bin/bash /home/pi/lightshowpi/lightshowpi-frodeauxfork/bin/play_sms
    pi        2662     1  0 14:20 pts/0    00:00:00 /bin/bash /home/pi/lightshowpi/lightshowpi-frodeauxfork/bin/check_sms
    root      2681     1  0 14:20 pts/0    00:00:00 sudo /home/pi/lightshowpi/lightshowpi-frodeauxfork/bin/pifm - 100.1 44100 stereo
    root      2682  2681  9 14:20 pts/0    00:00:52 /home/pi/lightshowpi/lightshowpi-frodeauxfork/bin/pifm - 100.1 44100 stereo
    root      2759     1  0 14:24 pts/0    00:00:00 sudo /home/pi/lightshowpi/lightshowpi-frodeauxfork/bin/pifm - 100.1 44100 stereo
    root      2760  2759  6 14:24 pts/0    00:00:21 /home/pi/lightshowpi/lightshowpi-frodeauxfork/bin/pifm - 100.1 44100 stereo
    root      2790     1  0 14:26 pts/0    00:00:00 sudo /home/pi/lightshowpi/lightshowpi-frodeauxfork/bin/pifm - 100.1 44100 stereo
    root      2791  2790 20 14:26 pts/0    00:00:46 /home/pi/lightshowpi/lightshowpi-frodeauxfork/bin/pifm - 100.1 44100 stereo
    root      2852  2661  0 14:29 pts/0    00:00:00 sudo python /home/pi/lightshowpi/lightshowpi-frodeauxfork/py/synchronized_lights.py
    root      2853  2852 56 14:29 pts/0    00:00:10 python /home/pi/lightshowpi/lightshowpi-frodeauxfork/py/synchronized_lights.py
    root      2861  2853  1 14:29 pts/0    00:00:00 lame --quiet --decode /home/pi/lspmusic/favorites/dont_you_worry_child.mp3 -
    root      2862  2853  0 14:29 pts/0    00:00:00 sudo /home/pi/lightshowpi/lightshowpi-frodeauxfork/bin/pifm - 100.1 44100 stereo
    root      2863  2862  1 14:29 pts/0    00:00:00 /home/pi/lightshowpi/lightshowpi-frodeauxfork/bin/pifm - 100.1 44100 stereo
    root      2864  2662  5 14:30 pts/0    00:00:00 sudo python /home/pi/lightshowpi/lightshowpi-frodeauxfork/py/check_sms.py
    root      2865  2864 69 14:30 pts/0    00:00:00 python /home/pi/lightshowpi/lightshowpi-frodeauxfork/py/check_sms.py


  9. chris usey

    We can always place the killall command before the calling synchronized_lights.py in the play and play_sms scripts. That way all pifm processes will be killed every time.


  10. Stephen Burning

    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.

  11. Todd Giles reporter

    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!

  12. yohan_bohan

    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?

  13. Todd Giles reporter

    Yes, it works just fine on the B, simply change the gpio pins to not use GPIO 7 in your config file and enable pifm in the config and you should be good to go!

  14. yohan_bohan

    Todd, 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

    gpio_pins = 0,1,2,3,4,5,6,21

    Sorry for being confused by this

  15. Todd Giles reporter

    I see what you are saying now. There are many options when using the B board, you could simply not use GPIO 7 and have 7 output channels:

    gpio_pins = 0,1,2,3,4,5,6

    You could also use GPIO 8,9,10,11 if you have Rev 2 of the model B which are a secondary set of GPIO:


    So for example, using GPIO 0-6 and GPIO 8 on the Rev 2 model B:

    gpio_pins = 0,1,2,3,4,5,6,17

    Make sense?

  16. yohan_bohan

    Very much doable, but that means soldering pins to the P5 header. My soldering skills not the best. Last time I picked up a soldering iron was way back in the late 90's in school.

  17. yohan_bohan


    Per last comment, I just decided to break down and buy a Pi B+ and make use of the model B for something else. Maybe raspbmc for upstairs bedroom to watch movies from file server downstairs.

    So, with B+ in hand, all is golden, now to build box quick and start planning how to display the lights.

  18. Log in to comment