Wednesday 5 September 2012

Moving on from the realm of DVB-T with the RTL2832U - Undoing your hard work

So, you may have read my last (and also first) blog post on getting the RTL2832U-based dongles working with Ubuntu and wondered what might be next. Before I start dissecting all the possibilities, I thought it best to explain what needs to happen before you start moving in that direction.

If you've followed the guidelines in my first post, your system will now be in a state where the required DVB-T modules are auto-magically loaded upon hot-plugging your RTL2832U dongle. This behaviour doesn't play well with GNURadio, RTL-SDR and OsmosSDR; and you'll be needing these to fully unlock the potential of your new toy.

You need to unload the modules that have been loaded. There are a whole load of DVB and infra-red modules that hog the device, that can be removed with a handful of commands, allowing you to run the aforementioned applications and libraries comfortably. To save you the effort, I've knocked up a very simple bash script (if I were to be bold enough to call it that) that you can steal from me.

#!/bin/bash 
lsmod | grep -e "ir_*" -e "dvb_*" -e "lirc_*" | awk '{ print $1 }' | tr '\n' ' ' | awk '{ print "sudo modprobe -r " $0 }' | sh
This will unload all modules relating to DVB and infra-red devices immediately. I wouldn't advise using this if you have other DVB or infra-red devices present on your systems that you need to keep functional, as it WILL disable them.

Once the modules are unloaded your system will be in the same state it was before you compiled the DKMS kernel modules.  You're now ready to start tinkering with the extended functionality of the device, which is way more fun than the DVB-T stuff.  My next post will tackle how to get GNURadio up and running, to the point where you can tune into FM radio stations.

Thanks for reading,

Chris

Tuesday 4 September 2012

Realtek RTL2832U DVB-T on Ubuntu 12.04 - A cleaner way

So, here we are again in the realms of the newbie, this time as a blog virgin.  I hope I can find the time to keep this up to date, as the main aim of this blog is to document new and useful things I've found that may be useful to others.  Wish me luck and please, provide as much feedback as you can.  If people are reading, I'll keep posting!

Some of you may have heard chatter about the nifty DVB-T/DAB USB dongles based upon the inexpensive RTL2832U chipset with E4000 tuner on board.  They come in a variety of shapes and sizes and are available for peanuts on eBay (£9 shipped from China when I purchased).  You might be thinking "Well that's nothing new", and on the basis of my initial description, you'd be correct.

When I add that these devices are from a functional perspective entirely software driven, that opens up different potential avenues for use and abuse.  With a little craft and some free open source software, these things can be turned into SDR's, or software defined radios to give them their full name.  They can pick up anything in the 60Mhz - 1700Mhz range, which includes (but isn't limited to) AM/FM radio, DVB-T, DAB/+ and even monitor the location and altitude of the aircraft flying above you.  As I said, pretty nifty stuff.

Before I got into playing with all of that neat stuff, I figured it'd be a nice starting point to at least get the DVB-T functionality working.  Unfortunately, the RTL2832U kernel modules haven't as of yet made it into the mainline, so we're on our own when it comes to getting these devices up and running.

Inspired by this blog post, I decided to leverage the Dell-sponsored DKMS system to manage this module.  The beauty of this solution is that you don't need to worry about ensuring that the module is rebuilt every time you upgrade your kernel; DKMS takes care of it all behind the scenes, so you won't have to manually recompile every time a kernel update is pushed out.  At worst a reinstall of the package via aptitude will fix any issues, which I'm sure you'll agree is much more elegant than the usual `make clean; make; make install;` rigmarole.  Learning the structure of the DKMS tree took around 20 minutes, plus another five minutes to hastily cobble together a .dsc set.  This has been tested on two different Ubuntu 12.04 LTS amd64 boxes, but should work just as well for i386 and possibly other architectures. 

Without further adieu, here are the commands you'll need to run to get up and running with DVB-T. Please ignore the typo in the repository name! It was late in the evening when I created the PPA repo, and I'd already published packages before I'd noticed. :)

$ sudo apt-add-repository ppa:chrisfu/rt2832u-dkms
$ sudo apt-get update
$ sudo apt-get install rtl2832u-dkms
Once the last command completes, you should be able to hot-plug the DVB-T dongle and see this sort of output in dmesg:

[  354.576385] IR NEC protocol handler initialized
[  354.579418] IR RC5(x) protocol handler initialized
[  354.586588] dvb-usb: found a 'RTL2832U DVB-T USB DEVICE' in warm state.
[  354.586602] dvb-usb: will pass the complete MPEG2 transport stream to the software demuxer.
[  354.588113] IR RC6 protocol handler initialized
[  354.588413] DVB: registering new adapter (RTL2832U DVB-T USB DEVICE)
[  354.590264] IR JVC protocol handler initialized
[  354.595469] IR Sony protocol handler initialized
[  354.598784] IR MCE Keyboard/mouse protocol handler initialized
[  354.600567] lirc_dev: IR Remote Control driver registered, major 249
[  354.600748] IR LIRC bridge handler initialized
[  354.604391] RTL2832U usb_init_bulk_setting : USB2.0 HIGH SPEED (480Mb/s)
[  354.844016] RTL2832U check_tuner_type : E4000 tuner on board...
[  355.405150] DVB: registering adapter 0 frontend 0 (Realtek DVB-T RTL2832)...
[  355.405396] input: IR-receiver inside an USB DVB receiver as /devices/pci0000:00/0000:00:1a.7/usb1/1-3/input/input5
[  355.406482] dvb-usb: schedule remote query interval to 287 msecs.
[  355.406489] dvb-usb: RTL2832U DVB-T USB DEVICE successfully initialized and connected.
[  355.406544] usbcore: registered new interface driver dvb_usb_rtl2832u

You can then use Xine/VLC/whatever you typically use to watch television.  I'd recommend you install the following package in order to test your card and scan the muxes for DVB-T channels to watch.
$ sudo apt-get install dvb-tools
$ scan -o zap /usr/share/dvb/dvb-t/uk-WinterHill > channels.conf
I'd suggest ditching any supplied aerial and using the best one available to you, for which you'll probably need a coaxial converter that can be bought on eBay for a few pounds. Remember to change the last argument in the above command to the nearest transmitter to you. You can find all the UK transmitter configs with the following command:
$ find /usr/share/dvb/dvb-t/ -type f -iname '*uk*'
That should get you started on your adventure. After you're through with tinkering with it's DVB-T capabilities, I'd strongly urge you to have a play with the devices other capabilities. After all, it's the tinkering that got Linux to where it is today!

If anyone has any bug reports of questions, please go ahead and comment.

There we have it, my blog cherry has been officially popped.

Cheers,

Chris