Showing posts with label dump1090. Show all posts
Showing posts with label dump1090. Show all posts

Thursday, September 14, 2017

Flight Tracking (ADS-B) using the Raspberry Pi



In a previous post we looked at getting ADS-B tracking working on a pcDuino, to compare build difficulty with a Raspberry Pi, we built one of those as well. TL;DR version - it is much easier and you get the latest version of PiAware.

To get Dump1090 and PiAware working on a Raspberry Pi the easiest way is to just download a version of Raspbian with the software preloaded and then copy it to a SD card. Done. Full instructions are available on the FlightAware website.

We made things a bit harder for ourselves because we wanted to also try out the 4D Systems 2.4" touchscreen HAT. This requires its own drivers.

4DPi 24 HAT Display



The 4DPi-24-HAT is a 2.4" 320x240 Primary Display HAT for the Raspberry Pi, which plugs directly on top of a Raspberry Pi. It features an integrated Resistive Touch panel, enabling the 4DPi-24-HAT to function with the Raspberry Pi without the need for a mouse (theoretically). In practise the touch part of the screen is unusable. You will need a mouse to do anything useful.

Communication between the 4DPi-24-HAT and the Raspberry Pi is via the high speed 48Mhz SPI connection.

The HAT also features 5 push buttons, and a backlight. Supposedly this backlight can be configured as either On/Off or PWM controlled, selectable by an on board jumper, but only one position worked for us - see point 2 below.

The pushbuttons can be used in a python script (for example) but it isn't totally straight forward. Have a look at the data sheet for some examples.




There are a few tricks to getting this display to work with the Raspberry Pi:

  1. Make sure you download the latest drivers. The link in the instructions which came with my HAT was for an older version (which didn't work with the Raspberry Pi 3).
  2. Set the backlight link to ON/OFF not PWM. Mine came with PWM selected but it wouldn't work in this configuration. A definite trap for young players! It took me a while to track this down.
  3. You will need a couple of PCB stand offs. Get ones with a M2.5 thread and the body should be 11mm in length. These are not provided (but should be).

Optimising the Display




The 4DPi-24-HAT has a 320x240 resolution, so expectations need to be realistic about what can be usefully displayed. 

Raspbian has not been optimised to run on a display with this resolution, so there are some menus and applications which will not display correctly, or fit on the screen.

This can be helped somewhat, by setting up the display appearances, and setting fonts and
menus to be smaller. You will need to use a USB mouse and keyboard to perform this set up.

Raspberry Menu -> Preferences -> Appearance
Settings
go to Menu Bar tab
Select Small

go to System tab
click on font (Robo Light)
drag window, to see font size, select 8
(close window [x])

Click on File Manager in Menu Bar
Go to Edit, select Preferences
Select Display
Choose smallest icon sizes for all icon types
Click on "Size of Large Icons", press tab 6 times (as
the OK button is not visible), Press enter

Right click on menu bar (just left from pi menu,
near bottom edge of menu bar), to get a pop-up
menu.

Choose Add/Remove Panel Items
Remove unwanted items (eg Bluetooth)
(close window [x])

Raspberry Menu->Shutdown->Reboot

Installing Dump1090 and PiAware


To install Dump1090 and PiAware on an exisiting Raspbian installation, follow these instructions on FlightAware. It is very straight forward. The best way is to ssh in and paste the commands into terminal. Once you have plugged the USB SDR in and rebooted you should be up and running. 

We used the same USB DVB-T TV Tuner RTL2832U + R820T as our SDR. You can get these very cheaply on E-Bay.



Notice in the screen shot below that we are running the latest version of PiAware (unlike the older version we were using on the pcDuino).


Auto Load PiAware on Boot


We wanted the Raspberry Pi to auto load the PiAware web site for our ADS-B station every time the system is rebooted. To do this, first make a copy of the LXDE autostart file:

$ cp /etc/xdg/lxsession/LXDE-pi/autostart /home/pi/.config/lxsession/LXDE-pi/autostart
Then edit it:

sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart
And add the following:

@xscreensaver -no-splash 
@xset s off
@xset -dpms
@xset s noblank
@chromium-browser --incognito --kiosk http://localhost:8080
Save the file, reboot and you should be good.

Comparison with pcDuino


As expected it is a lot easier (trivial in fact) to get PiAware to work on the Raspberry Pi than the pcDuino. The biggest issues we had were with the 4D Systems 2.4" Display HAT - which I don't think add much value in this instance.

Friday, August 18, 2017

Flight Tracking (ADS-B) using the pcDuino

Introduction





Interested in what planes are flying over your house? Want to know how high they are and how fast they are going? Want to build your own ADS-B ground station that can be installed anywhere and receive real-time data directly from airplanes on your computer. Then this project may be for you.

As mentioned in a previous post Diyode Magazine and Jaycar Electronics very kindly gave me a pcDuino to have a play with. Having got the 5" LCD display working with the pcDuino, I wanted to try using it as part of a project that has been on my "to do" list for some time, namely a plane tracker.

There are lots of tutorials on how to do this with a Raspberry Pi, but I think this may be the first time it has been done on the pcDuino. Everything installs pretty much as it would on the Raspberry Pi but of course the pcDuino uses an Ubuntu variant and most Pi's use Debian (or Raspbian to be precise). This means that there is a little bit more work to get things operational.



Credit to RubyDucky for providing the basis for the install technique on Ubuntu. I will note where I found differences installing on the pcDuino and the workarounds required.

ADS-B


Our plan is to track planes using ADS-B. So what is this?

ADS-B is a system in which electronic equipment onboard an aircraft automatically broadcasts the precise location of the aircraft via a digital data link. The data can be used by other aircraft and air traffic control to show the aircraft’s position and altitude on display screens without the need for radar.

The system involves an aircraft with ADS-B determining its position using GPS. A suitable transmitter then broadcasts that position at rapid intervals, along with identity, altitude, velocity and other data. Dedicated ADS-B grounds stations receive the broadcasts and relay the information to air traffic control for precise tracking of the aircraft.

Automatic – Requires no pilot input or external interrogation.

Dependant – Depends on accurate position and velocity data from the aircraft’s navigation system (eg. GPS).

Surveillance – Provides aircraft position, altitude, velocity, and other surveillance data to facilities that require the information.

Broadcast – Information is continually broadcast for monitoring by appropriately equipped ground stations or aircraft.

ADS-B data is broadcast every half-second on a 1090MHz, digital data link. The ability of a ground station to receive a signal depends on altitude, distance from the site and obstructing terrain. The maximum range of each ground station can exceed 250 nautical miles. [Credit: Air Services Australia]

Don't expect a 250 nm range with our setup. I have found the planes need to be pretty much overhead and the aerial near the window, although I do live in a valley. The signal is not designed to penetrate buildings and is pretty much line of sight. Refer to the antenna section below if you want to improve reception.

The Software Defined Radio (SDR) Receiver






The RTL2832U-based SDR receiver is designed and marketed for DVB-T reception. However, it’s possible to get raw samples from the device, rather than just a demodulated DVB signal. This means that wireless systems can then be implemented in software. I used the USB DVB-T TV Tuner RTL2832U + R820T from Wiltronics (shown above).

The RTL2832U chip is generally paired with a tuner IC and in the case of the USB receiver from Wiltronics, it’s an R820T, which enables reception from 24MHz to 1,850MHz.

Installation of the hardware is simple just plug the SDR receiver into a USB port. As there is only one USB port on the pcDuino you will probably need a hub so that you can also plug in the keyboard and mouse required for setup. I had a powered hub but it doesn't seem to need it, I think the pcDuino supplies enough current for an unpowered USB hub to work. Don't plug in the SDR receiver until instructed below.

Antenna


The antenna which comes with the USB Tuner is 100 mm in length. This works ok but is not optimised for receiving signals with a frequency of 1090 MHz. If you are having problems with reception, you could purchase the FlightAware 1090MHz antenna, or there are plenty of home brew designs online.

Software Installation


The first step is to download some packages and libraries which are required for dump1090 and piaware. Fire up the pcDuino, open LXTerminal and type the following.

$ sudo apt-get install git cmake libboost-all-dev libusb-1.0-0-dev python-scitools portaudio19-dev -y
$ sudo apt-get install tcl8.5-dev tclx8.4-dev itcl3-dev tcl-tls tcllib automake cmake telnet git gcc make

RubyDucky included tcl-tclreadline in the installation list above, but I received an "unable to locate package" error when I tried installing it. Omitting the package didn't appear to cause any subsequent issues.

RTL_SDR


RTL-SDR is a very cheap software defined radio that uses a DVB-T TV tuner dongle based on the RTL2832U chipset. Three Linux hackers found that the signal I/O data could be accessed directly, which allowed the DVB-T TV tuner to be converted into a wideband software defined radio via a new software driver. This means that a cheap TV tuner USB dongle (like the one shown above) which uses the RTL2832U chip can be used as a computer based radio scanner. This opens up all sorts of opportunities. For other project ideas have a look at the RTL-SDR website.

Download RTL-SDR (assuming you're in ~/):

$ sudo git clone git://git.osmocom.org/rtl-sdr.git

Install RTL-SDR:

$ cd rtl-sdr/
$ sudo mkdir build
$ cd build
$ sudo cmake ../
$ sudo make
$ sudo make install
$ cd ~
$ sudo cp ~/rtl-sdr/rtl-sdr.rules /etc/udev/rules.d/
$ sudo ldconfig

The kernel that comes with Ubuntu already contains a DVB driver, which we don't want to use. To stop the conflicting Linux DVB-T driver from loading, we need to blacklist it.

$ cd /etc/modprobe.d/
$ sudo nano blacklist.conf

Then add the following line at the end of the file. You can either use the existing blacklist.conf file or create a new file, as long as it is in this directory and ends in .conf.

blacklist dvb_usb_rtl28xxu

At this point you can plug in your receiver dongle and reboot. Rebooting will allow our blacklisting to take effect.

Aviation transponder interrogation modes


You may see references to s-mode when reading about ADS-B plane tracking and sometimes s-mode is used interchangeably with ADS-B (which is not strictly correct). We will take a small detour at this point to explain what this is and how it relates to ADS-B. A transponder is a piece of kit on a plane to help air traffic controllers identify a particular aircraft's position and altitude on a radar screen. This helps them maintain separation and prevent collisions. There are 3 civilian transponder modes, called A, C and S.

Mode A - Following an interrogation request, the transponder broadcasts the configured transponder code (or "squawk code").  A separate type of response called "Ident" can be initiated from the airplane by pressing a button on the transponder control panel.

Mode C - Will send a pressure altitude response when interrogated.

Mode S - (Select) is to avoid over interrogation of the transponder (if there are many radars in busy areas) and to allow automatic collision avoidance. Mode S transponders are compatible with Mode A and Mode C. A Mode S transponder is required to implement ADS-B, but there are other ways to implement ADS-B.

In Australia, CASA is moving towards most aircraft requiring a Mode S transponder which is ADS-B capable, but this will take years to come into effect (particularly for VFR aircraft). All of the big jets certainly have it.


Dump1090_mr




Dump1090 is a Mode S decoder specifically designed for RTLSDR devices. It provides robust decoding of weak messages, and an embedded HTTP server that displays the currently detected aircraft on Google Maps. The 1090 refers to the 1090MHz frequency that the signals are broadcast on.

Dump1090_mr is a FlightAware fork, of Malcolm Robb's fork, of Salvatore Sanfilippo's dump1090 program. FlightAware uses it as an important element of PiAware (a Debian package for forwarding ADS-B data to FlightAware - more on this later). This is the version that we will download and install. Note that dump1090_mr is no longer available on the FlightAware GitHub repository but there is a copy here, which we will use. To build and install dump1090 and faup1090 and configure the system to start them automatically whenever the system boots, change to the ~/ directory and type:

$ git clone https://github.com/CTassisF/dump1090_mr.git
$ cd dump1090_mr/
$ make
$ make -f makefaup1090 all
$ sudo make -f makefaup1090 full-install
You can now test whether dump1090_mr is operational. This should show you a list of detected planes (see screenshot above).

$ dump1090 --interactive

Dump1090 will also show the position of detected planes on Google Maps. Open the Chromium browser and point it at http://127.0.0.1:8080 to see the display on your pcDuino.

You can also view this page from other computers on your LAN. To do this you will need the IP address of your pcDuino (type hostname -I on the command line). On the other computer you can then access the page via that IP address. So for example, my pcDuino IP address was 192.168.0.7 to view the dump1090 page I enter: http://192.168.0.7:8080 into the browser address bar.



FlightAware and PiAware


This next part is optional but there are benefits to being part of a world wide network of ADS-B base stations.

FlightAware is the world's largest flight tracking data company. Head over to their site and register so that you can add your ADS-B base station results to the worldwide collection of other operators. Make a note of your user name and password.

PiAware is a FlightAware client program that runs on a Raspberry Pi (or pcDuino!) to securely transmit dump1090 ADS-B and Mode S data to FlightAware.

I had some trouble getting PiAware to work on the pcDuino. The instructions provided by RubyDucky didn't work for me. Instead I used Piaware Debian Package Builder. The instructions below work for version 3.5.1 of PiAware.

To create the PiAware package, change to the ~/ directory and type:

$ sudo apt-get install build-essential debhelper librtlsdr-dev libusb-1.0-0-dev pkg-config tcl8.5-dev autoconf python3-dev python-virtualenv libz-dev git tclx8.4 tcllib tcl-tls itcl3
$ git clone https://github.com/flightaware/piaware_builder.git
$ cd ~/piaware_builder
$ ./sensible-build.sh wheezy
$ cd ~/piaware_builder/package-wheezy
$ dpkg-buildpackage -b
To install the PiAware package:

sudo dpkg -i ~/piaware_builder/piaware_3.5.1_armhf.deb

Reboot and then you can check that everything is working as it should by typing:

sudo piaware-status

This should display something like the screenshot below. Note that you no longer need to add your user name and password to the PiAware configuration file.



To link your new pcDuino ADS-B base station to your FlightAware account, log in to the FlightAware website and then go to the page to claim a new station.



FlightAware works out which base station is yours based on your IP address, so the computer you are using to claim the station needs to be on the same LAN as your base station and the station needs to be transmitting data to FlightAware. Wait 15 minutes or so after booting the pcDuino to make sure that FlightAware is receiving your data before trying to claim your station.

As a thank you from FlightAware, users sending ADS-B data receive the following:

  • Live data on flightaware.com (subject to standard data processing delay of up to two minutes)
  • Access to up-to-the-second live data received by the local device (accessible from the stats page with a local network connection)
  • Data from local device highlighted on FlightAware track logs
  • Detailed statistics on site performance
  • A free Enterprise Account (USD89.95/mo value)

So, there you have it, plane tracking on a pcDuino using Dump1090 and PiAware.