tech stuff

Main - Archive - About - Feed

RPi, rtl_sdr and DIY discone

RPi works great as Software Defined Radio station. Here is my setup: cheap USB DVB-T dongle with RTL2832U chipset and Elonics E4000 tuner (more info on RTL-SDR and supported hardware can be found here, I've bought mine here), connected to Raspbery Pi USB port.

RPi uses default raspbian image from here on a 4GB micro-SD card.

Kernel identifies device and loads apropriate module:

[    3.179476] usb 1-1.3: new high-speed USB device number 4 using dwc_otg
[    3.302080] usb 1-1.3: New USB device found, idVendor=0ccd, idProduct=00d7
[    3.310923] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    3.319909] usb 1-1.3: Product: RTL2838UHIDIR
[    3.325762] usb 1-1.3: Manufacturer: Realtek
[    3.331517] usb 1-1.3: SerialNumber: 00000001

[    8.555931] usb 1-1.3: dvb_usb_v2: found a 'TerraTec Cinergy T Stick+' in warm state
[    8.567425] usbcore: registered new interface driver dvb_usb_rtl28xxu
[    8.640382] usb 1-1.3: dvb_usb_v2: will pass the complete MPEG2 transport stream to the software demuxer
[    8.665831] DVB: registering new adapter (TerraTec Cinergy T Stick+)
[    8.718103] usb 1-1.3: DVB: registering adapter 0 frontend 0 (Realtek RTL2832 (DVB-T))...
[    8.811593] i2c i2c-0: e4000: Elonics E4000 successfully identified
[    8.837842] Registered IR keymap rc-empty
[    8.849773] input: TerraTec Cinergy T Stick+ as /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/rc/rc0/input0
[    8.876496] rc0: TerraTec Cinergy T Stick+ as /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/rc/rc0
[    8.904216] usb 1-1.3: dvb_usb_v2: schedule remote query interval to 400 msecs
[    8.931812] usb 1-1.3: dvb_usb_v2: 'TerraTec Cinergy T Stick+' successfully initialized and connected


# lsusb -s 001:004
Bus 001 Device 004: ID 0ccd:00d7 TerraTec Electronic GmbH

Actually, if I connect USB dongle to the live Pi, it reboots, probably due some power issues, but if it's booted attached, everything's fine. RPi is networked and connected to the LAN.

Building rtl-sdr:

# apt-get install cmake libusb-1.0-0-dev
# mkdir -p /lab/srd
# cd /lab/srd
# git clone git://git.osmocom.org/rtl-sdr.git
# cd rtl-sdr/
# mkdir build
# cd build
# cmake ../
# make
# make install
# ldconfig

Testing:

# rtl_test -t
Found 1 device(s):
  0:  Terratec T Stick PLUS

Using device 0: Terratec T Stick PLUS

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.

Removing and blacklisting dvb_usb_rtl28xxu module:

# modprobe -r dvb_usb_rtl28xxu
# echo '# blacklist dvb_usb_rtl28xxu for rtl-sdr' > /etc/modprobe.d/rtl-sdr.conf
# echo 'blacklist dvb_usb_rtl28xxu' >> /etc/modprobe.d/rtl-sdr.conf

And testing again:

# 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 2223000000 Hz!
[E4K] PLL not locked for 1112000000 Hz!
[E4K] PLL not locked for 1252000000 Hz!
E4K range: 53 to 2222 MHz
E4K L-band gap: 1112 to 1252 MHz

So, we have a wide range, 53-2222 MHz receiver. And now we need an antenna. We are hitting a situation from an old ham radio saying: "Buy a $10 radio and a $100 antenna". Discone is a good choice for our purposes, because it's wideband and we can create one out of scrap.

First, some visual understanding, how it should look like here.

Second, several DIY variants: here, here, and here(ru).

Third - Discone Antenna Calculato

To build mine I used:

  • 8x 30cm stainless steel rulers, like this
  • 8pcs of 1m galvanized hanger wire hooks for suspension celing, like this
  • 32mm PVC bell-end drainage/sewer pipe like this - two pieces, 25cm and 1m, and 32mm socket plug
  • M6 screw with DIN-315 wing nut
  • 2x hose metal clamps like this
  • ~10m of RG58 50Ω coax cable

Stainless steel rulers form a disc part of the discone, and are connected with a screw through the plug to the core of the coax cable. Hanger wires, mounted with clamps to the pipe, forms the cone part, and are connected to the shield.

After connecting the antenna to the USB dongle, on the RPi we can launch

# rtl_tcp -a 0.0.0.0

dowload latest build of the SDR# to some PC on the same network, choose "RTL-SDR/TCP" as a source, configure IP of the RPi and port 1234 in it's settings, and play around.

On this screen we see SDR# tuned to Vilnius Approach Air Traffic frequiency (120.700 MHz AM) with active voice communication with RyanAir board taking place.

RPi Linaro cross-compiller toolchain

Continuing with RPi booting options, we need a way to compile both u-boot and RPi kernels. Setting cross-compiler toolchain on x86 Debian linux box is the most optimal way. It's quite straightforward if you just follow instructions. My log (with minor modifications) is below:

$ sudo apt-get install gperf bison flex texinfo libtool automake subversion
$ mkdir -p /lab/pi/src
$ cd /lab/pi/src
$ wget -c http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.19.0.tar.bz2
$ tar -jxvf crosstool-ng-1.19.0.tar.bz2
$ cd crosstool-ng-1.19.0
$ ./configure --prefix=/lab/pi/crosstool-ng-1.19.0
$ make
$ make install
$ export PATH=$PATH:/lab/pi/crosstool-ng-1.19.0/bin
$ mkdir -p /lab/pi/x-compiler/build
$ cd /lab/pi/x-compiler/build
$ ct-ng menuconfig

Configure values as per instructions. The only difference in my case was "gcc version" "linaro-4.8-2013.06-1", as "linaro-4.7-2012.10" failed to build due some conflicts. I did menuconfig once, so now I can do:

$ wget http://dev.xff.lt/stuff/pi/crosstool-ng-config.txt -O .config
$ ct-ng oldconfig

my CT_PREFIX_DIR is commented out, so you'll need to provide your target directory, and then

$ ct-ng build

it took ~50 minutes on VPS with 2 x 2.40 GHz, including downloading all the sources.</p>

apt-cyg and .xz archives

Stock apt-cyg has one more problem, besides the one already fixed before. Yesterday I've noticed, that it fails to install new packages in .tar.xz format (before there were only .tar.bz2). The problem is in these lines:

echo "Unpacking..."
cat $file | bunzip2 | tar > "/etc/setup/$pkg.lst" xvf - -C /

There are several fixes (1, 2) available, but most have errors in them. The easiest way to fix this, is to let tar guess compression method by itself (modern tar can do it):

echo "Unpacking..."
tar -xvf $file -C / > "/etc/setup/$pkg.lst"

apt-cyg fixed the right way can be found in this fork on github.