Audio only signal to Raspberry Pi Zero

Want to write your own code to work with a HDHomeRun or work with the HDHomeRun DVR? We are happy to help with concepts, APIs, best practices.
se99paj
Posts: 16
Joined: Thu Jul 02, 2015 5:08 am

Audio only signal to Raspberry Pi Zero

Postby se99paj » Wed Jul 05, 2017 8:32 am

I've been working on creating a new alarm clock based on a Raspberry Pi Zero, I'd like to hear FM Radio over the speakers in the morning and I've been looking at options.

I have streamed FM radio from various places on the internet but there seemed to be a delay in the signal - as I have a HDHomeRun and as Freeview in the UK broadcast FM radio stations I would be interested to know if I could look at using a HDHomeRun as an alternative.

Ideally using a Python script as that is the code I've been using at the moment.

mack0331
Posts: 19
Joined: Sat Sep 17, 2016 1:42 pm

Re: Audio only signal to Raspberry Pi Zero

Postby mack0331 » Wed Jul 05, 2017 9:44 am

I've been working on creating a new alarm clock based on a Raspberry Pi Zero, I'd like to hear FM Radio over the speakers in the morning and I've been looking at options.

I have streamed FM radio from various places on the internet but there seemed to be a delay in the signal - as I have a HDHomeRun and as Freeview in the UK broadcast FM radio stations I would be interested to know if I could look at using a HDHomeRun as an alternative.

Ideally using a Python script as that is the code I've been using at the moment.
Without knowing all the details of how you want your alarm clock to work (i.e. Does it go off every day at the same time? Do you have a GUI that you use to change your alarm settings, etc.) I would recommend you do the following to get started:

1. Install VLC on your Pi Zero. (sudo apt-get install vlc)

2. Use hdhomerun command line to set the tuner channel and program to match the UK FM radio station.
eg: hdhomerun_config FFFFFFFF set /tuner0/channel 9
eg: hdhomerun_config FFFFFFFF set /tuner0/program 15
You can see full instructions for identifying your channel/program and streaming to VLC at: https://www.silicondust.com/hdhomerun/h ... opment.pdf

3. Send your hdhomerun tuner signal to a specific UDP port.
format: hdhomerun_config <id> set /tuner<n>/target udp://<ip>:<port>
eg: hdhomerun_config FFFFFFFF set /tuner0/target udp://192.168.1.100:5000

4. Set up your "alarm_clock.py" script with your date/time preferences for alarm clock settings. Using the above example with port 5000, I imagine the python script would include the following (along with your preferences) to play the stream through VLC

import os
os.system("vlc udp://192.168.1.100:5000")

**Note: This will technically play the video as well, which won't matter since it sounds like you're running a headless system. If you only care about the audio, I think you could use the "os.system("vlc--no-video udp://192.168.1.100:5000") to have only the audio streamed.

5. Set the script up to run at boot so you don't have to rerun your python script every time you reboot your Pi:

sudo crontab -e
#scroll to the bottom of the file and call your python script like this
@reboot python /home/pi/alarm_clock.py &

6. Test the system with a sudo reboot!

Happy coding! Let us know how it turns out!

mack0331
Posts: 19
Joined: Sat Sep 17, 2016 1:42 pm

Re: Audio only signal to Raspberry Pi Zero

Postby mack0331 » Wed Jul 05, 2017 9:47 am

Oh, if you're using a button or something else to stop the audio stream (i.e. Turn off the alarm clock radio) I'd recommend you close the stream entirely on the hdhomerun side rather than the VLC side. If you close VLC, you will still be sending the entire hdhomerun stream to the specified port (which uses up one of your tuners).

To stop the tuner set the channel to none:
format: hdhomerun_config <id> set /tuner<n>/channel none
eg: hdhomerun_config FFFFFFFF set /tuner0/channel none


Return to “Development Support”

Who is online

Users browsing this forum: No registered users and 1 guest