Sunday, 8 April 2018

Software Defined Radio: installing rtl-sdr in Slackware 14.2

RTL2832U 
I got a generic no-name RTL2832U TVB-T USB dongle for just RM39. Plug it into a Slackware 14.2 with a recent kernel (I have 4.16.0) and if you did a 'dmesg -T':

[Fri Mar 30 00:12:58 2018] usb 1-2: new high-speed USB device number 57 using xhci_hcd
[Fri Mar 30 00:12:58 2018] usb 1-2: New USB device found, idVendor=0bda, idProduct=2838
[Fri Mar 30 00:12:58 2018] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[Fri Mar 30 00:12:58 2018] usb 1-2: Product: RTL2838UHIDIR
[Fri Mar 30 00:12:58 2018] usb 1-2: Manufacturer: Realtek
[Fri Mar 30 00:12:58 2018] usb 1-2: SerialNumber: 00000001
[Fri Mar 30 00:12:59 2018] usb 1-2: dvb_usb_v2: found a 'Realtek RTL2832U reference design' in warm state
[Fri Mar 30 00:12:59 2018] usb 1-2: dvb_usb_v2: will pass the complete MPEG2 transport stream to the software demuxer
[Fri Mar 30 00:12:59 2018] dvbdev: DVB: registering new adapter (Realtek RTL2832U
 reference design)
[Fri Mar 30 00:12:59 2018] i2c i2c-11: Added multiplexed i2c bus 12
[Fri Mar 30 00:12:59 2018] rtl2832 11-0010: Realtek RTL2832 successfully attached
[Fri Mar 30 00:12:59 2018] usb 1-2: DVB: registering adapter 0 frontend 0 (Realtek RTL2832 (DVB-T))...
[Fri Mar 30 00:12:59 2018] i2c i2c-12: fc0012: Fitipower FC0012 successfully identified
[Fri Mar 30 00:12:59 2018] lirc_dev: IR Remote Control driver registered, major 237
[Fri Mar 30 00:12:59 2018] IR LIRC bridge handler initialized
[Fri Mar 30 00:12:59 2018] Registered IR keymap rc-empty
[Fri Mar 30 00:12:59 2018] rc rc0: Realtek RTL2832U reference design as /devices/
pci0000:00/0000:00:14.0/usb1/1-2/rc/rc0
[Fri Mar 30 00:12:59 2018] input: Realtek RTL2832U reference design as /devices/p
ci0000:00/0000:00:14.0/usb1/1-2/rc/rc0/input132
[Fri Mar 30 00:12:59 2018] rc rc0: lirc_dev: driver ir-lirc-codec (dvb_usb_rtl28xxu) registered at minor = 0
[Fri Mar 30 00:12:59 2018] usb 1-2: dvb_usb_v2: schedule remote query interval to
 200 msecs
[Fri Mar 30 00:13:00 2018] usb 1-2: dvb_usb_v2: 'Realtek RTL2832U reference design' successfully initialized and connected
[Fri Mar 30 00:13:00 2018] usbcore: registered new interface driver dvb_usb_rtl28xxu

            This means the device is working and ahs been recognized by the kernel:
root$ls -lt /dev/dvb
total 0
drwxr-xr-x 2 root root 120 Apr  2 09:33 adapter0

The SDR software of choice for Linux Slackware 14.2 has got to be rtl-sdr. I simply followed the steps for Linux listed in their 'Quick Start Guiide', and are relisted here as tested steps for Slackware 14.2.

My download was from osmocom.

~/sdr/rtl-sdr$unzip rtl-sdr-master.zip
~/sdr/rtl-sdr/rtl-sdr-master$autoreconf -i
~/sdr/rtl-sdr/rtl-sdr-master$./configure
~/sdr/rtl-sdr/rtl-sdr-master$make
~/sdr/rtl-sdr/rtl-sdr-master$su -c "make install"

Since rtl-sdr is mainly a library; at this point it will list some instructions on linking to it:

----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the 'LD_RUN_PATH' environment variable
     during linking
   - use the '-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to '/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

~/sdr/rtl-sdr/rtl-sdr-master$su -c "ldconfig"

Now you will need to remove (or better yet blacklist) the kernel driver for RTL2832U:

root@aspireF15:/home/heong/sdr$modprobe -vr dvb_usb_rtl28xxu
rmmod dvb_usb_rtl28xxu
rmmod dvb_usb_v2
rmmod rc_core

A quick test (Ctrl-C to exit):

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

Using device 0: Generic RTL2832U OEM
Found Fitipower FC0012 tuner
Supported gain values (5): -9.9 -4.0 7.1 17.9 19.2
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...
Signal caught, exiting!
^CSignal caught, exiting!

User cancel, exiting...
Samples per million lost (minimum): 0

The next command to use is rtl_power. Aim it at some known frequency, perhaps your local FM radio station. In my case it aimed it at my autogate remote at 330MHz:

$rtl_power -f 320000000:340000000:1000 -e 10m -g 40 -i 1s persona.csv
Number of frequency hops: 8
Dongle bandwidth: 2500000Hz
Downsampling by: 1x
Cropping by: 0.00%
Total FFT bins: 32768
Logged FFT bins: 32768
FFT bin size: 610.35Hz
Buffer size: 16384 bytes (3.28ms)
Reporting every 1 seconds
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001

Using device 0: Generic RTL2832U OEM
Found Fitipower FC0012 tuner
Tuner gain set to 19.20 dB.
Exact sample rate is: 2500000.107620 Hz

User cancel, exiting...

This produces a massive data file persona.csv.

Now we need to visualize the data. keenerd has a simple python script, heatmap.py. Download it, rename it to heatmap.py and make it executable:
$chmod +x heatmap.py

We aim it at persona.csv:
$./heatmap.py --offset 1000 --ytick 0.001s --palette charolastra persona.csv persona.png

The output is an image file persona.png, which looked something like this:

x-axis is frequence, y-axis is time. The 8 red smudges correspond to two buttons on the autogate remote, 4 presses each

There you have it: instant gratification SDR. 

Happy Trails.

No comments:

Post a Comment