Skip to content

Commit

Permalink
Update hackrf install and script (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
777arc authored Nov 8, 2024
1 parent 5332385 commit d0177d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
16 changes: 4 additions & 12 deletions content/hackrf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,7 @@ Lastly, we must install the HackRF One `Python bindings <https://github.com/Gvoz
.. code-block:: bash
sudo apt install libusb-1.0-0-dev
cd ~
git clone https://github.com/GvozdevLeonid/python_hackrf.git
cd python_hackrf
export LDFLAGS="-L/usr/lib/x86_64-linux-gnu -L/usr/local/lib"
export CFLAGS="-I/usr/include/libusb-1.0 -I/usr/local/include/libhackrf"
python setup.py build_ext --inplace
pip install -e .
pip install python_hackrf==1.2.1
We can test the above install by running the following code, if there are no errors (there will also be no output) then everything should be good to go!

Expand Down Expand Up @@ -202,19 +196,17 @@ After running the code below, if in your time plot, the samples are reaching the
sdr = pyhackrf.pyhackrf_open()
allowed_baseband_filter = pyhackrf.pyhackrf_compute_baseband_filter_bw_round_down_lt(baseband_filter) # calculate the supported bandwidth relative to the desired one
allowed_lna_gain = round(max(0, min(40, lna_gain)) / 8) * 8
allowed_vga_gain = round(max(0, min(62, vga_gain)) / 2) * 2
sdr.pyhackrf_set_sample_rate(sample_rate)
sdr.pyhackrf_set_baseband_filter_bandwidth(allowed_baseband_filter)
sdr.pyhackrf_set_antenna_enable(False) # It seems this setting enables or disables power supply to the antenna port. False by default. the firmware auto-disables this after returning to IDLE mode
sdr.pyhackrf_set_freq(center_freq)
sdr.pyhackrf_set_amp_enable(False) # False by default
sdr.pyhackrf_set_lna_gain(allowed_lna_gain) # LNA gain - 0 to 40 dB in 8 dB steps
sdr.pyhackrf_set_vga_gain(allowed_vga_gain) # VGA gain - 0 to 62 dB in 2 dB steps
sdr.pyhackrf_set_lna_gain(lna_gain) # LNA gain - 0 to 40 dB in 8 dB steps
sdr.pyhackrf_set_vga_gain(vga_gain) # VGA gain - 0 to 62 dB in 2 dB steps
print(f'center_freq: {center_freq} sample_rate: {sample_rate} baseband_filter: {allowed_baseband_filter} lna_gain: {allowed_lna_gain} vga_gain: {allowed_vga_gain}')
print(f'center_freq: {center_freq} sample_rate: {sample_rate} baseband_filter: {allowed_baseband_filter}')
num_samples = int(recording_time * sample_rate)
samples = np.zeros(num_samples, dtype=np.complex64)
Expand Down
8 changes: 3 additions & 5 deletions figure-generating-scripts/hackrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,17 @@
sdr = pyhackrf.pyhackrf_open()

allowed_baseband_filter = pyhackrf.pyhackrf_compute_baseband_filter_bw_round_down_lt(baseband_filter) # calculate the supported bandwidth relative to the desired one
allowed_lna_gain = round(max(0, min(40, lna_gain)) / 8) * 8
allowed_vga_gain = round(max(0, min(62, vga_gain)) / 2) * 2

sdr.pyhackrf_set_sample_rate(sample_rate)
sdr.pyhackrf_set_baseband_filter_bandwidth(allowed_baseband_filter)
sdr.pyhackrf_set_antenna_enable(False) # It seems this setting enables or disables power supply to the antenna port. False by default. the firmware auto-disables this after returning to IDLE mode

sdr.pyhackrf_set_freq(center_freq)
sdr.pyhackrf_set_amp_enable(False) # False by default
sdr.pyhackrf_set_lna_gain(allowed_lna_gain) # LNA gain - 0 to 40 dB in 8 dB steps
sdr.pyhackrf_set_vga_gain(allowed_vga_gain) # VGA gain - 0 to 62 dB in 2 dB steps
sdr.pyhackrf_set_lna_gain(lna_gain) # LNA gain - 0 to 40 dB in 8 dB steps
sdr.pyhackrf_set_vga_gain(vga_gain) # VGA gain - 0 to 62 dB in 2 dB steps

print(f'center_freq: {center_freq} sample_rate: {sample_rate} baseband_filter: {allowed_baseband_filter} lna_gain: {allowed_lna_gain} vga_gain: {allowed_vga_gain}')
print(f'center_freq: {center_freq} sample_rate: {sample_rate} baseband_filter: {allowed_baseband_filter}')

num_samples = int(recording_time * sample_rate)
samples = np.zeros(num_samples, dtype=np.complex64)
Expand Down

0 comments on commit d0177d1

Please sign in to comment.