DesignSpark Electrical Logo
  • Brought to you by
  • RS Components
  • Allied Electronics
Andrew Back

February 2, 2015 09:27

Taking the Raspberry Pi 2 for a Test Drive with GNU Radio

title

Installing GNU Radio and receiving aircraft radar with a USB TV tuner

The Raspberry Pi has been put to countless creative uses, with it's low cost and easy to use GPIO, coupled with a passionate and inventive community, giving birth to applications that have ranged from simple fun, to inspired and even profound.

However, the single-core Raspberry Pi couldn't be everything to everyone and a common wish was for just a little more horsepower, for those applications that really need it. A great example being software-defined radio (SDR), where components usually implemented in hardware are instead implemented in software. Resulting in flexibility, but at the cost of being computationally intensive.

The Raspberry Pi 2 Model B, with it's quad-core processor and 1GB RAM, weighs in at around six times the performance of its predecessor and should far better accommodate SDR applications.

title

Installing GNU Radio

The GNU Radio SDR toolkit is a fairly substantial codebase and with some equally heavyweight dependencies. Thankfully, Raspbian packages are available — not in the current “wheezy” release , but in the “jessie” testing release. The MicroSD card that came supplied with the Pi 2 was based on wheezy, but adding a line to the Apt configuration was all that was needed to get jessie packages.

Edit /etc/apt/sources.list and add the line:

deb http://archive.raspbian.org/raspbian jessie main

Update the Apt cache:

$ sudo apt-get update

Install GNU Radio runtime and development files:

$ sudo apt-get install gnuradio gnuradio-dev

title

Setting up RTL-SDR

title

It still never ceases to amaze me what can be done with a humble USB TV tuner dongle that can be picked up for around £10 plus open source SDR software. Above can be seen the Pi 2 with such a tuner plugged in to one of the USB ports, and the supplied antenna attached. For more information on the wonder that is rtl-sdr, see the post I wrote about this back in 2012.

Since we're re-purposing a TV tuner that is supported by the Linux kernel and which would otherwise be claimed by it and for TV reception, we need to first stop the kernel from doing so.

Edit the file /etc/modprobe.d/raspi-blacklist.conf and add the line:

blacklist dvb_usb_rtl28xxu

Install the rtl-sdr software and GNU Radio support:

$ sudo apt-get install rtl-sdr gr-osmosdr

In order to access the device as a non-root user we need to set up a new udev rule, but first we need to ascertain the USB ID. Ensure that the tuner is plugged in and type:

$ lsusb

This gave me:

Bus 001 Device 004: ID 0bda:2832 Realtek Semiconductor Corp. RTL2832U DVB-T

Next we create the file /etc/udev/rules.d/20.rtlsdr.rules, with the line:

SUBSYSTEM=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2832", GROUP="adm", MODE="0666", SYMLINK+="rtl_sdr"

We could restart udev at this point, but since we also blacklisted a kernel module it's probably just easiest to reboot.

A simple test

title

To get a simple spectrum display we can run the FFT application which is provided as part of the gr-osmocom software.

$ osmocom_fft

If we then check the CPU load we can see that we have plenty of capacity to spare, with just one core at around 70% utilisation.

title

gr-air-modes

Around 2 ½ years ago I wrote about how you could use rtl-sdr hardware together with the GNU Radio-based gr-air-modes software, to receive position and heading information from aircraft Mode-S transponders. At the time I used a laptop, and did try using a Raspberry Pi Model B also, but this didn't have quite enough processing power and resulted in buffer underruns.

In order to build gr-air-modes a few additional dependencies are required.

$ sudo apt-get install cmake libboost-dev sqlite pyqt4-dev-tools liblog4cpp5-dev swig

With these installed the sources can be cloned from GitHub:

$ git clone https://github.com/bistromath/gr-air-modes.git

To then build and install:

$ cd gr-air-modes
$ mkdir build
$ cd build
$ cmake ../
$ make
$ sudo make install
$ sudo ldconfig

We can then run the application with:

$ modes_rx -s osmocom

And with only a tiny antenna and a good number of miles from the nearest airport, I still managed to get no shortage of output!

title

Not to mention, once again with plenty of headroom to spare.

title

Conclusion

The Pi 2 provides a marked improvement on the first generation hardware, with four cores instead of one and each of these being a more recent and more powerful version of the ARM architecture. A performance improvement that will be welcomed by many and not least of all those with SDR applications in mind.

See also the post on running a GSM network on the Raspberry Pi 2 with UmTRX.

Andrew Back

BUY A Pi2

Andrew Back

Open source (hardware and software!) advocate, Treasurer and Director of the Free and Open Source Silicon Foundation, organiser of Wuthering Bytes technology festival and founder of the Open Source Hardware User Group.

Comments

zqcebtmu

March 1, 2016 20:08

Great post! I was wondering if you could get SDRPlay to work with the Raspbian!

jb63

February 23, 2016 19:06

Would appreciate some help for the issue I'm having. Here is the error message I get:

pi@raspberrypi:~ $ osmocom_fft
linux; GNU C++ version 4.9.1; Boost_105500; UHD_003.007.003-0-unknown

gr-osmosdr 0.1.3 (0.1.3) gnuradio 3.7.5
built-in source types: file osmosdr fcd rtl rtl_tcp uhd miri hackrf bladerf rfspace airspy
Using device #0 Realtek RTL2838UHIDIR SN: 00000001
Found Rafael Micro R820T tuner
Exact sample rate is: 250000.000414 Hz
Using Volk machine: neon_hardfp_orc
The program 'osmocom_fft' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadMatch (invalid parameter attributes)'.
(Details: serial 2455 error_code 8 request_code 70 minor_code 0)
(Note to programmers: normally, X errors are reported asynchronously;
that is, you will receive the error a while after causing it.
To debug your program, run it with the --sync command line
option to change this behavior. You can then get a meaningful
backtrace from your debugger if you break on the gdk_x_error() function.)

namori

January 29, 2016 13:45

does somebody know if this also works with a funcube pro+ dongle?

lukbe

October 26, 2015 15:59

On my RPI2 i have this problem with raspbian wheezy and now with jassie I have this problem too. But RPI2 with ubuntu mate, I did not have this problem.

Andrew Back

October 26, 2015 13:26

@lukbe I'm not sure what to suggest here, as I've not experienced that/those problems myself. The Xlib error I would suspect to be related to either how you are logging in, e.g. local, X11 forwarding or VNC etc. else perhaps installed X or desktop software. I'd suggest exploring Raspberry Pi community resources. For the audio_alsa_source error I'd suggest searching and perhaps posting to the GNU Radio list.

lukbe

October 26, 2015 11:43

Please how to fix this error:

Xlib: extension "RANDR" missing on display ": 1.0".
gr :: log: INFO: audio source - Audio source sheet: alsa
gr :: log: ERROR: audio_alsa_source0 - [default]: No such file or directory
Traceback (most recent call last):
File "/home/pi/Desktop/pokus/top_block.py", line 59, in
tb = top_block ()
File "/home/pi/Desktop/pokus/top_block.py", line 32, in __init__
self.audio_source_0 = audio.source (samp_rate, "" True)
File "/usr/lib/python2.7/dist-packages/gnuradio/audio/audio_swig.py", line 133, in makeup
_audio_swig.source_make return (* args, ** kwargs)
RuntimeError: audio_alsa_source


thank you

rbolling

October 5, 2015 15:01

Thanks very much lukbe! osmocom_fft now displays on the LapDock perfectly. I don't have any hints about the alsa challenges you are facing but will certainly post if a have anything to help.

lukbe

October 5, 2015 09:04

@rbolling

./src/unix/glx11.cpp(442) in GetGLXVersion(): GLX version not found


I had this problem too,solutions: sudo apt-get install libgl1-mesa-swx11


I still have this problem : RuntimeError: audio_alsa_source :(

rbolling

October 4, 2015 17:40

Andrew - This is a marvelous tutorial. I've got it all working with the latest Raspbian image - Jessie version 4.1 dated 2015-09-24. All works great including ssh -X display osmocom_fft on Mac OS X. As you say, even with the included mini antenna, I get mode-S and ADS-B hits.

I notice in the thread some folks are having issues with glx. I have my pi connected to a Motorola Lapdock for display and keyboard. Although ssh -X of osmocom_fft works great on the Mac, when I run it on the Pi connected to the Lapdock's HDMI display osmocom_fft fails during startup with:

wx._core.PyAssertionError: C++ assertion "ok" failed at ../src/unix/glx11.cpp(442) in GetGLXVersion(): GLX version not found

I tried adding:

framebuffer_depth=32
framebuffer_ignore_alpha=1

just in case to /boot/config.txt but no change. Not a big deal if you don't have any hints.

Next I am going to see if I can get gqrx working as you suggested to vk2byf...

lukbe

September 29, 2015 21:37

Very nice tutorial!
I have a problem when I use the block Audio Sink, I get this error:

Xlib: extension "RANDR" missing on display ": 1.0".
gr :: log: INFO: audio source - Audio source sheet: alsa
gr :: log: ERROR: audio_alsa_source0 - [default]: No such file or directory
Traceback (most recent call last):
   File "/home/pi/Desktop/pokus/top_block.py", line 59, in
     tb = top_block ()
   File "/home/pi/Desktop/pokus/top_block.py", line 32, in __init__
     self.audio_source_0 = audio.source (samp_rate, "" True)
   File "/usr/lib/python2.7/dist-packages/gnuradio/audio/audio_swig.py", line 133, in makeup
     _audio_swig.source_make return (* args, ** kwargs)
RuntimeError: audio_alsa_source

Can you help me ?

vk2byf

September 25, 2015 02:07

Andrew, my research suggests the Pi has not the 'grunt' to run Gqrx.
even the pi2 with 4 cores is struggling.
Gqrx looks exactly like what I need but I have to learn more linux
before I can try and install it.
Thanks, Bob

Andrew Back

September 24, 2015 17:06

@bob Congratulations! :o) You might want to take a look at Gqrx.

vk2byf

September 24, 2015 00:17

IT WORKS !

I'm 15km from a military airport.
Using a homebrew QFT antenna designed for the
70cm HAM satellite band.
I'm getting messages like this

(-30 308.71750900) Type 0 (short A-A surveillance) from 595d0a at 72800ft (TCAS resolution inhibited)

Not sure what it all means. 72800ft is a little high for aircraft to fly unless there is a decimal point missing somewhere.

Thank you Andrew for making this stuff available. It was a great learning experience. Some of this stuff is actually starting to sink in by osmosis |I expect.

I'm really looking for some way to control the RTL-SDR via some kind of interface to tune the HAM satellite bands.

Any ideas where to find such a program? SDRSharp for the raspberry Pi would be nice.
Thanks again, regards bob VK2BYF

[attachment=0:76ay9uhx]Ashampoo_Snap_2015.09.24_10h12m46s_001_.png[/attachment:76ay9uhx]

vk2byf

September 23, 2015 06:15

Hi again
I see I'm not a Pioneer after all.
The X display problem has been dealt with before.
I just didn't drill down far enough into the comments.
Thanks again. Bob

vk2byf

September 23, 2015 06:03

Hi
First let me thank you for making this sort of stuff available for those of us who are NOT programmers.

I'm new here and a complete novice with Linux and Raspberry Pi
I, updated, upgraded and improved my Pi to Raspian jessie successfully.
I followed all the step very carefully making sure I made no mistakes when
editing system files using pico.

I'm talking to my Pi using SSH and Bitvise SSH Client which makes editing a lot easier.
This method looks very stable and easy to use.

I got as far as A simple test and ran $ osmocom_fft from Text i/f or command-line via SSH
a very short graphic popped up on the HDMI screen, about 250mS, too short to be sure but it
looked like the fft display. The Pi came back with the following error message.

linux, GNU C++ version 4.9.1; Boost_105500; UHD_003.007.003-0-unknown
Unable to access the X Display, is $DISPLAY set properly?

I rebooted the pi and got the same results from the pi via the pi keyboard and command line input
Also when running the command from within the GUI interface.

I did not go any further with installing GNU Radio. The pi "sees" the RTL-SDR dongle and is configured.

Thank you for taking the time to read this and off cause for any help with a solution.

Regards Bob (VK2BYF)

Andrew Back

September 2, 2015 10:27

@rob jones thanks for spotting that! Fixed the typo and updated the dependencies — it's all too easy to miss something off, but was pretty sure I'd gone through this a second time with a fresh card.

clementarnardi

September 1, 2015 21:46

clementarnardi wrote:
> Hello all, thank you for tutorial but I'm trying to install GNU Radio+Hackrf support+Osmocom
> since 2 days on Rpi 2 and it looks like a fight, there is always something wrong..
> For now I have Gnuradio+osmo but when i hackrf_info i've got :
>
> hackrf_info: symbol lookup error: hackrf_info: undefined symbol: hackrf_device_list
>
> Is there someone who successed to do that?
> If yes would it be possible to create an img of your SD card and upload it ?
> I tried on Ubuntu mate and now i'm on Raspbian
> Thx
Solved, if u are interrested by an img of my sdr with osmocom+grc+hackrf, mail me, I'll try to upload it for you
Keep Hacking,
Clement
clement.arnardi@isen.fr

clementarnardi

August 29, 2015 11:09

Hello all, thank you for tutorial but I'm trying to install GNU Radio+Hackrf support+Osmocom since 2 days on Rpi 2 and it looks like a fight, there is always something wrong..
For now I have Gnuradio+osmo but when i hackrf_info i've got :

hackrf_info: symbol lookup error: hackrf_info: undefined symbol: hackrf_device_list

Is there someone who successed to do that?
If yes would it be possible to create an img of your SD card and upload it ?
I tried on Ubuntu mate and now i'm on Raspbian
Thx

Rob Jones

August 26, 2015 22:16

Minor issue - the command should be 'lsusb' - you have 'lusb'

Bigger issue - 'cmake' is not installed in a NOOBS Raspberry Pi setup - the solution is:

sudo apt-get install libboost-dev cmake

Great tutorial - amazing software - but so many moving parts... thanks for guiding us through it all

lightdesign84

July 19, 2015 20:15

The solution to the X Window System error is to add the following to /boot/config.txt

framebuffer_depth=32
framebuffer_ignore_alpha=1

lightdesign84

July 2, 2015 00:50

I followed the instructions on my Raspberry Pi 2 with a fresh install of Raspian. When I type osmocom_fft into the terminal, I see the GUI for a split second before it crashes and I get the below message. Anybody know what's wrong and how to fix it?

linux; GNU C++ version 4.9.1; Boost_105500; UHD_003.007.003-0-unknown

gr-osmosdr 0.1.3 (0.1.3) gnuradio 3.7.5
built-in source types: file osmosdr fcd rtl rtl_tcp uhd miri hackrf bladerf rfspace airspy
Using device #0 Realtek RTL2838UHIDIR SN: 00000001
Found Rafael Micro R820T tuner
Exact sample rate is: 250000.000414 Hz
Using Volk machine: neon_hardfp_orc
The program 'osmocom_fft' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadMatch (invalid parameter attributes)'.
(Details: serial 1833 error_code 8 request_code 70 minor_code 0)
(Note to programmers: normally, X errors are reported asynchronously;
that is, you will receive the error a while after causing it.
To debug your program, run it with the --sync command line
option to change this behavior. You can then get a meaningful
backtrace from your debugger if you break on the gdk_x_error() function.)

w7ki

June 13, 2015 15:59

Thanks for the great write-up ! I ran into the same thing as brendanm and I made sure the sample rate parameter was correct:

linux; GNU C++ version 4.9.1; Boost_105500; UHD_003.007.003-0-unknown

gr-osmosdr 0.1.3 (0.1.3) gnuradio 3.7.5
built-in source types: file osmosdr fcd rtl rtl_tcp uhd miri hackrf bladerf rfspace airspy
Using device #0 Realtek RTL2838UHIDIR SN: 00000001
Found Rafael Micro R820T tuner
Exact sample rate is: 2000000.052982 Hz
Gain is 33
Rate is 2000000
Using Volk machine: neon_hardfp_orc
python2: /usr/include/boost/smart_ptr/intrusive_ptr.hpp:162: T* boost::intrusive_ptr::operator->() const [with T = pmt::pmt_base]: Assertion `px != 0' failed.

If anyone has advice on the cause of this error or a workaround it would be greatly appreciated !

- Rich

zanco

June 10, 2015 15:35

Hi Andrew,

thanks for your Blog. I did not know about the osmocom_fft and I have to say that it's a great tool for signal observation. With the Average and the Peak Hold selected it's a nice way to see on what frequencies there have been transmissions.

Now, I am going to make the image for the Pi 2 and try the same program on that one.

Kind regards,

Ben

zanco

June 10, 2015 11:46

Brendan :

The R820T dongles only work up to 3.2 MS samplerate max !

The preferred value is 2MS. So, your first problem is shown in your message"

Invalid sample rate: 4000000 Hz

Try again with 2000000 as samplerate, perhaps that solves the problem. I can not reply to you directly, but if you have questions you can email me at

pe2bz (at) pe2bz (dot) nl.

Good luck !

brendanm

May 4, 2015 10:36

Not sure what I'm doing wrong, but all I get is:

linux; GNU C++ version 4.9.1; Boost_105500; UHD_003.007.003-0-unknown

gr-osmosdr 0.1.3 (0.1.3) gnuradio 3.7.5
built-in source types: file osmosdr fcd rtl rtl_tcp uhd miri hackrf bladerf rfspace airspy
Using device #0 Realtek RTL2838UHIDIR SN: 00000001
Found Rafael Micro R820T tuner
Invalid sample rate: 4000000 Hz
Gain is 33
Rate is 4000000
Using Volk machine: neon_hardfp_orc
python2: /usr/include/boost/smart_ptr/intrusive_ptr.hpp:162: T* boost::intrusive_ptr::operator->() const [with T = pmt::pmt_base]: Assertion `px != 0' failed.
Aborted

The error happens after an arbitrary length of time -- typically more than a couple minutes, but usually less than 15. My -guess- is that it's happening during processing of the first received message, but the error message isn't terribly helpful.

Any hints as to what I need to look at to get this going?

Brendan

Andrew Back

April 23, 2015 12:13

Hi Peter,

Well, as I think you know there are performance issues with the GNU Radio GUI applications built on WX, and I get frozen controls when I run these up on the Novena also. However, I do wonder whether, in addition to which there are some specific performance issues with GNU Radio on ARM (and which cannot be explained by simply the relatively limited resources compared with, say, an Intel/AMD desktop class machine).

Regards,

Andrew

pebol

March 3, 2015 21:11

Thanks for this how-to. Both osmocom_fft and gr-air-modes work fine. A small grc test circuit consisting of an Audio Source, a Audio Sink, a FFT Sink and a slider to control the frequency also does what it should.

With a similar circuit consisting of a RTL SDR Source, a FFT Sink and a slider the slider is shown but can't be moved. I also can't type in the frequency and none of the FFT sink's buttons can be pressed. If I minimize the top block window and resize it afterwards the slider and all the buttons are gone. CPU load is approx. 35 %, 300 MB RAM is used.

A RTL SDR based WBFM receiver works, again with inactive buttons and sliders.

What could be wrong?

Peter

fotografAle

February 25, 2015 08:22

That's very interesting!
And please, does anyone has already tested the behaviour of the GPIO4 pin, with the new Raspberry Pi 2 version?
I'm a supporter of the following ham radio applications.
http://youtu.be/-ONIrqeE63Y

Andrew Back

February 18, 2015 11:04

@pirat3uk GPIO connection not required — I just prefer to use a serial console with such boards, rather than a keyboard, mouse and monitor. Of course, most of the time you don't need either, provided you can ascertain the DHCP address and SSH in.

pirat3uk

February 18, 2015 09:35

really interested by all this since having play using an old laptop a while ago, cant seem to find any reference to the GPIO connection in the picture? (what is it?)
Thanks

ptamike

February 17, 2015 17:12

Apologies - brain and mouth not in gear today!

Adding the following to /boot/config.txt is the fix for the X-Windows Badmatch problem. Thanks to G0UKB :-)

framebuffer_depth=32
framebuffer_ignore_alpha=1

ptamike

February 17, 2015 16:09

Has anyone cracked the X-Windows Badmatch problem yet?

g0ukb

February 13, 2015 10:19

FIXED! Needed to add :

framebuffer_depth=32
framebuffer_ignore_alpha=1

to /boot/config.txt

g0ukb

February 12, 2015 21:07

Well, doing a full release upgrade to jessie hasn't solved the X Badmatch. On the plus side everything else is working and getting plenty of output from gr-air-modes. For anyone else going down this route I had a pretty vanilla wheezy Raspian to start with and the only things I needed to do were to add cmake and libboost-dev to the list of dependencies to build gr-air-modes.

g0ukb

February 12, 2015 18:10

Great instructions - alas for me osmocom-fft is failing with an X-Windows Badmatch error. The FFT screen appears briefly so looks like all is OK with the RTL_SDR setup.

More stuff to go investigate - thanks for the instructions and hopefully when I crack this I'll be up and running.

Andrew Back

February 2, 2015 20:23

Thanks, Peter!

Frequency range depends on which particular tuner IC your dongle uses. The rtl-sdr wiki lists a few:

http://sdr.osmocom.org/trac/wiki/rtl-sdr

It's also possible to bypass the tuner (hardware mod) and run the RTL2832U IC in direct sampling mode, so that you can receive HF. However, I gather you really need to apply ESD protection and filtering. All doable given a bit of time and patience.

peterjfrancis

February 2, 2015 15:24

Great Post Andrew !
Can't wait to get a Raspberry Pi 2 setup in my new 'Man Cave' when it is completed

What is the lowest practical frequency the USB TV dongle will receive ?

siddly

February 2, 2015 13:19

Another application is ghpsdr3-alex at napan.ca/ghpsdr3/index.php/Main_Page. Building is quite involved but the wiki steps if followed bullet by bullet anyone can build it.
It supports many SDR's including RTL-SDR and can be made accessible on the internet to its QtRadio application running on a PC or ARM board or glSDR from Google Play store running on an Android phone or tablet.

I had a dongle up on the internet for a number of weeks with a 2m/70cms co-linear antenna above the roof.

I built an HF upconvertor to allow it to receive the HF bands, but have not yet got around to testing HF - too many other more urgent SDR projects on the go.