From charlesreid1

Overview

Plug It In

First thing is to hook up the antenna to the USB dongle, and plug the USB dongle into the computer, and make sure the computer sees it:

$ lsusb | grep -i rtl
Bus 001 Device 003: ID 0bda:2838 Realtek Semiconductor Corp. RTL2838 DVB-T

Get Software

Gnu Radio

First thing is to install gnuradio.

apt-get install gnuradio

Cmake

Yer gonna need Cmake.

apt-get install cmake

Boost/GSL Development

Then we'll install the Boost and GSL headers/development libraries for building scripts:

apt-get install libboost-1.49 libboost-dev libgsl0-dev

(Note that both of these were found using aptitude search [keyword]).

RTL-SDR Project

Next, clone into the rtl-sdr repository:

git clone git://git.osmocom.org/rtl-sdr.git

This project contains the software needed to interpret the raw I/Q packets sent from the antenna to the computer.

Now build the RTL-SDR project:

mkdir build
cd build
cmake ../

LibUSB Error

cmake ../
-- The C compiler identification is GNU 4.7.2
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Build type not specified: defaulting to release.
-- Extracting version information from git describe...
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.26") 
-- checking for module 'libusb-1.0'
--   package 'libusb-1.0' not found
-- Looking for libusb_handle_events_timeout_completed
-- Looking for libusb_handle_events_timeout_completed - not found
-- Looking for libusb_error_name
-- Looking for libusb_error_name - not found
-- libusb-1.0 not found.
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
CMake Error at CMakeLists.txt:69 (message):
  LibUSB 1.0 required to compile rtl-sdr


-- Configuring incomplete, errors occurred!

Oh no dude! We're doomed!

Naw, it's cool, we can fix that by installing LibUSB, since that's what the last line of the error said to do.

$ apt-get install libusb
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package libusb

Oh no dude! We're doomed!

Naw, just kidding, we can fix that by looking for libusb-related packaged with aptitude:

$ aptitude search libusb
p   libusb++-0.1-4c2                                       - userspace C++ USB programming library                           
p   libusb++-dev                                           - userspace C++ USB programming library development files         
i   libusb-0.1-4                                           - userspace USB programming library                               
i A libusb-1.0-0                                           - userspace USB programming library                               
p   libusb-1.0-0-dbg                                       - userspace USB programming library development files             
p   libusb-1.0-0-dev                                       - userspace USB programming library development files             
p   libusb-1.0-doc                                         - documentation for userspace USB programming                     
i A libusb-dev                                             - userspace USB programming library development files             
[......]

We need both the regular and the development versions of LibUSB 1.0. So the package we need is: libusb-1.0-0-dev

apt-get install libusb-1.0-0-dev

Return to the SDR Project

Okay, now we can go back to our build directory in the rtll-sdr project, and re-run cmake:

$ cmake ../
-- Build type not specified: defaulting to release.
-- Extracting version information from git describe...
-- checking for module 'libusb-1.0'
--   found libusb-1.0, version 1.0.17
-- Found libusb-1.0: /usr/include/libusb-1.0, /usr/lib/x86_64-linux-gnu/libusb-1.0.so
-- Udev rules not being installed, install them with -DINSTALL_UDEV_RULES=ON
-- Building with kernel driver detaching disabled, use -DDETACH_KERNEL_DRIVER=ON to enable
-- Building for version: v0.5.3-12-ge3c0 / 0.5git
-- Using install prefix: /usr/local
-- Configuring done
-- Generating done
-- Build files have been written to: /root/codes/sdr/rtl-sdr/build

All done! Just kidding, you gotta make it first:

make
Scanning dependencies of target convenience_static
[  5%] Building C object src/CMakeFiles/convenience_static.dir/convenience/convenience.c.o
Linking C static library libconvenience_static.a
[  5%] Built target convenience_static
Scanning dependencies of target rtlsdr_shared
[ 10%] Building C object src/CMakeFiles/rtlsdr_shared.dir/librtlsdr.c.o
[ 15%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_e4k.c.o
[ 20%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_fc0012.c.o
[ 25%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_fc0013.c.o
[ 30%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_fc2580.c.o
[ 35%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_r82xx.c.o
Linking C shared library librtlsdr.so
[ 35%] Built target rtlsdr_shared
Scanning dependencies of target rtl_adsb
[ 40%] Building C object src/CMakeFiles/rtl_adsb.dir/rtl_adsb.c.o
Linking C executable rtl_adsb
[ 40%] Built target rtl_adsb
Scanning dependencies of target rtl_eeprom
[ 45%] Building C object src/CMakeFiles/rtl_eeprom.dir/rtl_eeprom.c.o
Linking C executable rtl_eeprom
[ 45%] Built target rtl_eeprom
Scanning dependencies of target rtl_fm
[ 50%] Building C object src/CMakeFiles/rtl_fm.dir/rtl_fm.c.o
Linking C executable rtl_fm
[ 50%] Built target rtl_fm
Scanning dependencies of target rtl_power
[ 55%] Building C object src/CMakeFiles/rtl_power.dir/rtl_power.c.o
Linking C executable rtl_power
[ 55%] Built target rtl_power
Scanning dependencies of target rtl_sdr
[ 60%] Building C object src/CMakeFiles/rtl_sdr.dir/rtl_sdr.c.o
Linking C executable rtl_sdr
[ 60%] Built target rtl_sdr
Scanning dependencies of target rtl_tcp
[ 65%] Building C object src/CMakeFiles/rtl_tcp.dir/rtl_tcp.c.o
Linking C executable rtl_tcp
[ 65%] Built target rtl_tcp
Scanning dependencies of target rtl_test
[ 70%] Building C object src/CMakeFiles/rtl_test.dir/rtl_test.c.o
Linking C executable rtl_test
[ 70%] Built target rtl_test
Scanning dependencies of target rtlsdr_static
[ 75%] Building C object src/CMakeFiles/rtlsdr_static.dir/librtlsdr.c.o
[ 80%] Building C object src/CMakeFiles/rtlsdr_static.dir/tuner_e4k.c.o
[ 85%] Building C object src/CMakeFiles/rtlsdr_static.dir/tuner_fc0012.c.o
[ 90%] Building C object src/CMakeFiles/rtlsdr_static.dir/tuner_fc0013.c.o
[ 95%] Building C object src/CMakeFiles/rtlsdr_static.dir/tuner_fc2580.c.o
[100%] Building C object src/CMakeFiles/rtlsdr_static.dir/tuner_r82xx.c.o
Linking C static library librtlsdr.a
[100%] Built target rtlsdr_static


Gnu Radio Baz

The Baz extension for gnu radio:

git clone https://github.com/balint256/gr-baz.git

and apparently I didn't install the right boost library.

Using RTL-SDR

Now that we've installed RTL-SDR, we can start to use it.

The Binary

You can enter the src/ directory of your Cmake build, and you'll see your rtl-sdr binary:

ls -1 src/
CMakeFiles
cmake_install.cmake
libconvenience_static.a
librtlsdr.a
librtlsdr.so
librtlsdr.so.0
librtlsdr.so.0.5git
Makefile
rtl_adsb
rtl_eeprom
rtl_fm
rtl_power
rtl_sdr
rtl_tcp
rtl_test

Test

First thing I ran was the sdr_test binary:

./rtl_test 
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001

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.

We can detach driver modules from the kernel by using rmmod, so we'll detach this module:

rmmod dvb_usb_rtl28xxu

and try again.

Hello RTL-SDR World!

HelloSDRWorld.png

$ ./rtl_test 
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001

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 
[R82XX] PLL not locked!
Sampling at 2048000 S/s.

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...

What does all this mean?!?

The antenna is basically ingesting raw radio frequency information, at whatever frequency it happens to be listening on (it's variable), and is reading 2048000 samples per second. That means, if we want to scan a whole range of frequencies, we can grab a handful of samples from each frequency, and loop through every single frequency, and it won't take very long. That enables us to create a "waterfall" display of activity across a whole range of frequencies, even though an antenna can only listen to one frequency at a time.

Dumping What You Hear

You can dump out what the antenna hears with the rtl_sdr script, which does a raw dump of binary data from onboard the SDR chip. This has a couple of nice parameters:

./rtl_sdr
rtl_sdr, an I/Q recorder for RTL2832 based DVB-T receivers

Usage:	 -f frequency_to_tune_to [Hz]
	[-s samplerate (default: 2048000 Hz)]
	[-d device_index (default: 0)]
	[-g gain (default: 0 for auto)]
	[-p ppm_error (default: 0)]
	[-b output_block_size (default: 16 * 16384)]
	[-n number of samples to read (default: 0, infinite)]
	[-S force sync output (default: async)]
	filename (a '-' dumps samples to stdout)

Suppose we want to listen to 900 MHz, like all the other cool hipster hacker kids who are doing HamProxy SDR projects. Okay, we're gonna listen to 920 MHz. We're reading at about 2 billion samples per second (take a minute to contemplate that: that's absolutely astounding). We can specify a number of samples, this obviously doesn't correspond to the number of samples it's taking per second because the two don't match up at all:

$ ./rtl_sdr /tmp/raw_sdr -f 920e6 -n 1e6

This will make a file full of gibberish:

SDRGibberish.png

Freeze. Kill. Respawn. Repeat.

If you run into problems with the radio freezing up or listening forever and not responding to Contrl+C, you can always do a killall on your process, unplug the USB dongle, re-plug it in, and run:

rmmod dvb_usb_rtl28xxu