Inicio » OSES: Software defined radio session

OSES: Software defined radio session

Rationale

This session is focused to show a typical effort to get something working on a general purpose operating system for embedded.

Typically, you will need to search for information (forums, blogs, web pages, datasheets, manuals, electronic schematics, etc.), install software, tweak your embedded OS, install drivers, … to get something working.  Finally, you can go back to the «programming session» concept and develop your desired application.

This session is focused to illustrate this idea. When developing the activity at the lab, I will explain OS concepts associated with the activity.

For clarity reasons, this session uses only software available in Linux repositories. So, no source download from code repositories or build like in the previous sessions.

Taking into consideration that you are «telco», I decided to elect something modern, well recognized and amazing (from my point-of-view: Software Defined Radio (SDR).

ATCHUNG! This session implies installing software and running time-consuming apps, so we will overlap installing/running with looking for external information.

Software Defined Radio (SDR) concepts

Some very basics about Software Defined Radio. Please, correct me if I say something incorrect 😉

Hell, I need more space in the SD

Raspbian keeps growing year by year!.  It is full of sh*

Please, test the available space in your SD

$ df

If no room (around 2GB), un-install something

$ sudo apt-get purge libreoffice*
$ sudo apt-get purge wolfram-engine
$ sudo apt-get clean
$ sudo apt-get autoremove

And, test space

$ df

Playing with a DVB-T USB dongle

Well, lets prepare things before going to SDR playground.

I provided you with a typical (well, it seems typical) DVB-T USB dongle described in the equipment section and bought in Amazon.

Of course, the purpose of the dongle is watching TV. Doing it on Microsoft Windows with a closed-source commercial application bundled with your dongle is not amazing. So let’s try to get it working using Linux using OPEN SOURCE SOFTWARE (Yes, I’m crying).

The reference page for watching TV on Linux boxes is the LinuxTV site.

Let’s start.

  • Please, turn on your Linux machine (your Raspberry Pi with Raspbian or the Linux Virtual Machine)
  • Plug the DVB-T USB dongle
  • Open a terminal and issue the command dmesg
$ dmesg

On my RPi I obtaining the following output

[   67.153264] usb 1-1.4: new high-speed USB device number 6 using dwc_otg
[   67.265292] usb 1-1.4: New USB device found, idVendor=1d19, idProduct=1101
[   67.265322] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[   67.265339] usb 1-1.4: Product: DVB-T Dongle
[   67.265355] usb 1-1.4: Manufacturer: Realtek
[   67.265371] usb 1-1.4: SerialNumber: 00000991
[   67.343319] usb 1-1.4: dvb_usb_v2: found a 'Dexatek DK DVB-T Dongle' in warm state
[   67.375724] usb 1-1.4: dvb_usb_v2: will pass the complete MPEG2 transport stream to the software demuxer
[   67.375790] DVB: registering new adapter (Dexatek DK DVB-T Dongle)
[   67.394259] i2c i2c-3: Added multiplexed i2c bus 4
[   67.394287] rtl2832 3-0010: Realtek RTL2832 successfully attached
[   67.394330] usb 1-1.4: DVB: registering adapter 0 frontend 0 (Realtek RTL2832 (DVB-T))...
[   67.409628] fc0013: Fitipower FC0013 successfully attached.
[   67.421851] Registered IR keymap rc-empty
[   67.422223] input: Dexatek DK DVB-T Dongle as /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/rc/rc0/input3
[   67.422503] rc0: Dexatek DK DVB-T Dongle as /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/rc/rc0
[   67.430333] IR NEC protocol handler initialized
[   67.433824] IR RC5(x/sz) protocol handler initialized
[   67.437937] IR RC6 protocol handler initialized
[   67.441147] IR JVC protocol handler initialized
[   67.444658] IR Sony protocol handler initialized
[   67.449079] IR Sharp protocol handler initialized
[   67.449140] IR SANYO protocol handler initialized
[   67.452303] usb 1-1.4: dvb_usb_v2: schedule remote query interval to 200 msecs
[   67.454732] input: MCE IR Keyboard/Mouse (dvb_usb_rtl28xxu) as /devices/virtual/input/input4
[   67.458161] IR MCE Keyboard/mouse protocol handler initialized
[   67.461227] usb 1-1.4: dvb_usb_v2: 'Dexatek DK DVB-T Dongle' successfully initialized and connected
[   67.461478] usbcore: registered new interface driver dvb_usb_rtl28xxu
[   67.461550] lirc_dev: IR Remote Control driver registered, major 243 
[   67.465894] rc rc0: lirc_dev: driver ir-lirc-codec (dvb_usb_rtl28xxu) registered at minor = 0
[   67.465924] IR LIRC bridge handler initialized
[   67.467099] IR XMP protocol handler initialized

This output shows messages of the Linux kernel. At the end of the log there are messages about our dongle because it is the latest device inserted in the machine. Using «dmesg» is a typical action of a developer when he/she inserts a new «thing».

Carefully read these messages and try to understand their meaning. Search the Internet for understanding the interesting details about this output.

We are happy! The Linux kernel recognizes the dongle (drivers installed) and shows good chips for RTL-SDR (Realtek RTL2832 and Fitipower FC0013 chips).

Run the following to try to understand something about dmesg.

$ man dmesg

Errr … well, probably you will understand nothing this time. But now you are aware that man continues here.

Let’s continue. For watching TV, we need tuning information about broadcast TV/radio stations. There are tables on the Internet for that, but we can use some utilities for scanning the sky.

First, we need more software (open and free), let’s install it from repositories

$ sudo apt-get install w-scan dvb-apps

Now, you can run a utility for scanning. Run it in a terminal and use man in another terminal.

$ mkdir wowsdr
$ cd wowsdr
$ w_scan -ft -c ES -X > channels.conf

You should get an output similar to this one

FREQ (174.00MHz ... 862.00MHz)
219500: (time: 00:19) 
226500: (time: 00:22) 
Scanning 8MHz frequencies...

762000: (time: 03:40) (time: 03:41) signal ok:
    QAM_AUTO f = 762000 kHz I999B8C999D999T999G999Y999
    updating transponder:
       (QAM_AUTO f = 762000 kHz I999B8C999D999T999G999Y999) 0x0000
    to (QAM_64   f = 762000 kHz I999B8C23D0T8G4Y0) 0x405A
...

Use man to understand the parameters utilized for the new command w_scan.

Well, you are «telco» so, please, explain to me the meaning of «MHz», «QAM», …

Take a look inside the channels.conf file. It is a text file. Try to understand its contents.

Now we are ready for watching TV, we need a video playing utility (VLC, mplayer, Kaffeine, …) and redirect the decoded flow of data to these applications. Let’s try it.

$ sudo apt-get install mplayer
$ mplayer

The last step is only for letting mplayer to create a default configuration for the user)

$ cp channels.conf ~/.mplayer/
$ mplayer dvb://"PARAMOUNT CHANNEL(PARAMOUNT CHANNEL)"

The parameter for mplayer has been obtained of the contents of channels.conf file. Test your own file for available channels.

You should get an image similar to this one (crossed fingers).

sdr-dvb-t-2015-11-03-212543_1552x1168_scrot

Activity: headphones

Oh! Hell! This year our monitors don’t have an audio input.

Plug-in the headphones, plug-in in your ears … it works? No?

Well, this is a typical embedded system and OS configuration problem. Practice solving it!.

Please, let me know which is the problem and your proposed solution.

RTL-SDR

The cheapest option to start playing with SDR is to use a commercial DVB-T USB dongle and benefit of the RTL-SDR effort. Not all the dongles are adequate, so you need some research in order to get the appropriate one.

In our case, I elected the dongle showed in the equipment section and bought it on Amazon.

In this section, I will show you how to get a running SDR environment using the dongle, an embedded platform (RPi), the Linux OS, and adequate pieces of software. For an inexperienced newbie, this could be equivalent to 10/20 hours of work.

Installing RTL-SDR

Well, let’s hack. It is time for using the dongle for other things. You can scan an incredible range of frequencies with this device and decode data using software radio blocks.

Install «the easy way» (group the packages in the same line to avoid waiting between installs. Perfect for coffee break.)

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

or follow instructions available at http://sdr.osmocom.org/trac/wiki/rtl-sdr.

Setup udev rules

Ein? What «udev» means? The simple response is that your OS if full of configuration files. In this case, you will configure the option that the OS elects for a given device.

Well, you need to add some udev rules to make the dongle available. First, you want to find the vendor id and product id for your dongle. This is typical USB bla, bla. Run:

 $ lsusb

and locate the line that identifies the dongle. For my dongle it is:

Bus 002 Device 016: ID 1d19:1101 Dexatek Technology Ltd. DK DVB-T Dongle

where «1d19» is the vendor id and «1101» is the device id.

Now WITH CARE, do the following

$ sudo bash
# cd /etc/udev/rules.d
# ls
# nano 20.rtlsdr.rules

Add the following line and save the file,

SUBSYSTEM=="usb", ATTRS{idVendor}=="1d19", ATTRS{idProduct}=="1101", GROUP="adm", MODE="0666", SYMLINK+="rtl_sdr"

Unplug the DVB-T dongle and run,

(For Ubuntu 12.04)

$ sudo restart udev

(For raspberry)

$ sudo udevadm control --reload-rules

Or, simply, reboot your system.

Testing operation

Plug-in the USB dongle and test correct access to the dongle using the rtl_test utility

$ rtl_test

If you get the following error,

Found 1 device(s):
0: Realtek, DVB-T Dongle, SN: 00000991
Using device 0: Dexatek DK DVB-T Dongle (Logilink VG0002A)
Kernel driver is active, or device is claimed by second instance of librtlsdr.
In the first case, please either detach or blacklist the kernel module
(dvb_usb_rtl28xxu), or enable automatic detaching at compile time.

This is because the drivers for watching TV are loaded, and you need to unload it. Temporary solution (every reboot of the system).

$ sudo rmmod dvb_usb_rtl28xxu rtl2832

you can use man for understanding the use of rmmod. Essentially you are loading/unloading software modules in the OS kernel.

Rerun rtl_test, if the output is similar to the showed bellow, then things started working (press Ctrl-C for terminating)

Found 1 device(s):
0: Dexatek DK DVB-T Dongle (Logilink VG0002A)
Using device 0: Dexatek DK DVB-T Dongle (Logilink VG0002A)
Found Fitipower FC0013 tuner
Supported gain values (23): -9.9 -7.3 -6.5 -6.3 -6.0 -5.8 -5.4 5.8 6.1 6.3 6.5 6.7 6.8 7.0 7.1 17.9 18.1 18.2 18.4 18.6 18.8 19.1 19.7
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!

SDR with gqrx

qqrx is a graphical tool developed using Qt and GNUradio that simplifies the use of SDR for basic reception activities.

PARA EL CURSO 2020/2021

$ sudo apt install gqrx-sdr

$ gqrx –edit

y mira el diálogo de configuración que hay abajo

Install it (I had some trouble with the sound output) …

HELLLLLLLLLLL and now we have «buster» Raspbian.

Try

$ sudo apt install pulseaudio gqrx-sdr

and follow this (but no sound working)

https://raspberrypi.stackexchange.com/questions/639/how-to-get-pulseaudio-running

HELLL it does not work this year, forget these lines …

$ sudo apt-get install pulseaudio
$ sudo apt-get install gqrx-sdr

And follow http://gqrx.dk/download/gqrx-sdr-for-the-raspberry-pi except …

Configure dialog

sdr-gqrx-config

Activity

Tune for FM at 106.6MHz Radio Clásica (Valencia-Spain). Use your headphones for listening.

NOTE: take into account that the RPi has limited power, so try to reduce sampling rates, bandwidth, etc. for avoiding crashes.

sdr-gqrx-106.6M-Radio-clasica

Activity

Try to find transmissions in different bands. Use the appropriate demodulation mode to listen to the transmission (perhaps it will data, but you can hear «chirps»).

You can find transmissions of the public services or flight information (flight tracker) …

GNU Radio

Amazing project for telecos!.

You installed GNU radio in the previous steps. And gqrx is based on gnuradio project.

There is a lot of pieces here. Probably, the best option is to start with the GNU Radio Companion utility. GNU Radio Companion (GRC) is a graphical tool for creating signal flow graphs and generating flow-graph source code.

screenshot_grc

Let’s run it.

$ gnuradio-companion

And start playing.

Find information and examples.

Task: Morse decoder (CW)

This will be part of your marks.

Install gnuradio in your RPi or your Linux Virtual box (I don’t know if it works for MWindows or MacOS).

Find information about decoding Morse using GNU Radio.

Find or develop a decoder.

Test your decoder on recorded data.

To get the highest mark, you can borrow me the DVB-T USB dongle (when you show me something near to work).

SUBMIT YOUR WORK USING POLIFORMAT TASK ADDING AN SMALL REPORT (max. 4 pages) WITH FOLLOWED STEPS

Task: LoRa decoder

Well, this is another possibility. Really amazing.

https://github.com/rpp0/gr-lora