0

I've only recently begun working with Raspberry Pi, and decided to start with what seemed like a relatively simple project in the Pirate Radio (found here), but I have been unable to make it work properly. I am able to run PiFM from the terminal with ease, by typing in the following:

sudo /usr/bin/mpg123 -4 -s -Z /home/pi/Music/* | sudo /home/pi/pifm/pifm - 106.1

However, when I try to make PiFM run at system startup, it always gives me a black screen while playing the first second of a song on repeat infinitely. Originally I created the bash script as described in the Pirate Radio tutorial linked above, by making the following script, /etc/init.d/pirateRadio.sh

#!/bin/bash 
# /etc/init.d/pirateRadio.sh 
### BEGIN INIT INFO
# Provides:              pirateRadio.sh
# Required-Start:        $remote_fs $syslog
# Required-Stop:         $remote_fs $syslog
# Default-Start:         2 3 4 5
# Default-Stop:          0 1 6
# Short-Description:     Runs radio
# Description:           Runs my radio.
### END INIT INFO

case "$1" in 
    start) 
        echo "StARRRRRRRting Pirate Radio" 
        sudo /usr/bin/mpg123 -4 -s -Z /home/pi/Music/* | sudo /home/pi/pifm/pifm - 106.1 
        ;; 
    stop) 
        echo "Stopping Pirate Radio" 
        killall pifm 
        ;; 
    *) 
        echo "Usage: /etc/init.d/pirateRadio.sh start|stop" 
        exit 1 
        ;; 
esac 
exit 0

So, this did not work, as I described above. Upon looking it up to see if there were any solutions online, I found this, so I tried the solution found in there. However, this did not work. For reference, I put the following into my /etc/rc.local

#!/bin/bash

# rc.local

export PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/sbin:/usr/bin

(
    exec &>> /var/log/my_rc_local.log
    mpg123 -4 -s -Z /home/pi/Music/* | /home/pi/pifm/pifm - 106.1
) &

exit 0

Again, upon booting up my Pi, it would give me a black screen and the first second of a song on repeat. So, I am stuck, and do not know what to do to fix my little FM transmitter. I would appreciate any and all help I may receive, thank you.

4
  • 1
    pifm is possibly illegal in many jurisdictions.
    – joan
    Commented Feb 13, 2017 at 9:13
  • @joan I am aware of my regional regulations, and as such, this is not meant to be a permanent thing, just a very temporary project to learn more about Raspberry Pi. Thus, I am looking to get it working fully before I move on to another project.
    – Mason.
    Commented Feb 13, 2017 at 22:54
  • I'm not sure if it was ever properly working on the Pi2 or Pi3. If you are using one of those try an earlier (single core) Pi.
    – joan
    Commented Feb 13, 2017 at 22:58
  • @joan I am using the Pi Zero, so I believe it has a single core 1Ghz CPU.
    – Mason.
    Commented Feb 13, 2017 at 23:02

1 Answer 1

-1

I got the answer from Jaromanda X on my question auto start using /etc/rc.local or /etc/init.d not working you need to add sleep 10 and fix spacing

#!/bin/bash
export PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/sbin:/usr/bin
sleep 10
(
  exec &>> /var/log/my_rc_local.log
  cd /home/pi/pifm && ./pifm sound.wav 90.5 
) &

exit 0

that worked for me

I used http://www.icrobotics.co.uk/wiki/index.php/Turning_the_Raspberry_Pi_Into_an_FM_Transmitter and instructions from https://adestefawp.wordpress.com/raspberry-pi/pifm-radio/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.