Software Defined Radio for Raspberry Pi 3B+ (Part 2)

The Raspberry Pi is a versatile radio receiver when used with the RTL-SDR receiver.

Recapping Part 1

Welcome to Part 2 of our guide for setting up the Raspberry Pi 3B+ for Software Defined Radio (SDR).

When we left off in Part 1, we had just successfully booted the Raspbian Buster operating system on the Raspberry Pi 3B+.  We did not yet use the radio receiver: the RTL-SDR dongle.  But by now, I’m assuming you already have a microSD card running the appropriate version of the Raspbian Operating system, and that your own Raspberry Pi will boot successfully to the graphical desktop.

A picture containing indoor, wall, sign

Description automatically generated
Figure 2: Our Setup from Part 1

Objective

Here in part 2, we will:

  1. Configure the Raspberry Pi so we can get the most out of it and its peripherals
  2. Update the system to get the latest software packages
  3. Install dependencies (prerequisite software) for running rtl-sdr
  4. Install the rtl-sdr application from source.  This is the suite of applications that will receive radio broadcasts from the RTL-SDR dongle and then pipe the audio out to the amplified speakers

If you are new to Linux operating systems, note that the text-only console environment is case-sensitive. So be prepared to copy text commands verbatim, and double-check your use of uppercase and lowercase.

When it’s all said and done, we will have a functioning SDR that can tune into wideband frequency modulation (FM or WBFM) broadcasts.

Configuring Raspbian

The first thing we need to do is configure the Raspbian operating system.  Most of the settings we deal with can be adjusted later if needed, but its best to get them right the first time and set the stage for an easy setup experience.

If you plan to connect your Raspberry Pi to the Ethernet with a wired cable to your router, you should do so now.

Go ahead and power on the Raspberry Pi if you haven’t already.

A close up of a piece of paper

Description automatically generated
Figure 3: Raspbian’s Boot Screen

Set Country

Here, you should configure your time zone, language, and your preferred keyboard type.

A screenshot of a cell phone

Description automatically generated
Figure 4: Country and Time Localization Settings

If you are used to the American style keyboard (which lacks the £ symbol), then this is something you don’t want to answer incorrectly.  You need the correct keyboard setting to use the text-only console in future steps.

Change Password

Here, you need to create and confirm a strong and memorable password.  This is something you don’t want to forget.

Set Up Screen

Here is where your situation may be very different from mine.  In my build, I am using a Newhaven Display International HDMI display with an 800 x 480-pixel resolution.  Raspbian did not detect this automatically, and until I configure it in a later step, the right-hand side of my display will be undrawn.

A screenshot of a cell phone

Description automatically generated
Figure 5: Set Up Screen.

Normally, I would follow instructions and fix this by checking the “This screen shows a black border…” option.  But my monitor came with some special setup instructions from the manufacturer’s website that I will have to configure later in the console.

Select Wi-Fi Network

If you aren’t using a wired Ethernet connection, then select your Wireless network.  Then prepare to enter your login credentials for the wireless network.  I should note that having metal in the proximity of the Raspberry Pi may hurt your reception, so take this into consideration.

A screenshot of a cell phone

Description automatically generated
Figure 6: The Wireless Setup Screen will List all of the Wi-Fi Networks in Range

Update Software

Within a minute or so, your Raspberry Pi should have access to your wireless network and the internet.

Next, Raspbian will offer to automatically update its software packages and language support.

A screenshot of a cell phone

Description automatically generated
Figure 7: Raspbian Update Imminent

This updating step can be a lengthy process.  I would allocate around 30 minutes to this in your schedule.  So it may be a good time to take a short break, move around a bit or otherwise let the system run its course.

Reboot

When the system completes its updates, you should be able to reboot.  You can do this by clicking the raspberry icon in the top-left corner of the desktop. Then navigate to the very bottom of the menu, and tap or click: Shutdown –> Shutdown.

Reboot the Raspberry Pi 3B+.

Raspi Configuration

After the system reboots and the desktop is restored, click the Console icon near the top of the desktop as shown in the figure below.

A close up of a cage

Description automatically generated
Figure 8: Important Icons (Left to Right): Web Browser, File Manager, Console

While the console opens, start the Rasbpian configuration tool by typing the following into the console:

sudo raspi-config

This should open the configuration tool.

A screenshot of a cell phone

Description automatically generated
Figure 9: Raspi-Config Application

Use the arrow keys to navigate this application in the following steps…

Expand the File System

To get the most out of the microSD card, expand the file system.  Navigate to Advanced Options –> Expand File System.  This change will take effect after the next reboot.

Set Audio Output

Next, navigate to: Advanced Options –> Audio

This is where you should select the appropriate audio output method for your setup.  In my case, I want all of my audio directed to the 3.5 mm stereo audio jack, but Raspbian has the option to send audio over HDMI if that suits you.

You can change this setting later if needed, so select your preference accordingly.

Video Configuration

Finally, there’s the issue of my screen resolution.  By default, Raspbian selected a 640 x 480 format for me.  This was intended for a screen with a different aspect ratio.

Navigate to: Advanced Options –> Resolution

For me, there was no option to use 800 x 480.  This is fine for now because I can add a special configuration for my display in a later step.  So for now, I will not make changes here.  If you see an option that works better for your display, you may want to select it here and now.    

Reboot

Return to the raspi-config main menu, and then select “Finish” and select “Yes” under “Reboot Now?”

Let the Pi reboot again.

Special Video Configuration

Let the system boot back to the desktop.  If your display looks okay, you can skip this step and proceed to the Audio Test section below.

As I mentioned, I am using the Newhaven Display NHD-7.0-HDMI-N-RTXL-CTU and I want to expand the desktop to use the entire width and height of this display.  The official user guide says I need to open a boot configuration file and make some adjustments.

Open the console, and then enter:

sudo nano /boot/config.txt

This will open a text editor called nano.  If you’re not familiar with Linux or Nano, I will warn you right now not to use CTRL+C, CTRL+X, or CTRL+V for copying, cutting, or pasting in this environment. Those key combinations will have other results.  Instead, cut and paste by right-clicking to bring up the menu.

A screenshot of a cell phone

Description automatically generated
Figure 10: /boot/config.txt as it Appears in the GNU Nano Editor

Within this file, I need to add the following lines of text:

hdmi_group=2

hdmi_mode=87

hdmi_cvt=800 480 60 6 0 0 0

I have chosen to enter this directly below the line that says “#hdmi_mode=1.”

A screenshot of a cell phone

Description automatically generated
Figure 11: Configuration File After Modification

When you are done, save your changes by pressing CTRL+O.  Then press CTRL+X to exit GNU Nano.

Reboot again, and the desktop should now span the entire display.  Nice!

A close up of a computer

Description automatically generated
Figure 12: Raspbian Buster’s Desktop after Complete Video Configuration

Test the Audio

Now is a good time to make certain the audio is working.  Plug in your amplified speakers or turn up the volume on your HDMI device if it supports audio (depending on your audio preference from the previous steps).

The audio levels out of the 3.5 mm stereo port are intended for amplification and will not drive speakers or earbuds to useful levels of loudness.  So instead, I am using a pair of PC speakers with a power supply and an audio amplifier built-in.

If you have installed the full version of Raspbian, then you should have no trouble accessing the web by clicking the blue globe icon on the top toolbar.  This will open the Chromium browser, which you can use to test the audio.

A screenshot of a computer

Description automatically generated
Figure 13: Using the Chromium Web Browser

Installing Dependencies

Now its time to start installing the applications to run the RTL-SDR dongle.  Speaking of which, if you haven’t already plugged in your RTL-SDR receiver, shut down Raspbian and plug it in.  Note that if your 5-volt supply to the Raspberry Pi 3B+ is under-sized, the Raspberry Pi may reboot suddenly when you plug in the RTL-SDR, which is why I shut it off first.

A desk with a monitor keyboard and mouse

Description automatically generated
Figure 14: Raspberry Pi 3B+ with Attached RTL-SDR

When the desktop launches again, open the console.

To be 100 % sure the update we did in earlier steps completed, do another round of updates with the following commands:

sudo apt-get update

sudo apt-get upgrade

A screenshot of a cell phone

Description automatically generated
Figure 15: Raspbian OS Updates

Next, use GNU nano again to create a file called no-rtl.conf

sudo nano /etc/modprobe.d/no-rtl.conf

Using the GNU Nano editor, add the following lines of text to the no-rtl.conf file…

blacklist dvb_usb_rtl28xxu

blacklist rtl2832

blacklist rtl2830

Now save it by pressing CTRL+O.  Then exit the GNU Nano editor by pressing CTRL+X.

Reboot

Now reboot the system.

Install Dependencies

Now it’s time to install the software dependencies for rtl-sdr.  Reopen the console and perform the following installations.

sudo apt-get install git-core

sudo apt-get install git

sudo apt-get install cmake

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

sudo apt-get install build-essential

Now, copy the latest version of the rtl-sdr code from the Git repository:

git clone git://git.osmocom.org/rtl-sdr.git

cd rtl-sdr/

mkdir build

cd build

cmake ../ -DINSTALL_UDEV_RULES=ON

make

sudo make install

sudo ldconfig

cd ~

sudo cp ./rtl-sdr/rtl-sdr.rules /etc/udev/rules.d

sudo mv no-rtl.conf /etc/modprobe.d

Reboot

Reboot the system one last time. 

Test and Use the RTL-SDR with Audio

When the desktop boots again, return to the console and enter the following…

rtl_test

This should yield something resembling the following…

A screenshot of a cell phone

Description automatically generated
Figure 16: Executing rtl_test

Congratulations!  You should now have a working RTL-SDR receiver. 

Let’s take things one step further by piping a little audio to the speakers/display.  Press CTRL+C to terminate the rtl_test application. 

Then enter the line below into the console.  The number “101500000” in this line should correspond to the frequency (in Hz) that you wish to receive.  In my case, 101.5 MHz is the center frequency for a local, powerful WBFM station in my listening area.  But your situation may be different…

rtl_fm -M wbfm -f 101500000 | aplay -r 32000 -f S16_LE -c 1

Entering this yields not only the following screen, but also plays the demodulated audio from the amplified speakers…

A screenshot of a computer screen

Description automatically generated
Figure 17: The rtl_fm Application Successfully Generating Audio

Coming Up in Part 3…

Congratulations on making it this far, and we hope you found this helpful.  If you have feedback, feel free to reach us via our contact page, as we welcome constructive criticism.

Luckily, the hardest parts are now behind us.  In the next part, we will install the graphical SDR program: GQRX.

A close up of a computer

Description automatically generated
Figure 18: Part 3 Objective

References

[1] B. R. Mayes, “Software Defined Radio for Raspberry Pi 3B+ (Part 1),” 24 Nov. 2019. [Online]. Available: https://unboxing-tomorrow.com/software-defined-radio-for-raspberry-pi-3b-part-1/. [Accessed 1 Dec. 2019].
[2] Raspberry Pi Foundation, “Audio configuration,” Raspberry Pi Foundation, [Online]. Available: https://www.raspberrypi.org/documentation/configuration/audio-config.md. [Accessed 25 Nov. 2019].
[3] Newhaven Display International, “7.0” HDMI TFT Modules,” 2018. [Online]. Available: http://www.newhavendisplay.com/userguides/NHD-7.0-HDMI-N_User_Guide.pdf. [Accessed 30 Nov 2019].
[4] floehopper, “Install rtl-sdr on Raspian on Raspberry Pi,” GitHub Gist, [Online]. Available: https://gist.github.com/floehopper/99a0c8931f9d779b0998. [Accessed 1 Dec 2019].
[5] “Stack Exchange | File Manager instantly closes when opened,” Stack Exchange, 24 Dec. 2018. [Online]. Available: https://raspberrypi.stackexchange.com/questions/92213/file-manager-instantly-closes-when-opened. [Accessed 26 Nov. 2019].

Important Notice: This article and its contents (the “Information”) belong to Unboxing-tomorrow.com and Voxidyne Media LLC. No license is granted for the use of it other than for information purposes. No license of any intellectual property rights is granted.  The Information is subject to change without notice. The Information supplied is believed to be accurate, but Voxidyne Media LLC assumes no responsibility for its accuracy or completeness, any error in or omission from it or for any use made of it.  Liability for loss or damage resulting from any reliance on the Information or use of it (including liability resulting from negligence or where Voxidyne Media LLC was aware of the possibility of such loss or damage arising) is excluded.