DVB-T Fun with a Raspberry PI – Playing Radio with Linux (Part 1)

In this chapter : Playing Radio with a Raspberry PI and a DVB-T Dongle.

You have probably heard about the cheap little USB Dongles made to receive digital Television and / or radio. They come in many shapes and forms (and prices) but you can find some cheap ones around the net. You can score one for around 10 € easy on ebay.

The heart of the system is build on the RTL2832U Chipset or the RTL2838 (Many devices with EEPROM have 0x2838 as PID and RTL2838 as product name, but in fact all of them have an RTL2832U inside.
Realtek never released a chip marked as RTL2838 so far (source) ) and comes with a variety of tuners. The two most common (and wanted) tuners are :

E4000 – 53 Mhz – 2217 Mhz (with a gap in 1109 to 1251 Mhz)  These tuners are the most desirable to have, though the company providing this tuner (Elonics IP) seems to be sold. The future of this tuner is unsure.  My Terratec Tstick, for example, has this tuner.

E4000

R820T – Rafael Micro R820T  – According to rtlsdr.org this tuner is a worthy follow up with comparable performance and cheaper in production.

R820T

I have both variants. And I will connect them both to my freshly new Rasperry PI with Raspian and see what we are running up to 🙂

So basically what I will do is install RTL-SDR to communicate with the USB Stick and we will install multimon-ng to add some extra nifty features for decoding POCSAG e.t.c.

So the first step is to boot-up your Raspberry, connected to the network and SSH to your Raspberry (or use the local shell ofcourse, but I prefer to do it remotely)

If you add the USB Stick (the R820T + RTL2838) I’ve noticed the Raspberry rebooted.

 pi@srv-rasp-01 ~ $ lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0bda:2838 Realtek Semiconductor Corp. RTL2838 DVB-T

To see a bit more details and to find out the VID (Vendor ID) and PID (Product ID) you can use LSUSB -v and check if your hardware is compatible with RTL-SDR here : http://sdr.osmocom.org/trac/wiki/rtl-sdr

  idVendor           0x0bda Realtek Semiconductor Corp.
  idProduct          0x2838 RTL2838 DVB-T

It seems my DVB-T Stick is compatible. ( Generic RTL2832U (e.g. hama nano)) so lets move on to the installation of the RTL-SDR software.

Get your Raspberry up2date first.

sudo -i
apt-get update && apt-get upgrade

Now install the required utils and libraries to compile RTL-SDR

apt-get install git cmake libusb-1.0-0.dev build-essential

Download RTL-SDR and compile the software.

git clone git://git.osmocom.org/rtl-sdr.git
cd rtl-sdr/
mkdir build
cd build
cmake ../ -DINSTALL_UDEV_RULES=ON
make
make install
ldconfig

In order to be able to use the dongle as a non-root user, I used cmake with -DINSTALL_UDEV_RULES=ON argument in the above build steps. This is an optional thing. The software will install in /usr/local/bin/ and consists of a few utils : rtl_adsb, rtl_eeprom, rtl_fm, rtl_power, rtl_sdr, rtl_tcp, rtl_test

After the installation, reboot the raspberry and login with a normal user account.

Now, type rtl_test :

pi@srv-rasp-01 ~ $ rtl_test
Found 1 device(s):
  0:  Generic RTL2832U OEM

Using device 0: Generic RTL2832U OEM

Kernel driver is active, or device is claimed by second instance of librtlsdr.
In the first case, please either detach or blacklist the kernel module
(dvb_usb_rtl28xxu), or enable automatic detaching at compile time.

usb_claim_interface error -6
Failed to open rtlsdr device #0.

Ok, not good. let’s fix this little issue 🙂 . We have to blacklist the automatically loading of the kernel module. Edit /etc/modprobe.d/raspi-blacklist.conf and add the following lines. (Note : If this raspi-blacklist.conf doesn’t exist, just create it)

blacklist dvb_usb_rtl28xxu
blacklist rtl_2832
blacklist rtl_2830

Reboot the Raspberry again and retry the rtl_test

pi@srv-rasp-01 ~ $ rtl_test
Found 1 device(s):
  0:  Generic RTL2832U OEM

Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
Supported gain values (29): 0.0 0.9 1.4 2.7 3.7 7.7 8.7 12.5 14.4 15.7 16.6 19.7 20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6

Info: This tool will continuously read from the device, and report if
samples get lost. If you observe no further output, everything is fine.

Reading samples in async mode...
lost at least 64 bytes

This looks O.K. to me. I lost a few samples at the startup. But no new messages popped up.

Now, lets try to listen to some radio. I choose 100.7 FM as this is a fair strong signal. Lets hook up some speakers to the Raspberry and let’s go :

pi@srv-rasp-01 ~ $ rtl_fm -f 100.7M -M wbfm -s 200000 -r 48000 | aplay -r 48k -f S16_LE
Found 1 device(s):
0:  Realtek, RTL2838UHIDIR, SN: 00000001

Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
Oversampling input by: 2x.
Oversampling output by: 4x.
Buffer size: 5.12ms
Tuned to 101116000 Hz.
Sampling at 1600000 Hz.
Output at 48000 Hz.
Tuner gain set to automatic.
Playing raw data 'stdin' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono

And we have radio.!….let’s try if the Terratec dongle does any better 🙂 .. Let’s first run it through a rtl_test with the -t parameter designed to benchmark the E4000 tuner.

pi@srv-rasp-01 ~ $ rtl_test -t
Found 1 device(s):
0:  Terratec T Stick PLUS

Using device 0: Terratec T Stick PLUS
Found Elonics E4000 tuner
Supported gain values (14): -1.0 1.5 4.0 6.5 9.0 11.5 14.0 16.5 19.0 21.5 24.0 29.0 34.0 42.0
Benchmarking E4000 PLL...
[E4K] PLL not locked for 52000000 Hz!
[E4K] PLL not locked for 2214000000 Hz!
[E4K] PLL not locked for 1107000000 Hz!
[E4K] PLL not locked for 1249000000 Hz!
E4K range: 53 to 2213 MHz
E4K L-band gap: 1107 to 1249 MHz

Good.. this seems to work. Now lets try the radio again…. same quality..Not better or worse. Though it have to be mentioned that I had to use a good antenna (outside) to get a noise-free signal while a portable radio could do the same with a small internal antenna. (Don’t mind my long antenna-adapter-conversion as I used what-ever I could find to hook it up to the IEC connector of the Dongle)

As a result of this setup, I have made a little video :

 

Later on we will dig more into the other possibilities with the DVB Dongle and the Raspberry PI

This entry was posted in Linux, Rasperry PI, Technical and tagged , , , , , , , . Bookmark the permalink.

15 Responses to DVB-T Fun with a Raspberry PI – Playing Radio with Linux (Part 1)

  1. Pingback: DVB-T Fun with a Raspberry PI – Airtraffic (Part 2) | Yellownote

  2. Pingback: DVB-T Fun with a Raspberry PI – Weatherstations (Part 3) | Yellownote

  3. Massimo says:

    Hello, I tried to follow your great guide, no problems except one: while I am listening to radio i got underrun message each 5 or 6 seconds…I really don’t undestand why…..CPU load is about 18%…
    Did you notice the same problems?
    Thank you.
    Massimo.

    • Alexander says:

      Hi Massimo,
      I also get those underruns. However they come every second.
      I didn´t find a solution yet. On my PC everything works just fine.
      Did you find a solution to that problem?

  4. Massimo says:

    Hello, sorry for late reply.
    I still have underrun…but I mind to try two possible solutions:
    1) I connected my dongle directly to raspberry so a powered hub is absolutely necessary.
    2) I see raspberry can be overclocked….why not have a try?
    I am going to try these solutions on this week end (but time is a precious thing nowdays….so…better not make previsions…) then I will inform you with my results.
    Thank you and greetings from Italy.
    Massimo.

  5. Jason says:

    Hi,

    Thanks for the great tutorial! I too am experiencing t he buffer underrun issue. Apparently many others are too. There is a discussion with a proposed resolution on the osmocom mailing list. I’ve tried this, and it slows down the underrun reporting, but does not resolve it. It does seem like worth toying with though.

    Jason

  6. Andy says:

    Hi,

    I was playing with something similar the other night, and I noticed your comment on needing a large outdoor antenna to get a clear signal. I found this improved for me if I set the tuner gain using the “-g” option on rtl_fm. Values between 10 and 20 seemed to produce good results, although I noticed rtl_test has given you a list of supported values, so you could experiment.

    Cheers
    Andy.

    • Cris says:

      HI Andy,

      I think you are right. I did not set the gain option. Definitely worth a try as in theory you can use any piece of wire as a perfect antenna for the strong radio signals.

      Thanks for your comment.

  7. Mushtaq says:

    SUB:kernel module
    —-

    Hello, I am Mushtaq / LA3RIA. I have followed your web tauter for to install
    App for to listen FM Radio DVB-T Fun with a Raspberry. I am using the latest
    version of raspbian-wheezy v.2015-05-05

    After step by step installing software, I have got a issue, I do not understand how to
    setup the (automatically loading of the kernel module).

    Could you please help me how I can access for to get it work. I typed the same CMD:
    rtl_test. Got same answer as you have described in your web tauter.

    Looking forwarding to hear from you…

    TNX es 73 de Mushtaq / LA3RIA
    APRS: http://aprs.fi/la3ria-7

    • Cris says:

      Hi LA3RIA,

      If you mean you don’t know how to add anything to the blacklist, its actually pretty simple.

      Run as superuser or root :

      sudo nano /etc/modprobe.d/raspi-blacklist.conf

      add these lines –>

      blacklist dvb_usb_rtl28xxu
      blacklist rtl_2832
      blacklist rtl_2830

      Press CTRL-O to save

      That should do the trick.
      Kind regards, and 73’s back

  8. Ungatonga says:

    Do not working…. Thank you for the time ispend for nothing!!!

  9. Henk says:

    rtl_test
    Found 1 device(s):
    0: Realtek, RTL2838UHIDIR, SN: 00000013

    Using device 0: Generic RTL2832U OEM

    Kernel driver is active, or device is claimed by second instance of librtlsdr.
    In the first case, please either detach or blacklist the kernel module
    (dvb_usb_rtl28xxu), or enable automatic detaching at compile time.

    usb_claim_interface error -6
    Failed to open rtlsdr device #0

    This is what I get after rtl_test, even after editing /etc/modprobe.d/raspi-blacklist.conf.
    I don’t know if it make a difference but I am booting my PI from USB (stick 8GB)

    Greetings

  10. Mark Wright says:

    I wonder, how come things like that look both simple to do and unbelievingly complex? I mean I know Linux but the actual tinkering with a radio is something I can only think through but not actually do.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.