Friday 17 April 2015

Raspberry Pi Software Defined Radio

OK, so I failed in my attempt to get the GQRX Software Defined Radio (SDR) to work on my Raspberry Pi.

But I've now come up with a simpler arrangement using rtl_fm that does work.

By using rtl_fm and some simple lines of code, I now have a Pi SDR with preset stations and the ability to fine tune.

In an earlier post I described how to create an SDR using a cheap TV dongle on a Debian based Linux machine.

I was not able to get this working on my Pi-2 as there was a pulse-audio error. It looks like gqrx v2.3.1 was compiled to use pulse-audio, so it would probably need to be compiled from source to use Alsa (I'm not that keen!).

But playing around with rtl_fm I found I could get it to work on the Pi just using a terminal command like this:-

rtl_fm -f 100900000 -M wbfm -s 200000 -r 48000 - | aplay -r 48000 -f S16_LE

...which gave me ClassicFM at 100.9MHz.

The Pi-2 seemed well behaved, with "top" reporting 10-15%cpu useage.

Gambas SDR application

So I thought I'd make a simple SDR application using Gambas. You could use almost any language for this, including Python. This is a pretty trivial programming task, as I just need to run a command with appropriate parameters, and make sure I kill the task when changing stations.

The idea is that I can selected from a number of preset stations via radio buttons (no, they really are called radio buttons!). The frequencies for each station can either be hard coded, or stored in a settings/config file.

The "fine tuning" buttons change the frequency in 10kHz steps, and the final frequency can be saved back to the settings file.

I can also select "manual" then enter a frequency, select a modulation mode, and then Go to the channel.

So at the heart of the code I have this:-

Public Function PlayStation() As Boolean
Dim strCommand As String

  strCommand = "rtl_fm" & " -f " & strFrequency & "e6" & " -M " & strModulation & " -s " & strSampleRate
  strCommand = strCommand & " -r " & strSampleAudio & " - | aplay -r " & strSampleAudio & " -f " & strAudioFormat
  hPlay = Shell strCommand

...and when I click on a radio button to change stations, I do something like this:-

Public Sub rbGatwick_Click()

  fraManual.Enabled = False
  strFrequency = "124.225"
  strModulation = "am"
  lblFreq.Text = strFrequency & "MHz"


...which kills the rtl_fm process, resets the parameters as required, and then starts it again.

The fine tuning buttons do this:-

Public Sub btnPlusF2_Click()
Dim fFreq As Float

  fFreq = CFloat(strFrequency) + 0.01
  strFrequency = CStr(fFreq)
  lblFreq.Text = strFrequency & "MHz"


It couldn't be simpler!

No comments:

Post a Comment