Skip to content

Linux_info

Mark Wickert edited this page Dec 28, 2017 · 2 revisions

Linux Setup Information

This page will explain how to configure Linux (Ubuntu 16.04 x64, but similar for others) for the RTL-SDR dongle and Pyaudio for real-time DSP using internal and external audio devices.

RTL-SDR

The device you are configuring is the TV tuner USB dongle known as the RTL-SDR, which as this link shows can be purchased for under $20. During the tutorial a number of these dongles will be available for hands-on experimenting with signal capture and processing the signals into playback information, e.g., music, speech, and data bits. Not required, but encouraged for the hardware tinkerer, is to purchase your own dongle from the above link.

Background

On to the software driver set-up. A good set of instructions on Linux set-up is (http://osmocom.org/projects/sdr/wiki/rtl-sdr). In the tradition of Linux this is a build from scratch approach that starts with git clone git://git.osmocom.org/rtl-sdr.git. On a rebuilt machine running Ubuntu 16.04, I chose the cmake option, but first had to install cmake and libusb 1.0:

sudo apt install cmake
sudo apt-get install libusb-1.0-0-dev

To build the library and command line utilities I took the following steps:

cd rtl-sdr/
mkdir build
cd build
cmake ../ -DINSTALL_UDEV_RULES=ON
make
sudo make install-udev-rules
sudo ldconfig

The library files and command line utilities are found in /rtl-sdr/build/src:

mwickert@ubuntu:~/rtl-sdr/build/src$ ls
CMakeFiles               librtlsdr.so         rtl_adsb    rtl_sdr
cmake_install.cmake      librtlsdr.so.0       rtl_eeprom  rtl_tcp
libconvenience_static.a  librtlsdr.so.0.5git  rtl_fm      rtl_test
librtlsdr.a              Makefile             rtl_power

One remaining detail is black listing.

Black Listing

See (https://www.reddit.com/r/RTLSDR/wiki/blacklist_dvb_usb_rtl28xxu) which explains how to avoid conflict with the real digital video broadcast intent of the RTL-SDR. Simply put you can avoid conflict by the placing a file in /etc/modprobe.d with the extension .conf, for example

mwickert@ubuntu:~$ cd /etc/modprobe.d/
mwickert@ubuntu:/etc/modprobe.d$ ls
alsa-base.conf              blacklist-modem.conf         fbdev-blacklist.conf
blacklist-ath_pci.conf      blacklist-oss.conf           iwlwifi.conf
blacklist.conf              blacklist-rare-network.conf  mlx4.conf
blacklist-firewire.conf     blacklist-rtl_dvb.conf       vmwgfx-fbdev.conf
blacklist-framebuffer.conf  blacklist-watchdog.conf
mwickert@ubuntu:/etc/modprobe.d$ cat blacklist-rtl_dvb.conf 
blacklist dvb_usb_rtl28xxu 
blacklist rtl2832 
blacklist rtl2830

As the final step pip install pyrtlsdr:

Marks-MacBook-Pro:MacOS wickert$ pip install pyrtlsdr
Collecting pyrtlsdr
  Downloading pyrtlsdr-0.2.4-py2.py3-none-any.whl
Installing collected packages: pyrtlsdr
Successfully installed pyrtlsdr-0.2.4

Note: The installation also sets up a path to the drivers so you can access the utilities from and any location, and the pyrtlsdr can access the libraries accordingly.

Testing the Install with/without the RTL-SDR Dongle

There are a number of command line utilities that are part of the RTL-SDR driver set, common to all platforms, i.e.,

mwickert@ubuntu:~/RTLSDR/rtl-sdr/build/src$ ls -l
-rwxrwxr-x  1 mwickert mwickert  29024 May 23 23:00 rtl_adsb
-rwxrwxr-x  1 mwickert mwickert  22288 May 23 23:00 rtl_eeprom
-rwxrwxr-x  1 mwickert mwickert  47696 May 23 23:00 rtl_fm
-rwxrwxr-x  1 mwickert mwickert  42224 May 23 23:00 rtl_power
-rwxrwxr-x  1 mwickert mwickert  23608 May 23 23:00 rtl_sdr
-rwxrwxr-x  1 mwickert mwickert  29744 May 23 23:00 rtl_tcp
-rwxrwxr-x  1 mwickert mwickert  24160 May 23 23:00 rtl_test

In particular rtl_eeprom reads registers in the dongle. To explore any of these utilities type util_name -h at the command line to get help on the command. Usage examples for some of them can be found at (http://osmocom.org/projects/sdr/wiki/rtl-sdr) . I use this below to see if all is well when the dongle is present. There is not too much to do without the dongle present, but some encouragement is the following:

mwickert@ubuntu:~$ rtl_eeprom
No supported devices found.

The above at least tells you the USB interface drivers are trying find a device. With the dongle plugged in I get:

mwickert@ubuntu:~$ rtl_eeprom
Found 1 device(s):
  0:  Generic RTL2832U OEM

Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner

Current configuration:
__________________________________________
Vendor ID:		0x0bda
Product ID:		0x2838
Manufacturer:		Realtek
Product:		RTL2838UHIDIR
Serial number:		00000001
Serial number enabled:	yes
IR endpoint enabled:	yes
Remote wakeup enabled:	no
__________________________________________

Capture Test

Once you have a RTL-SDR dongle available you can perform a sample capture using the code found in the Jupyter notebook RTL-SDR_Test.ipynb which is located in the tutorial repo folder hardware_configure.

Setting Up a GUI Receiver App (optional)

After setting up the drivers, you optionally can install an SDR receiver application known as GQRX (similar to SDR# for Windows). If you decide to purchase your own RTL-SDR I highly recommend installing a receiver app such as this one.

GQRX on Linux

Pyaudio

Audio I/O is another avenue for hardware interfacing between your PC and the signal processing capabilities of Python. Pure audio I/O is of interest unto itself, but you can also thing of streaming audio out of your PC as the back-end to streaming radio signals in via the RTL-SDR. The intent of the tutorial is to focus on processing signal captures made from the RTL-SDR. Setting up a real-time stream from the radio input the audio output is the ultimate challenge, and something that I have been contemplating, but do not have a polished solution for just yet. The speed limitations of Python means that the Python code that sits between the input and output be very lean and efficient, and requires the use of call-backs and buffer management.

To get started with analog I/O I like Pyaudio, which provides Python bindings to the well established cross-platform C/C++ library PortAudio. PortAudio is used in many of the RTL-SDR apps that you can read about on the Web. For Linux follow the instructions found on the Pyaudio project Web Site.

Test the Installation

When installation is complete you can run code samples found in the Jupyter notebook Pyaudio_Test.ipynb which is located in the tutorial repo folder hardware_configure. You will be able hear sounds playing through your speakers or headphones.