Thursday, August 8, 2024

RTL-SDR Radio Setup With GNURadio Companion

 

These little USB Stick based “Software Defined Radio” (SDR) receivers are ubiquitous and most are based on the Rafael Micro RT82xx receiver chips. They make excellent little SDR Radios that can operate from around 24 MHz to 1.7 GHz. Certain versions can operate down to around 500 kHz or you can use an upconverter, like the “Ham It Up”, or “SpyVerter” [1] to get Medium Wave and Shortwave reception.

There are two major GNURadio source blocks for these chips available. The first is the OsmoSDR: RTL-SDR Source, the second is the Soapy: Soapy RTLSDR Source (figure 1).

Figure 1 - There are two common ways to use a RTL-SDR radio in GNURadio Companion. The Osmo Source Block and the Soapy Source Block.

If you read the GNURadio documentation, you will see that the developers really gush about the Soapy Interface from a programming perspective. That may be fine, but I have found that the Soapy interface is really spotty whether it works properly with all versions of GNURadio Companion and all Windows installation methods (Radioconda [2] or Pothosware [3]).

My personal experience is that I have never had any issue with the Osmocom interface working on any version or Windows install of GNURadio, therefore my advice is to use the Osmocom interface for the simple reason that it always works (your mileage may, of course, vary).

 

Osmocom RTL-SDR Block

The Soapy Block is less generic than the Osmo RTL-SDR Block, meaning it only shows the actually relevant radio parameters, whereas the Osmo block has a superset of all possible parameters, some of which are not really used for the RT82xx receiver sticks.

As shown in Figure 2, the useful parameters for an RT82xx receiver chip are highlighted. The rest of the parameters do nothing for these RT82xx based radios.

Figure 2 - Osmo block parameters that are useful for a RT82xx chip based SDR are highlighted in yellow above. The other parameters have no effect with a RT82xx based SDR.


Overview Of Osmocom Block Parameters

ID - You can set the ID to any name that you wish.

Output Type - Naturally, the driver will let you select any output type as this is GNURadio specific and not related to any SDR Radio type.

Device Arguments - The most useful device argument is to set the serial number of the device you wist to connect to. For instance, to connect to radio serial number “00000002”, you would specify: “rtl=00000002”. See your SDR radio documentation for information on how to set a specific serial number. If not used, leave this as an empty string. See the Osmo block documentation for a listing of all the possible Device Arguments.

Sample rate - The sample rate may be set to any value in the range of,

    225001 to 300000 sps and,

    900001 to 3200000 sps

Usual rates are 1,200,000 or 2,400,000 (1.2 to 2.4 MSPS) as these easily decimate to the standard 48 kHz audio rates and will work with lower performance PC’s

Sometimes, to get a proper sampling of specific BAUD rates on digital signals, it is convenient to sample on an exact multiple of the BAUD rate. If you pick a sampling rate, that cannot be achieved accurately, the console window will display something like,

Exact sample rate is: 2000000.052982 Hz

Note: For most USB 2 connections, 2.4 MSPS is the maximum rate without dropping samples. If signal visualization is the priority and not decoding, you have the option to use sample rates up to 3.2 MSPS. You will just have to experiment with your specific hardware to see what the maximum sampling rate is without dropping samples.

Note: You may use “Python Number Notation” to specify the Sample Rate, such as,

2_400_000 (specifies 2.4 MSPS)

2.4e6 (specifies 2.4 MSPS)

2400000 (Specifies 2.4 MSPS)

Note: If you specify a sampling rate that is invalid, the dialog window will display a warning like this,

Invalid sample rate: 3300000 Hz

BUT the flowgraph will still run, so be careful, as this can be very, very hard to debug unless you notice that the sampling rate is off.

Ch0: Frequency - This is the RF tuner frequency as specified in Hz. For the extended range RTL-SDR’s any frequency in the range of: 0 to 1.766 GHz may be specified.

Note: Even though you can specify a frequency below 500 kHz most extended range RTL-SDR’s won’t actually tune below that limit. Check your specific devices data sheet.

Note: If you try to set an invalid frequency, the console window may display something like this,

[R82XX] No valid PLL values for 1770256344 Hz!

r82xx_set_freq: failed=-1

Ch0: Frequency Correction - Every radio has some master Oscillator, and that Oscillator has some base error. For instance the 26 MHz Oscillator in RTL-SDR devices may be very temperature stable, but it will have some slight absolute error. Usually this error is less than 5 to 10 parts-per-million or PPM. You may enter the PPM error here as either a positive or negative error.

Note: If you think your RTL-SDR stick is has a greater error than 10 ppm, you might have measured the error incorrectly. There are many tutorials on the internet on how to determine the PPM error accurately.

Ch0: Gain Mode - The Gain Mode can be set to “Manual” or “Automatic” (a boolean: 0, 1 or True, False). Automatic means use the RT82xx chips built in Automatic Gain Control Circuit (AGC). Manual means don’t use AGC. In my experience, the AGC works well for wideband signals like FM Broadcast, but is too cautious for the mostly narrowband signals that we like to demodulate with GNURadio. My suggestion is to start with Manual mode and try Automatic after the flowgraph is working to see if that makes things better.

Ch0: RF Gain - When in Automatic Gain Mode, this field does nothing, as the AGC circuitry sets the RF Gain for you.

When in Manual Gain Mode this value many be set between 0 and 49.6 dB. Values greater than 49.6 will just be clipped at 49.6 dB. There are discrete steps built into the RT82xx chips and the driver will select the closest value to what you put in this field. When I am developing a new flowgraph, I either put this on a QT Slider or just set the gain to 50 dB just to start with as I want to hear something, even if it is distorted rather than guessing why I don’t hear anything.

Possible RT82xx chip discrete gains: 0.0, 0.9, 1.4, 2.7, 3.7, 7.7, 8.7, 12.5, 14.4, 15.7, 16.6, 19.7, 20.7, 22.9, 25.4, 28.0, 29.7, 32.8, 33.8, 36.4, 37.2, 38.6, 40.2, 42.1, 43.4, 43.9, 44.5, 48.0, 49.6 dB

Note: The RF Gain Control is physically located in the Tuner Chip. If you have a RT82xx device that specifies low frequency operation via "Direct Sampling" it will not have any means of gain control and this field will do nothing while direct sampling frequencies below 24 MHz. Direct Sampling bypasses the tuner chip. The exception is the RTL-SDR Blog V4 [4] which includes a physical upconverter in it.


Non-Highlighted Fields

The rest of the fileds in the Overview Of Osmocom RTL-SDR Block do not do anything with a basic RT82xx based SDR.

 

Console Window

It is wise to keep an eye on the Console Window when developing a new flowgraph as some useful error messages may be displayed as described above.

There are also annoying messages that may be ignored, such as the infamous “not locked” message,

[R82XX] PLL not locked!

This is the result of a well know driver bug and is not helpful at all. Since it has been here for as long as there have been RT82xx based SDR’s it appears it will never be fixed. You can safely ignore this.

If your radio isn’t plugged in, or can’t be found, you will get a cryptic message like this,

gr-osmosdr 0.2.0.0 (0.2.0) gnuradio 3.10.10.0

built-in source types: file rtl rtl_tcp uhd miri hackrf bladerf airspy airspyhf soapy redpitaya

Traceback (most recent call last):

File “C:\Users\steve\Documents\GNU_Radio_Projects\Cookbook\RTL_SDR_SETUP\Setup_Play_Around.py”, line 178, in <module>

main()

File “C:\Users\steve\Documents\GNU_Radio_Projects\Cookbook\RTL_SDR_SETUP\Setup_Play_Around.py”, line 156, in main

tb = top_block_cls()

^^^^^^^^^^^^^^^

File “C:\Users\steve\Documents\GNU_Radio_Projects\Cookbook\RTL_SDR_SETUP\Setup_Play_Around.py”, line 69, in __init__

self.rtlsdr_source_0 = osmosdr.source(

^^^^^^^^^^^^^^^

RuntimeError: Wrong rtlsdr device index given.

>>> Done (return code 1)

Sometimes you will get some fatal error, but the flowgraph will still run. One such case is the Sampling Rate error as mentioned above. This type of error is very hard to diagnose as your signals won’t be where you think that should be, so it is a good idea to keep an eye on the console window when working with flowgraphs. 


References:

[1] There are many little upconveters on the market that take signals in the range of 0.5 to 60 or so MHz and upconvert them to 120 or 125 MHz. The two most popular are the "Ham It Up" and the "SpyVerter". An internet search will lead you to them.

[2] Radioconda - https://github.com/ryanvolz/radioconda/

[3] Pothos - https://pothosware.com/

[4] RTL-SDR Blog V4, includes an upconverter in it. - https://www.rtl-sdr.com/tag/rtl-sdr-blog-v4/

No comments:

Post a Comment