Rtl-sdr

From Technologia Incognita
Revision as of 18:25, 13 January 2016 by Einstein (talk | contribs) (Weatherstations)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Projects
Participants Einstein
Skills 2+
Status Active
Niche Software
Purpose Fun

RTL-SDR

Installing rtl-sdr

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.

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

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.

Playing Radio with Linux

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)

Recieving Airtraffic

In this series we are going to use our previous setup to receive aircraft information with dump1090 . What aircraft is flying where? What altitude? Where is it heading to? All this information from the airplanes near the reach of your antenna can be grabbed from the air (1090Mhz) .. and all this with your little Raspberry and a cheap DVB-T Dongle.

I won’t go into details how to make a fancy antenna for this frequency. I am pretty sure there are many examples on the net. So google for one if you like if you are not happy with your reception.

In order to decode the information out of the air you might want to use a program called : dump1090 which is found on github. (This is the project page)

Login to your Raspberry pi as user and type the following commands. I assume you already followed the Part 1 tutorial with the setup that is mentioned there.

git  clone  git://github.com/MalcolmRobb/dump1090.git
cd  dump1090
make

Now, there are a few ways to start the tool, the quickest and easiest to test is to type :

./dump1090 --interactive

This will give you a screen similar to the picture above. But the most awesome feature (i think) is the fact that this little program has a build in web-server running on port 8080. Allowing you to see the airplanes flying on a map (in realtime!) You can start this feature by typing :

./dump1090 --interactive --net

Now browse from any other PC connected on your network to your raspberry by opening :

http://<ip-of-your-raspberry>:8080


Well, happy airplane spotting :)

Recieving Weatherstations

Welcome back to part 3 already with DVB-T Fun with a Raspberry PI. In this part I will show you how you can profit from receiving all the data of your neighbors fancy wireless weather station data and use it for your own benefits.

Weatherstations with wireless sensors are very common and cheap now-a-days. Prices vary from 80 euro to a few hundred euros. What most of them have in common is the use of the LPD433 (Low Power Device 433 MHz) or unlicensed ISM band/SRD bandfrequency to transmit the data on air. (Among with wireless doorbells, cheap wireless alarms, car key-locks e.t.c…)

The maximum transmission power for these devices is 10mW max. This will cause you will be receiving only weather stations that are in your direct vicinity (depending on your antenna set-up of course)

In order to decode these signals I will have to redirect you to part 1 where the basic setup for the basic setup of RTL_SDR. If you have this working, the following program will work too as it is based on the same code.

We will use rtl_433, which turns your Realtek RTL2832 based DVB dongle into a 433.92MHz generic data receiver.

Installation instructions:

git clone https://github.com/merbanan/rtl_433.git
cd rtl-433/
mkdir build
cd build
cmake ../
make

Now… lets start the fun, and start the program (which will be located in /rtl_433/build/src)

pi@srv-rasp-01 ~/rtl_433/build/src $ ./rtl_433 -p 24
Registering protocol[01] Rubicson Temperature Sensor
Registering protocol[02] Prologue Temperature Sensor
Registering protocol[03] Silvercrest Remote Control
Registering protocol[04] ELV EM 1000
Registering protocol[05] ELV WS 2000
Registering protocol[06] Waveman Switch Transmitter
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001
Using device 0: ezcap USB 2.0 DVB-T/DAB/FM dongle
Found Rafael Micro R820T tuner
Exact sample rate is: 250000.000414 Hz
Sample rate set to 250000.
Sample rate decimation set to 0. 250000->250000 
Bit detection level set to 10000.
Tuner gain set to Auto.
Reading samples in async mode...
Tuned to 433920000 Hz.
Sensor temperature event:
protocol       = Rubicson/Auriol
rid            = ac
temp           = 5.2
ac 80 34 f6 50

And there is the first weather station. 5.2 degrees Celsius. Good to know :) .. There are many more options to explore (you can use the -a option to analyze the signal) and you probably will receive some wireless doorbells, energy switches , e.t.c. so hopefully this will inspire you to do something nice with it.

rtl_sdr -a

Good luck with receiving! source: http://www.yellownote.nl/blog/index.php/2014/01/12/dvb-t-fun-raspberry-pi/