Skip to main content

Python wrapper for the libhackrf library

Project description

pyhackrf

Motivation

All python bindings for hackrf are experimental at best and the installation is quite quirky and weird. This is an attempt to change that.

Installation

pip install hackrf

Quick Example

To take samples and plot the power spectral density:

from libhackrf import *
from pylab import *     # for plotting

with HackRF() as hackrf:
	hackrf.sample_rate = 20e6
	hackrf.center_freq = 88.5e6

	samples = hackrf.read_samples(2e6)

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

More Example Use

To create a hackrf device:

from libhackrf import *

hackrf = HackRF()

If you have two HackRFs plugged in, you can open them with the device_index argument:

hackrf1 = HackRF(device_index = 0)
hackrf2 = HackRF(device_index = 1)

Callbacks

def my_callback(hackrf_transfer):
    c = hackrf_transfer.contents
    values = cast(c.buffer, POINTER(c_byte*c.buffer_length)).contents
    iq = bytes2iq(bytearray(values))

    return 0


# Start receiving...
hackrf.start_rx(my_callback)

# If you want to stop receiving...
hackrf.stop_rx()

Gains

There is a 14 dB amplifier at the front of the HackRF that you can turn on or off. The default is off.

The LNA gain setting applies to the IF signal. It can take values from 0 to 40 dB in 8 dB steps. The default value is 16 dB.

The VGA gain setting applies to the baseband signal. It can take values from 0 to 62 dB in 2 dB steps. The default value is 16 dB.

The LNA and VGA gains are set to the nearest step below the desired value. So if you try to set the LNA gain to 17-23 dB, the gain will be set to 16 dB. The same applies for the VGA gain; trying to set the gain to 27 dB will result in 26 dB.

# enable/disable the built-in amplifier:
hackrf.enable_amp()
hackrf.disable_amp()

# setting the LNA or VGA gains
hackrf.lna_gain = 8
hackrf.vga_gain = 22

# can also use setters or getters
hackrf.set_lna_gain(8)
hackrf.set_vga_gain(22)

Acknowledgements

For now most of the work is based on this. That is going to change, also this notice will be removed then.

License

This project is licensed under the GPL-3 license.

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

pyhackrf-0.1.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyhackrf-0.1.0-cp39-cp39-manylinux_2_31_x86_64.whl (19.2 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.31+ x86-64

File details

Details for the file pyhackrf-0.1.0.tar.gz.

File metadata

  • Download URL: pyhackrf-0.1.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.9.1 Linux/4.15.0-140-generic

File hashes

Hashes for pyhackrf-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3702043373611b9adbfd0d2c5aacae9d13f07915e22474435c34ac8b84c024d2
MD5 514e1a87d2a6a38f70ee4b765be26faa
BLAKE2b-256 6cd73a73fb646cc06318963f334d1d91344abe35cc4b09ee59f1a42578e9c395

See more details on using hashes here.

File details

Details for the file pyhackrf-0.1.0-cp39-cp39-manylinux_2_31_x86_64.whl.

File metadata

  • Download URL: pyhackrf-0.1.0-cp39-cp39-manylinux_2_31_x86_64.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: CPython 3.9, manylinux: glibc 2.31+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.9.1 Linux/4.15.0-140-generic

File hashes

Hashes for pyhackrf-0.1.0-cp39-cp39-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 608ad3f6f0f793e2f693f2a824c5762145e32cf6c57d32628a183a2122a7c137
MD5 13e77ba432da74a0111aa5cafd65490c
BLAKE2b-256 0a0ac1cc80b633596a7b7622675017a903aec26d7e57a586387369402dfb8235

See more details on using hashes here.

Supported by

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