-
Notifications
You must be signed in to change notification settings - Fork 22
macOS_info
This page will explain how to configure macOS for the RTL-SDR dongle and Pyaudio for real-time DSP using internal and external audio devices.
The device you are configuring is the TV tuner USB dongle known as the RTL-SDR, which as this link shows can be purchased for under $20. During the tutorial a number of these dongles will be available for hands-on experimenting with signal capture and processing the signals into playback information, e.g., music, speech, and data bits. Not required, but encouraged for the hardware tinkerer, is to purchase your own dongle from the above link.
On to the software driver set-up. There are several options available for macOS. A nice overview to consider is found at UC Berkeley. From this link you will find macOS set-up details, but this will likely not work without some additional work. See for example (https://superuser.com/questions/970604/rtl-sdr-on-mac-os-x) and other threads. An easy out is described below.
I suggest taking the Homebrew route. Three steps starting from Homebrew install and finishing with a pip
install. Along the way you may need to install/upgrade macOS Xcode
and need to accept xcodebuild
, e.g.
Error: You have not agreed to the Xcode license. Please resolve this by running:
sudo xcodebuild -license accept
Marks-MacBook-Pro:MacOS wickert$ sudo xcodebuild -license accept
Password:
- From the terminal install Homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Next
brew install rtl-sdr
:
Marks-MacBook-Pro:MacOS wickert$ brew install rtl-sdr
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
chakra planck roswell
==> Installing dependencies for librtlsdr: libusb
==> Installing librtlsdr dependency: libusb
==> Downloading https://homebrew.bintray.com/bottles/libusb-1.0.21.sierra.bottle
######################################################################## 100.0%
==> Pouring libusb-1.0.21.sierra.bottle.tar.gz
==> Using the sandbox
🍺 /usr/local/Cellar/libusb/1.0.21: 29 files, 510.5KB
==> Installing librtlsdr
==> Downloading https://homebrew.bintray.com/bottles/librtlsdr-0.5.3.sierra.bott
######################################################################## 100.0%
==> Pouring librtlsdr-0.5.3.sierra.bottle.1.tar.gz
🍺 /usr/local/Cellar/librtlsdr/0.5.3: 18 files, 327KB
As the final step pip install pyrtlsdr
:
Marks-MacBook-Pro:MacOS wickert$ pip install pyrtlsdr
Collecting pyrtlsdr
Downloading pyrtlsdr-0.2.4-py2.py3-none-any.whl
Installing collected packages: pyrtlsdr
Successfully installed pyrtlsdr-0.2.4
Note: The installation also sets up a path to the drivers so you can access the utilities from and any location, and the pyrtlsdr
can access the libraries accordingly.
There are a number of command line utilities that are part of the RTL-SDR driver set, common to all platforms.
mwickert@ubuntu:~/RTLSDR/rtl-sdr/build/src$ ls -l
-rwxrwxr-x 1 mwickert mwickert 29024 May 23 23:00 rtl_adsb
-rwxrwxr-x 1 mwickert mwickert 22288 May 23 23:00 rtl_eeprom
-rwxrwxr-x 1 mwickert mwickert 47696 May 23 23:00 rtl_fm
-rwxrwxr-x 1 mwickert mwickert 42224 May 23 23:00 rtl_power
-rwxrwxr-x 1 mwickert mwickert 23608 May 23 23:00 rtl_sdr
-rwxrwxr-x 1 mwickert mwickert 29744 May 23 23:00 rtl_tcp
-rwxrwxr-x 1 mwickert mwickert 24160 May 23 23:00 rtl_test
In particular rtl_eeprom
reads registers in the dongle. To explore any of these utilities type util_name -h
at the command line. Usage examples for some of them can be found at (http://osmocom.org/projects/sdr/wiki/rtl-sdr) . I use this below to see if all is well when the dongle is present. There is not too much to do without the dongle present, but some encouragement is the following:
Marks-MacBook-Pro:~ wickert$ rtl_eeprom
No supported devices found.
The above at least tells you the USB interface drivers are trying find a device. With the dongle plugged in I get:
Marks-MacBook-Pro:~ wickert$ rtl_eeprom
Found 1 device(s):
0: Generic RTL2832U OEM
Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
Current configuration:
__________________________________________
Vendor ID: 0x0bda
Product ID: 0x2838
Manufacturer: Realtek
Product: RTL2838UHIDIR
Serial number: 00000001
Serial number enabled: yes
IR endpoint enabled: yes
Remote wakeup enabled: no
__________________________________________
Once you have a RTL-SDR dongle available you can perform a sample capture using the code found in the Jupyter notebook RTL-SDR_Test.ipynb
which is located in the tutorial repo folder hardware_configure
.
After setting up the drivers, you optionally can install an SDR receiver application known as GQRX (similar to SDR# for Windows). See for example (http://www.rtl-sdr.com/installing-gqrx-on-osx-el-capitan/). Below is a screen-shot of the application running on macOS. If you purchase your own dongle feel free to start playing with this app before the tutorial. In the tutorial you will be working with the signal samples output from the device
Audio I/O is another avenue for hardware interfacing between your PC and the signal processing capabilities of Python. Pure audio I/O is of interest unto itself, but you can also thing of streaming audio out of your PC as the back-end to streaming radio signals in via the RTL-SDR. The intent of the tutorial is to focus on processing signal captures made from the RTL-SDR. Setting up a real-time stream from the radio input the audio output is the ultimate challenge, and something that I have been contemplating, but do not have a polished solution for just yet. The speed limitations of Python means that the Python code that sits between the input and output be very lean and efficient, and requires the use of call-backs and buffer management.
To get started with analog I/O I like Pyaudio, which provides Python bindings to the well established cross-platform C/C++ library PortAudio. PortAudio is used in many of the RTL-SDR apps that you can read about on the Web. For macOS follow the instructions found on the Pyaudio project Web Site, which is summaried in two steps: brew install portaudio
, then pip install pyaudio
.
When installation is complete you can run code samples found in the Jupyter notebook Pyaudio_Test.ipynb
which is located in the tutorial repo folder hardware_configure
. You will be able hear sounds playing through your speakers or headphones.