Skip to main content

A Python wrapper for librtlsdr (a driver for Realtek RTL2832U based SDR's)

Project description

Build Status

Description

pyrtlsdr is a simple Python interface to devices supported by the RTL-SDR project, which turns certain USB DVB-T dongles employing the Realtek RTL2832U chipset into low-cost, general purpose software-defined radio receivers. It wraps many of the functions in the librtlsdr library (including asynchronous read support), and also provides a more Pythonic API.

Usage

pyrtlsdr can be installed by downloading the source files and running python setup.py install, or using pip and pip install pyrtlsdr.

All functions in librtlsdr are accessible via librtlsdr.py and a Pythonic interface is available in rtlsdr.py (recommended). Some documentation can be found in docstrings in the latter file.

Examples

Simple way to read and print some samples:

from rtlsdr import RtlSdr

sdr = RtlSdr()

# configure device
sdr.sample_rate = 2.048e6  # Hz
sdr.center_freq = 70e6     # Hz
sdr.freq_correction = 60   # PPM
sdr.gain = 'auto'

print(sdr.read_samples(512))

Plotting the PSD with matplotlib:

from pylab import *
from rtlsdr import *

sdr = RtlSdr()

# configure device
sdr.sample_rate = 2.4e6
sdr.center_freq = 95e6
sdr.gain = 4

samples = sdr.read_samples(256*1024)

# use matplotlib to estimate and plot the PSD
psd(samples, NFFT=1024, Fs=sdr.sample_rate/1e6, Fc=sdr.center_freq/1e6)
xlabel('Frequency (MHz)')
ylabel('Relative power (dB)')

show()

Resulting plot here.

See the files ‘demo_waterfall.py’ and ‘test.py’ for more examples.

Experimental features

Two new submodules are available for testing: rtlsdraio, which adds native Python 3 asynchronous support (asyncio module), and rtlsdrtcp which adds a TCP server/client for accessing a device over the network. See the respective modules in the rtlsdr folder for more details and feel free to test and report any bugs!

rtlsdraio

Note that the rtlsdraio module is automatically imported and adds stream() and stop() methods to the normal RtlSdr class. It also requires the new async/await syntax introduced in Python 3.5+.

The syntax is basically:

async def streaming():
 sdr = RtlSdr()

 async for samples in sdr.stream():
  # do something with samples
  # ...

  # to stop streaming:
  sdr.stop()

 # done
 sdr.close()

asyncio.get_event_loop().run_until_complete(streaming())

Dependencies

  • Windows/Linux/OSX

  • Python 2.7.x/3.3+

  • librtlsdr (builds dated after 5/5/12)

  • Optional: NumPy (wraps samples in a more convenient form)

matplotlib is also useful for plotting data. The librtlsdr binaries (rtlsdr.dll in Windows and librtlsdr.so in Linux) should be in the pyrtlsdr directory, or a system path. Note that these binaries may have additional dependencies.

Todo

There are a few remaining functions in librtlsdr that haven’t been wrapped yet. It’s a simple process if there’s an additional function you need to add support for, and please send a pull request if you’d like to share your changes.

Troubleshooting

  • Some operating systems (Linux, OS X) seem to result in libusb buffer issues when performing small reads. Try reading 1024 (or higher powers of two) samples at a time if you have problems.

  • If you’re having librtlsdr import errors:

  • Windows: Make sure all the librtlsdr DLL files (rtlsdr.dll and libusb-1.0.dll) are in your system path, or the same folder as this README file. Also make sure you have all of their dependencies (e.g. the Visual Studio runtime files). If rtl_sdr.exe works, then you should be okay. Also note that you can’t mix the 64 bit version of Python with 32 bit builds of librtlsdr, and vice versa.

  • Linux: Make sure your LD_LIBRARY_PATH environment variable contains the directory where the librtlsdr.so.0 library is located. You can do this in a shell with (for example): export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib. See here for more details.

License

All of the code contained here is licensed by the GNU General Public License v3.

Credit

Credit to dbasden for his earlier wrapper python-librtlsdr and all the contributers on GitHub.

Copyright (C) 2013 by Roger https://github.com/roger-

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyrtlsdr-0.2.2.tar.gz (17.2 kB view details)

Uploaded Source

Built Distributions

pyrtlsdr-0.2.2-py35-none-any.whl (23.8 kB view details)

Uploaded Python 3.5

pyrtlsdr-0.2.2-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

pyrtlsdr-0.2.2-py2-none-any.whl (23.8 kB view details)

Uploaded Python 2

File details

Details for the file pyrtlsdr-0.2.2.tar.gz.

File metadata

  • Download URL: pyrtlsdr-0.2.2.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyrtlsdr-0.2.2.tar.gz
Algorithm Hash digest
SHA256 cd632ac74f07cef8f9cc4aea348f50288a07146becf1ae0424f682c00b9fd67a
MD5 fe4edfb725d8f1c0c84587140e81aa54
BLAKE2b-256 2b164d170517fd2be3179aa010d422b06baa91c2fab0efb4aa6e4cc4e6f17fc2

See more details on using hashes here.

File details

Details for the file pyrtlsdr-0.2.2-py35-none-any.whl.

File metadata

File hashes

Hashes for pyrtlsdr-0.2.2-py35-none-any.whl
Algorithm Hash digest
SHA256 509e5cec0e6813cdccd3ccb928c6ea8bea4a08c679538381a3623c9646f48da0
MD5 d584757cb2939784279077d1bcf1e65e
BLAKE2b-256 ab9300d0d64147c4d4399e0e575e33fc0d4255b6ce34e089a42b29559b8d2a4c

See more details on using hashes here.

File details

Details for the file pyrtlsdr-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pyrtlsdr-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d10a397fa517a9dec0992304dd9863926d15a433238a999f7461d205f7a6fa66
MD5 7f8dc111fc436886516a9c2f7f3d74d4
BLAKE2b-256 be0085a848cfddfd9bebde4eb54c9c57b53018f18314e9f7285e3395a0481dbe

See more details on using hashes here.

File details

Details for the file pyrtlsdr-0.2.2-py2-none-any.whl.

File metadata

File hashes

Hashes for pyrtlsdr-0.2.2-py2-none-any.whl
Algorithm Hash digest
SHA256 c4ba07f6546e3ab4626bd043ae341d35bbfd4c4082cef154a18f875975e21de8
MD5 134c5419971a7650c68b235be3014531
BLAKE2b-256 fe0ddb9d193f4f148bcc93f378c5f6da79ab1a071506954c320c4f8519f9f82b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page