Rtl-sdr

From Technologia Incognita
Revision as of 17:52, 13 January 2016 by Einstein (talk | contribs)
Jump to: navigation, search

DVB-T Fun with a Raspberry PI – Playing Radio with Linux (Part 1) Posted on January 12, 2014 by cris

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 :