Sunday 2 June 2013

Using your SDR Pi. Fun stuff.

Tune In with your Pi.

Grab yourself a powered set of computer speakers. One of those amplified ones with the Bass Reflex box and two speakers.

If you're ready to have a bit of fun with your Raspberry Pi and SDR receiver connect the speakers 3.5mm stereo plug into your Raspberry Pi audio out socket. Power up your Raspberry Pi with your USB SDR plugged in and log in when the command line prompt appears. You might want to make sure your SDR stick has the cool little antenna plugged in that came with it.
RasPi + DVB + Speaker plug = FM Stereo

You could also do this remotely using PuTTY on your Windows PC or just use 'SSH' on your Linux computer.

The RTL_SDR software we installed in our Raspberry Pi has a pre-made 'FM' mode that we can call from the command line. If you are now logged in just enter the following:

rtl_fm -f XXX -W -s 200000 -r 48000 - | aplay -r 48k -f S16_LE

NOTE: Replace the XXX with the frequency you want to listen to in Hertz. For our purposes you can enter the frequency for 100MHz as 100.0e6 as per the screen grab below. Its there just after the '-f'.


 Our Raspberry Pi is now an FM Radio Tuner that we can set to pretty much any frequency from 50MHz up to 2200MHz (with a gap around 1100MHz).

While we are building the rest of our Radio Astronomy Station we now have a neat way to play with our Raspberry Pi and SDR receiver. If you want to have a look through the command line options for the FM Receiver try entering:

rtl_fm --help

This results in the following output.

pi@raspberrypi ~ $ rtl_fm --help
rtl_fm, a simple narrow band FM demodulator for RTL2832 based DVB-T receivers

Use:    rtl_fm -f freq [-options] [filename]
    -f frequency_to_tune_to [Hz]
     (use multiple -f for scanning, requires squelch)
     (ranges supported, -f 118M:137M:25k)
    [-s sample_rate (default: 24k)]
    [-d device_index (default: 0)]
    [-g tuner_gain (default: automatic)]
    [-l squelch_level (default: 0/off)]
    [-o oversampling (default: 1, 4 recommended)]
    [-p ppm_error (default: 0)]
    [-E sets lower edge tuning (default: center)]
    [-N enables NBFM mode (default: on)]
    [-W enables WBFM mode (default: off)]
     (-N -s 170k -o 4 -A fast -r 32k -l 0 -D)
    filename (a '-' dumps samples to stdout)
     (omitting the filename also uses stdout)

Experimental options:
    [-r output_rate (default: same as -s)]
    [-t squelch_delay (default: 20)]
     (+values will mute/scan, -values will exit)
    [-M enables AM mode (default: off)]
    [-L enables LSB mode (default: off)]
    [-U enables USB mode (default: off)]
    [-R enables raw mode (default: off, 2x16 bit output)]
    [-F enables high quality FIR (default: off/square)]
    [-D enables de-emphasis (default: off)]
    [-C enables DC blocking of output (default: off)]
    [-A std/fast/lut choose atan math (default: std)]

Produces signed 16 bit ints, use Sox or aplay to hear them.
    rtl_fm ... - | play -t raw -r 24k -e signed-integer -b 16 -c 1 -V1 -
                 | aplay -r 24k -f S16_LE -t raw -c 1
      -s 22.5k - | multimon -t raw /dev/stdin


Cheers!
Robert.

Saturday 1 June 2013

Radio Astronomy Station. Part 4.

The Software Defined Radio.

In Part 2, I discussed the various parts of the Radio Astronomy Station and the Raspberry Pi with a USB Software Defined Radio (SDR).

In Part 3 we went through getting the Raspberry Pi working. You should now have a RasPi with a USB Keyboard and Mouse plugged in, power connected with a micro USB mobile phone charger and a screen plugged in to either the composite video RCA socket or getting an awesome picture through the HDMI connector.

If you successfully reached the Linux Rasbian login prompt you should see:

raspberrypi login :

Enter your username which should have defaulted to 'pi'.
Enter your password which is 'raspberry' if you didn't alter it with raspi-config.

You should now see the login message telling you when you last logged in and the GNU/Linux message telling you about free software!

If you have an ethernet cable from your RasPi to your router you should have an active internet connection. The login message we saw earlier shows the IP address of the RasPi. Most likely something like '192.168. something dot something'. It depends on how your router is set up.

We can now do some cool stuff to test our RasPi. On the command line type 'top' (without the quotes) and hit enter. You'll see the current time, how long your RasPi has been active for, how many users are logged in and also the amount of hard work your RasPi is doing. To exit from 'top' just hit 'q' and you should end up back at the command line prompt.

Raspberry Pi running 'top'

The picture here shows two active logins, one from the keyboard and one remote login.







Remote Login

The ability to log in remotely to the Raspberry Pi or in fact any Linux computer is a pretty cool thing to do. You might want to look at installing a program on your PC for logging in with SSH (unless you already use a Linux computer and have all the tools you need). On a Windows PC I use a program called PuTTY (www.putty.org) to log in. Its fairly easy to use. Just dont be put off by the options for using it. Only need three things. IP address, Username, Password to do a remote login. Make sure you use the 'SSH' option.

If you have a Linux PC, just open a terminal window and type 'ssh -l pi (ip address)'. Thats a lower case L not a 'one'.
Update Your Pi.

Ok so thats the hard part over. Your Raspberry Pi is running, you've seen 'TOP' give you a rundown of whats going on. If you haven't done so yet, now might be a good time to Update your operating system. Assuming you have a working internet connection enter the following:

sudo apt-get update

*(Note - 'sudo' means 'superuser do' and 'apt-get' is the cool updating and software installing tool).

Linux being the secure operating system it is, you'll be asked for your password. You should then see your Linux Raspbian querying a bunch of different websites asking for updates on files etc. You can now go ahead and run those updates by entering the following:

sudo apt-get upgrade

Your RasPi already knows your password was entered so it should now start downloading all the relevant updated files for your Linux Raspbian operating system. You were probably also asked if it is ok to download and install xxx Megabytes of updated files.

Once the downloading and upgrading is finished you may want to restart your Linux Raspbian. If you are remotely logged in your connection will be cut so you'll need to reconnect. If you are using keyboard and screen you'll just get a restart. Go ahead and type the following:

sudo shutdown -r now

Wait about 60 seconds while your RasPi goes through its reboot. 'Shutdown' with the -r means 'Shutdown and Reboot' and the 'now' means do it NOW.

If you have a keyboard and screen you'll be seeing the normal restart stuff. If you are using a remote login you'll have to go through the PuTTY login sequence again.

Once back at the command line we're ready for setting up the Software Defined Radio.

Setting up the SDR.

You may find it just as easy to go through Peter Goodhalls web page on setting up the Raspberry Pi. You can read his page here. http://m3php.com/2012/10/10/remote-sdr-using-raspberry-pi-rtl_tcp/

Otherwise, if you want to follow it here, here's what we need to enter.

  1. sudo apt-get install git
  2. git clone git://git.osmocom.org/rtl-sdr.git
  3. sudo apt-get install cmake
  4. sudo apt-get install pkg-config
  5. sudo apt-get install libusb-1.0
  6. cd rtl-sdr/
  7. mkdir build
  8. cd build
  9. cmake ../ -DINSTALL_UDEV_RULES=ON
  10. make
  11. sudo make install
  12. sudo ldconfig

If you have completed the steps above you should now have a Raspberry Pi with all the software needed to use the Software Defined Radio USB stick. You should now do another restart so repeat our shutdown sequence from before.

When you get back to the command line and you are logged in, plug in the DVB SDR stick into the spare USB port where the keyboard is. If you are remotely logged in this will be a lot easier without the keyboard connected. You may also want to consider an external powered USB Hub to provide extra USB ports and extra power for USB devices.

Ok lets start up our SDR stick. Type in the following:

lsusb

You should see a list of USB devices that are plugged in. One of them should be a Realtek RTL2832U which is our Digital Radio device. If you can successfully see this in the USB device list then go ahead and start the SDR.

rtl_tcp -a 192.168. (whatever your RasPi IP address is).

Our SDR is now receiving and ready
You might like to try an App on your Android phone called SDR Touch. While still buggy and prone to crashing it will interface with your SDR radio tuner and produce received audio from your phone.

On your Windows PC try using SDR Sharp (www.sdrsharp.com). This makes a good, easy to install application for Windows users. Go to this page http://rtlsdr.org/softwarewindows and follow the instructions for installing SDR Sharp on a Windows PC.


SDR Sharp running on Windows 7 connected via the network to my Raspberry Pi and SDR receiver
Spend some time getting used to how SDR Sharp works. For now, this makes a great testing program for your SDR receiver. Later on we should look at other SDR software that can give us even more flexability.

Thats one of the advantages with a system like this. We can swap and reconfigure different parts to get better results. At a later stage we could replace the whole Raspberry Pi and SDR receiver with a different SDR package that could work on frequencies as high as 10 GHz.

I hope for now you have fun with your SDR receiver.

Cheers.