Monday, November 13, 2017

Software Defined Radios With a Macbook Pro

I finally succumbed to the temptation and bought a couple of RTL SDR dongles.  These thingies are so cheap, they really open the art of amateur radio to the masses again.

CubicSDR on a Macbook Pro

These gadgets are wide band digital receivers, which make them much fun.  Effectively, RTL-SDR with CubicSDR provides you with a wide band DIY Spectrum Analyzer that works from about 1 MHz all the way up to about 3 GHz.

Read all about RTL-SDR here:

If you have no idea what to do with SDR toys, go here:

or here:

or, of course here:

BTW, if you use Linux or BSD, skip to the bottom of the page.

Where to Buy an SDR Widget

Get your own RTL-SDR kit for the enormous sum of $26 here:

For a proper transceiver, you can get the HackRF wotzit at Sparkfun, but it costs a rather more hefty amount - about 10x more:

Receiver Software

On my Macbook Pro, the CubicSDR program works like magic.  I can sincerely recommend using it:

There are a few things I would like to do with these SDR thingies:
  • Hook to my BitX40 radio to verify the HF performance at 7 MHz, 
  • Listen to ATC aircraft band radio at 118 to 136 MHz and 
  • Decode ADSB from ATC transponders at 1090 MHz.
  • Decode GPS at 1575.42 MHz
The receiver is wide band so things fold back, which makes it a bit confusing, but even the simplest antenna will pull in many FM stations.  I would recommend using a tuned antenna for HF listening though.

AM and FM Radio

So far I managed to tick off the BitX40 (and Abu Dhabi Classic!) with CubicSDR.  This should also work with the ATC voice radio band, I just haven't gotten round to trying it yet.

Get rtl-sdr With Macports

The CubicSDR program can do everything I want with this widget, but the command line utilities mentioned above can also be very handy, especially when you want to log data for later analysis. 

The rtl-sdr package provides the following command line utilities:
  • rtl_adsb: a simple ADS-B decoder
  • rtl_eeprom: an EEPROM programming tool
  • rtl_fm: a narrow band FM demodulator
  • rtl_sdr: an I/Q recorder
  • rtl_tcp: an I/Q spectrum server
  • rtl_test: a benchmark tool
  • rtl_power: a spectrum analyzer
So, I used Macports and updated it, since I already have it installed:

$ sudo port -v selfupdate
sudo: port: command not found


Why is everything so clunky on my Mac?  I can add /opt/local/bin to the path, but that is also a security concern.

Let's try again, this time with the full path to the utility:
$ sudo /opt/local/bin/port -v selfupdate

and this time it worked.

Try to install the rtl-sdr package:
$ sudo /opt/local/bin/port install rtl-sdr
Error: The installed version of Xcode (7.3) is too old to use on the installed OS version. Version 8.2.1 or later is recommended on Mac OS X 10.13.

Bah, humbug...

Open the App Store, search for xcode and Get it all over again, which of course takes foreeever (TM)...  So I clicked the Caffeine coffee cup to keep the Mac from going to sleep and let it upgrade overnight.

Then try to install the rtl-sdr package again:
$ sudo /opt/local/bin/port install rtl-sdr
--->  Computing dependencies for rtl-sdr
The following dependencies will be installed:
Continue? [Y/n]: y

Fetching - installing... getting somewhere now!

What hath god wrought?
$ ls /opt/local/bin/rtl*
/opt/local/bin/rtl_adsb        /opt/local/bin/rtl_power    /opt/local/bin/rtl_test
/opt/local/bin/rtl_eeprom    /opt/local/bin/rtl_sdr
/opt/local/bin/rtl_fm        /opt/local/bin/rtl_tcp

OK, let's test it.

Plug the widget in and:
$ /opt/local/bin/rtl_test
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001

Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
Supported gain values (29): 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
[R82XX] PLL not locked!
Sampling at 2048000 S/s.

Info: This tool will continuously read from the device, and report if
samples get lost. If you observe no further output, everything is fine.

Reading samples in async mode...
^CSignal caught, exiting!

User cancel, exiting...
Samples per million lost (minimum): 0

ATC Transponders and rtl_adsb

So the test passes, now try to receive ADS-B data:
$ /opt/local/bin/rtl_adsb
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001

Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
Tuner gain set to automatic.
Tuned to 1090000000 Hz.
Exact sample rate is: 2000000.052982 Hz
Sampling at 2000000 S/s.


OK, now to make it a little more friendly...

When all else fails, read the manual:
$ /opt/local/bin/rtl_adsb --help
/opt/local/bin/rtl_adsb: illegal option -- -
rtl_adsb, a simple ADS-B decoder

Use:    rtl_adsb [-R] [-g gain] [-p ppm] [output file]
    [-d device_index (default: 0)]
    [-V verbove output (default: off)]
    [-S show short frames (default: off)]
    [-Q quality (0: no sanity checks, 0.5: half bit, 1: one bit (default), 2: two bits)]
    [-e allowed_errors (default: 5)]
    [-g tuner_gain (default: automatic)]
    [-p ppm_error (default: 0)]
    [-T enable bias-T on GPIO PIN 0 (works for v3 dongles)]
    filename (a '-' dumps samples to stdout)
     (omitting the filename also uses stdout)

Streaming with netcat:
    rtl_adsb | netcat -lp 8080
    while true; do rtl_adsb | nc -lp 8080; done
Streaming with socat:
    rtl_adsb | socat -u -

So, let's try again, this time verbose and with short messages also:
$ /opt/local/bin/rtl_adsb -g49 -V -S
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001

Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
Tuner gain set to 49.60 dB.
Tuned to 1090000000 Hz.
Exact sample rate is: 2000000.052982 Hz
Sampling at 2000000 S/s.
DF=15 CA=1
ICAO Address=18f0d9
DF=10 CA=7
ICAO Address=052d75
DF=10 CA=3

Apparently, there are bazillions of planes in the desert sky, but if I look up, I cannot see any! 

Now I need to figure out how to list/map the planes with dump1090 or cocoa1090.

Cocoa1090 for ADS-B Transponders

For Air Traffic Control transponder ADS-B information, I experimented with Cocoa1090:

Start the rtl_tcp server first and connect to the dongle, then run cocoa1090.

The frequency is of course 1.090 GHz, so a half wave dipole antenna needs to be 275 mm overall, or each 1/4 wave arm needs to be138 mm.  Grab a ruler and tweak the telescopic antenna that you got with the SDR for best results.

ADS-B for Linux Lovers

You need to do one of the following:
$ sudo apt install rtl-sdr
$ sudo apt-get install rtl-sdr
# dnf install rtl-sdr

You can get Malcolm Robb's dump1090 from github.  If you need to ask how, then you have to hand your Geek card back.

ADS-B for BSD Devils

All that FreeBSD devil worshippers need to do is:
# pkg install install rtl-sdr
# pkg install dump1090
# dump1090 --net --aggressive

Then, point a webserver at http://localhost:8080/ and watch...

The OpenBSD Calgary Cowboys are SOL though - it doesn't work fully.


The RTL SDR wotzit works perfectly from inside my house with just a simple little dipole antenna.   It is very sensitive, so you don't need any fancy antennas, unless you want to do HF DX.

-. --- / .-- .. -. -.. --- .-- ... --..-- / -. --- / -.-. .-. -.--



No comments:

Post a Comment

On topic comments are welcome. Junk will be deleted.