Wednesday, May 29, 2013

Debugging on Linux

"Where can I look in my file system that shows errors and problems?"

Watch the log files!

On Ubuntu:
 $ sudo tail -f /var/log/syslog

or on Fedora:
$ sudo tail -f /var/log/messages

$ sudo tail -f /var/log/dmesg

The nice thing about Linux is that you can always see what is going on.  You need not poke around in the dark when looking for the cause of a problem.

Wednesday, May 22, 2013

UAE Vehicle Test

As an expat in the UAE, it doesn't make economic sense to buy a fancy new car if you have no idea how long you are going to be here.  My own vehicle is a young and sprightly 2004 Dodge Durango 5.7 litre V8, which does 0 to 100km/h in about 7s,  uses only 14 litres per 100km in fuel and cruises at 120km/h at slightly more than idle speed.

The Al Ain Traffic Department has a large test centre, driving school and registry, which is always overcrowded and getting a vehicle processed there can take half a day if all the Dust Devils are smiling kindly upon you.  This year, I went to a small test centre in Al Foah, a village on the outskirts of the city instead.

They open at 8am and I was first in line.  I had my car serviced at the dealer the week before, so I left the service papers on the front seat.  The test then took only a few minutes.

For the exhaust test, the vehicle is put on a dynamometer, but since the big Dodge is all wheel drive it always just climbs off the machine, so they test it at idle, which is probably not much use.

Inspection = 120 Dh
Insurance (3rd party UAE and Buraimi) = 750 Dh
Parking fine in Dubai = 100 Dh
Registration = 105 Dh

In by 8am and out 30 minutes later - probably less than the time I would have spent looking for parking at the main test centre and well worth the 15 minute drive to get there.

Scanner SMB Access

The company has a networked scanner which is configured to save scanned PDF documents on a MS Windows SMB share.

Hooking up from a Linux machine requires a domain name, user name, password and mount operation.   I need to scan things maybe once a month, so I don't want to bother with a permanent connection.

Here is a simple little script to handle this share on Fedora.  The script uses Zenity and Beesu to make it a little more user friendly.  You should replace the IP address of the scanner, YOURDOMAIN and myusername with your credentials.  You should also create the mount point /mnt/scan.
#! /bin/bash
pass=$(zenity --entry --title="Add an Entry" --text="WindowsPassword:" --entry-text "password" --hide-text)
beesu - mount -t cifs -o domain=YOURDOMAIN,username=myusername,password=$pass,rw,file_mode=0777,dir_mode=0777 // /mnt/scan
nautilus /mnt/scan
beesu - umount /mnt/scan

The rw, file_mode and dir_mode parameters ensure that while root does the mounting, a common user will get read and write access to the mounted share.

This script will ask for your Windows and Root passwords, mount the share and open a Nautilus file browser.  You can then do what you want and when you close Nautilus, it will unmount the share.

Another upshot of this is that if you have a virtual machine with Windows 7 Home edition, which Microsoft deliberately crippled so that it cannot access Domain services, then all you need to do is mount the share with Linux and then use Virtualbox Devices, Shared Folders, to connect to it!

La voila!

Virtualbox with Ubuntu and Xubuntu

It has been a few years since I last used Ubuntu Linux and since some of my students are using it, I decided to install it on Virtualbox and see what the fuss is all about.  Ubuntu used to be quite a nice system, but it seems to have regressed terribly and is now almost unusably slow and clunky due to the Unity/Gnome desktop.

My favourite desktop system is KDE.  I like my rotating desktop cube and wobbly windows, but on slower systems, I use the simpler XFCE or LXDE.  Gnome/Unity however, is the Win8 of Linux at this stage of its development and is much unloved.

Security Problems

The Ubuntu desktop also presents a serious security risk in its default configuration, since the Lens sends all your local and remote search activities to various third parties.  Ubuntu now is really a spyware system just like that other legacy system when it is infected with viruses and junkware. The only difference is that in Ubuntu, the spyware is deliberately installed, though it can be deactivated with a dozen or so clicks of the mouse, it doesn't deactivate everything.  The result is that Ubuntu is a total no-no for government users, lawyers, doctors and the like.  Anybody that needs FIPS compliance, should use Red Hat Fedora Linux.

However, Linux is Linux is Linux - so it can be fixed without too much trauma, by switching to the XFCE desktop.

Of course, you can avoid half the hassle by installing Xubuntu to begin with and not Ubuntu, but most people select the default download and then they are disappointed with the performance and don't know how to fix it.  So here, I deliberately use the bad version and then repair it.

Get It

Go to and download the latest and greatest version of Ubuntu desktop edition.

Make a VM

Run Virtualbox and make a new VM.  Select Ubuntu Linux for the type, size the disk as 30GB and allocate 1GB RAM to it.  Boot up and select the ISO image file you downloaded from Canonical and let it go with all the defaults.


Once you have Ubuntu up and running and experience its sluggishness, you'll be permanently cured of this  version of Linux in no time.

Click the lens at the top left, search for a 'terminal' and install some fixes:
$ sudo apt-get install linux-headers-$(uname -r) build-essential xubuntu-desktop

That lot will ensure that you can use the system for software development as well.

Restart Using XFCE

Restart the VM:
$ sudo reboot

 When you log in, select the XFCE desktop in the round little thingy to the right of your user name.

Your system will now run a hundred times faster.

Install Guest Additions

To make it work properly, you also need to install the guest additions, so that you can resize the screen, make the mouse move smoothly, share files with the host and make sound work.

Click on the top Virtualbox menu bar Devices and Install Guest Additions.  Nothing much will happen.  Open the File System browser and click VBoxAdditions.  Right click and select Open Terminal Here.  Run the file:
$ sudo ./VBoxL[tab] 

Now when you reboot the VM again, things should be honky dory.

Browser Security

While I am on the security complaints topic, you can make your internet browsing a lot more pleasant by installing a couple of add-ons called Adblock Plus and Ghostery.  These two will make your internet browsing much faster and will suppress the worst of the web. These are available for most browsers, even for Google Chrome.  In Firefox, click on Tools, Add-ons and search for them.  In Chrome, click the Spanner, then Tools, Extensions.  It is a similar process in other browsers.

Other VM Optimizations

In a Virtual Machine, you should also disable power management and the screen saver, since they will cause trouble and you already got these features on your host.


If the Virtualbox guest additions process complains that it cannot find the correct kernel headers even though you know that you installed them and other things compile just fine, then you may need to upgrade Virtualbox itself on the host machine.  The error message is a maybe a little subtle - it cannot find the correct kernel headers, so you got to upgrade.

La voila!


Tuesday, May 21, 2013

Compile a Moxa Serial Widget Device Driver on Ubuntu Linux

We needed a Linux serial device driver for the Moxa U1250 series multi-port USB to Serial adaptors.  The released driver on the Moxa web site only works with Ubuntu Linux up to version 11 and with Fedora Linux up to version 16, so you need a Virtual Machine of the right version for it.  Otherwise, ask Moxa support for a Beta version of their driver for the newer kernels.

Ubuntu Software Installer

There are basically three Linux development streams:
  • Slackware
  • Debian 
  • Red Hat
The Ubuntu distribution is part of the Debian family.
The Fedora distribution is part of the Red Hat family.

Each of these families has their own incompatible code packaging systems.  Each distribution has its own set of file servers and when you install a system, it will be configured to look at those servers for updates.  These servers are distributed all over the world at universities and large corporations.  Because they are perfect copies of each other, the servers are also known as 'mirrors'.

The update program used by Ubuntu is known as 'apt'.  To get a program from a mirror, you run a program called 'apt-get'.

To install stuff, you need super user (administrator) privileges.  You can elevate your permissions temporarily using a program called 'sudo' (set user do).  So therefore the command to get all system updates is:
$ sudo apt-get update

Similarly, to install a program, you would run:
$ sudo apt-get install programname

Apt keeps a database of installation data, so you can also use apt to remove a program, or upgrade an installed program to the latest version.  The graphical software wizard, is simply a nice looking front end for apt.

Low level programs such as device drivers, are operating system kernel modules that can be loaded and unloaded at run time - on the fly.  When you plug a new thing in, the system will automatically load the required driver if it is available,  For that to work, the driver needs to match your running kernel exactly. 

The Linux system is changing all the time.  It has a very rapid development cycle.  Therefore, most drivers are distributed as C source code and you have to compile it on your system before you can use it.

Software Development Tools

To do software development and compile device drivers for example, you need GCC (the GNU Compiler Collection) and the interface definition for your kernel version (the kernel header files).  These can be installed using apt. The command is something like:
$ sudo apt-get install linux-headers(versionnumber)
$ sudo apt-get install build-essential

The kernel version number can be displayed with the 'uname' command.  The command 'uname -a' will show all version parameters of the current running kernel.  The command 'uname -r' will show only the version number, so one can make a generic install command like this:
$ sudo apt-get install linux-headers-$(uname -r) build-essential

Compile and Install

After the above, one can download and compile the U1250 Linux device driver from (or email their support guys for a Beta version).

Compile and installation of any program usually follows a simple recipe, explained in the README and INSTALL files that come with each package.  The recipe is usually the same, but once in a blue moon it isn't, so it is always a good idea to read the readme file and in this case it is indeed different from the norm:
$ make driver_make

 Ubuntu 12.04.2 LTS 
 \l 3.5.0-23-generic
 MOXA UPort 1200/1400/1600 series driver ver 1.2.5
 Release Date: 2013/04/03

If and only if there are no errors above:
$ sudo make install
[sudo] password for herman: 
 Ubuntu 12.04.2 LTS 
 \l 3.5.0-23-generic
 MOXA UPort 1200/1400/1600 series driver ver 1.2.5
 Release Date: 2013/04/03
 MOXA UPort 1200/1400/1600 series driver ver 1.2.5 installed successfully.

Configure the Port

Now, when you plug the Moxa U1250 in, it should show up in /dev as ttyMXUSB0 and ttyMXUSB1.

Configure the device for RS232:
# setserial /dev/ttyMXUSB0 port 0x0

or for RS422:

# setserial /dev/ttyMXUSB0 port 0x2

and for RS485 2-wire:

# setserial /dev/ttyMXUSB0 port 0x1

It is all explained in the readme.txt file and I recommend you use it with Cutecom.

La voila.

USB Serial Device With Unknown IDs

I got a new USB serial widget, but although it uses a regular FTDI chip, the manufacturer thought it wise to change the IDs, so that the Linux system doesn't recognize it.  Yes, I am glaring at you SerialComm...

One can work around that by forcing the vendor and device IDs when the driver is loaded.

For example:
Plug the offending USB serial adaptor in.
$ dmesg

Note the Vendor and Device IDs:
[452076.573062] usb 2-1.2: New USB device found, idVendor=0403, idProduct=6001

Now load the module:
# modprobe usbserial vendor=0x0403 product=0x6001

and now it should show up in /dev:
$ ls /dev/ttyU*

Turn that into a little script in /usr/local/bin for next time and la voila!

Saturday, May 18, 2013

ArduPlane Smoke Test

Where are we?

The first step is just to be sure everything runs.

Mission Planner test

Plug the computer into the USB port of the AP.  Enable the FTDI USB device in the Windows VM.  The AP should power up like a Yuletide tree.  Let it go online and download the latest AP firmware.

If you carry your whole setup (minus the main wing) into your garden and if you have WiFi access out there, then the GPS, magnetometer and gyros should activate and after a while you should see your location on the map and wherever you went, that is where you are.

If you live in a desert like me, then you may not want to stay out there too long, but most people could carry on doing the rest of the tests on a patio table - all you need is power, WiFi and coffee.

So now you can see where that is going - either you need to pair a smart phone with your laptop PC or get a cell phone data modem of sorts for use out at the airfield.  This isn't a cheap hobby.

Manual Override

Initially, you need to fly and land the plane manually and will only engage the AP for brief periods till you are sure that it is calibrated right and won't flip the plane over, or fly away into the sunset, so the override switch on IN 8 on the AP is all important.

If you have a 6 channel RC set and you selected the Gear switch on channel 5, then it should be on the left of the transmitter, while the Flaps switch should be on the right.  I am right handed, so I prefer using the Flaps switch for the best reaction time.

On my system, Manual is in the Up position.

Smoke Test

Ensure that the plane is tied down securely.  It is also advisable to remove the propellor for the very first test.
  • Unplug the USB cable.  
  • Ensure that the BOB PSU is plugged in.  
  • Push the left hand throttle lever forward. 
  • Turn on the transmitter.  
  • Turn off the motor safety switch.  
  • Turn on the AV power switch.
  • Everything should light up like a Yuletide tree.
Nothing else should happen.

Move the right hand elevator and left hand rudder levers.

If they move the wrong way, then reverse the action in the transmitter setup and save it for your model name.  Any half decent transmitter can save the setup for multiple models.

If nothing happens, flip the Manual Override switch (Flaps on right) and try again.  Once working, mark the Manual position clearly.  On my system, Manual is in the Up position.

Now, check that there are no papers lying about and briefly try to run the motor a little bit with the left hand throttle lever.  (I once had the prop on and it tried to empty a box of tissues for me, which was rather spectacular).

If you see smoke, well, then you can see exactly what is wrong.

If all is well, then you should run the motor at half throttle while monitoring the battery and time how long it takes to run down.

Battery Performance

The Tornado 3400 NiMH battery performance is interesting.  I wired a multi-meter to the battery and played with the system on the bench:
  • At full charge, the battery measured 9.64V with no load.
  • With the motor running at half throttle, it ran down to 7.7V in about 4 minutes.  
  • At the 7.8V point the motor revs dropped suddenly and I closed the throttle.
  • With the motor turned off, the battery recovered to 9.03V.
  • Playing with the servos had no discernable effect on the battery.  They drew very little power.
  • Even though the battery was now clearly depleted, the motor could still run at 5 clicks of the throttle for several one minute periods.
Therefore, with careful motor use, it appears that the system can safely run for 20 minutes.  Just gliding, the system can run for a very long time and with the motor off, the electronics can safely keep running on a flat battery and glide home.

During this half hour of testing, the transmitter battery went from 11.1V to 10.3V.

Radio Interference

During the above tests, I noticed that the transmitter interfered with my Kindle WiFi connection and my online Prague Radio Gothic reception would drop out annoyingly (Abu Dhabi Classic is the strongest radio signal in Al Ain and that gets really tiring after a few years...).  Although the RC system kept working, it is probably a good idea not to use WiFi or Bluetooth devices while flying.


Once the whole system is under control, you can mount the propellor and go and fly the plane to set the trim values on the transmitter.  After that, you can calibrate the AP

Time for some nealkohol pivo...


Friday, May 17, 2013

ArduPlane Mission Planner Installation

I love it when a plane comes together...

Getting the ArduPlane autopilot installed in a plane is quite intricate and getting the Mission Planner software to work is also an adventure all by itself, hence this little guide.


The Mission Planner software is a legacy 'Java' application created with the Microsoft DotNet toolkit.

Assuming that you have a real computer - Linux or Mac - you would need a virtualizer to run some version of Windows.  I always use Windows XP for virtual machines, since I own about a dozen useless licenses for it and it is light and fast on a VM.

First get Virtualbox from Oracle for your machine

Make a VM and install your favourite least hated version of Windows, then select Guest Additions from the Devices menu and install it in Windows, then restart the VM.  Your screen should now resize and the mouse and copy/paste buffer should work transparently with UNIX.


Getting DotNet installed on XP is not easy.  Download the following from Microsoft:

  • MSI installer.
  • Dotnet Framework 2, 3, 3.5 and 4.

Reboot umpteen times - at least booting is very fast on a VM.


The FTDI installer may be in a zip file.

Reboot umpteen times again - the pleasure of the Windows user experience.

I machined a neat hole in the fuselage under the wing, opposite the AP USB connector with a Dremel, so that I can plug the computer in without hassle.  Then I remembered to add some foam tape under the AP to isolate the accelerometers from the engine vibration and had to make the hole bigger - sigh.

Mission Planner

Finally, you can install Mission Planner from

Be sure that the motor is switched OFF when you plug the USB cord in, since USB will power up the AP electronics for you and if the transmitter is off, depending on what else you got plugged in, then the motor may start up at full speed unexpectedly.  There is a safety diode in the AP to prevent it from powering the receiver and servos, but I don't know how you wired your things up.

La voila!

Next up - smoke test...


RC Electric Glider Autopilot Conversion


This document provides a brief description of the conversion of a RC plane to autonomous control with an Ardupilot ( system.

I started this project about 1 1/2 years ago and worked on it off and on.  My main problem was keeping track of the details, hence this guide.  If you have the time or inclination, then you can finish it off in a week!

I chose a large, positively stable RC Electric Glider from Sussex Model Centre ( in the UK. The plane has a 2 meter wingspan with 3 degrees of dihedral and swept up wing tips.

A positively stable glider will fly on its own even when the electronics are dead and it will eventually land all by itself too.  It will simply glide into the ground and ground effect will make it flair.  So if you can find it and there are not too many trees about, then you should always be able to recover your plane intact.  I prefer having a plane that can fly more than once.

The control surfaces consist of a rudder and elevator only. On a plane with this much sweep up, ailerons are not needed. When one lets go of the controls and cuts the engine, the plane should fly itself, level out and glide at a shallow slope. The large wing area allows the plane to carry some extra weight while still maintaining a good glide capability. This makes it relatively easy to do an autonomous conversion and fit fun sensors, such as a camera with a radio down link (an old Android phone will do!).

RC Electronics

The normal airborne RC schematic is shown below.

The normal RC setup is quite simple and consists of two batteries, a RC receiver, two servos, an Engine Speed Controller (ESC) and a powerful electric motor.

RC Receiver

I prefer Futaba RC gear.  It provides good value for money and works reliably.  The Futaba receiver is a very tiny little thing and is wired up as shown below:

Autopilot Electronics

The airborne RC/Autonomous schematic is shown below.

There are three main changes. Since a whole lot of electronics is added, the Receiver battery is removed to save weight. This requires a different Engine Speed Control or Switching Battery Eliminator Circuit (ESC/SBEC). The Ardupilot and associated electronics are added and the servos and throttle are rerouted, while the Flaps circuit is used as a failsafe/manual override switch.

DC-DC Convertor

An alternative solution is to keep the existing ESC and add a switch mode PSU, such as a Sparkfun BOB-09370, 6A, 0.59V to 5V, DC/DC convertor ( as shown below:

This little widget can be used to convert the 8.4V Motor Battery to 5V for the RC Receiver and servos, which will save the weight of an additional NiMH 4.8V receiver battery, but it will reduce the endurance somewhat.

The output voltage of this convertor is adjustable (the default output voltage is only 0.59V). It requires a 1k34, 0.5% precision resistor between the Trim and Gnd pins for a 5V output (alternatively use a 4k7 multi-turn trimpot for adjustment from 3V3 to 5V).

The ON/OFF input doesn't work – it is permanently on. The Power Good signal is also good for nothing and the SEQ pin is a very high voltage and not of any use either, so just put pins in Gnd, Vin and Vout, glue a trimpot to the bottom and ignore the rest.


Note that NiMH cells are 1.2V nominal (1.4V while charging) while LiPo cells are 4.2V nominal. Do not discharge NiMH below 1.1V per cell and LiPo below 3V per cell.

The Motor battery used by this glider is a 7 cell Tornado 3800 NiMH pack that provides 8.4V nominal, or 9.8V when fully charged and 7.7V when flat.

The receiver battery is a 4 cell NiMH Hi-Energy pack that provides 4.8V nominal. The above DC/DC convertor can be used to eliminate this battery to save some space and weight.

Note that NiMH cells self discharge very rapidly, losing 20% in the first day and 4% per day thereafter.  So you got to charge them each time before use.  From new, they will actually improve a bit during the first few charge/discharge cycles.


Full details on the Ardupilot is on the project Wiki (

My Ardupilot is a version 1.4 device with external magnetometer, GPS and Pitot sensors. The kit of parts is shown below:

On the version 1.4 board, three axis accelerometers and a pressure sensor are built in. The fully assembled unit (except for the magnetometer) is shown below:

The Magnetometer is mounted upside down behind the “No GPS!” connector on the blue board, as shown below. Add some tape to it as insulation against the other connector pins:

The GPS module plugs into the red board, as shown below. The red wire is on the outside:

Later models also integrate the magnetometer and GPS receiver, but otherwise the boards are much the same.

Put some insulation tape on the bottom of the GPS unit and after soldering the Magnetometer down, you can glue the GPS receiver down next to it on the Blue board using either hot glue (removable with a knife) or epoxy (never to be removed again). Take care not to cover the air pressure sensor with glue. The pressure sensor should instead be covered with a small sponge to protect it against blowing air from the propellor.

Note that it is useful to install the battery monitor resistors, even if you do not have a radio downlink, since it enables the Mission Planner to read the battery voltages when the USB lead is plugged into your computer.


The boards are labeled very well, considering the small space available, but it is difficult to determine how exactly to wire up the servos and receiver – a magnifying glass helps. The hookup is described in detail here ( and is summarized below.

Typically, the RC channel assignments are as follows:

RC Channel
APM Connector (v1.0)
APM Connector (v1.4)
Roll - Aileron
IN 0
IN 1
Pitch - Elevator
IN 1
IN 2
IN 2
IN 3
Yaw - Rudder
IN 3
IN 4
Landing Gear
IN 4
IN 5
Autopilot control (Flaps)
IN 7
IN 8

Note that RC 6 (Flaps) goes to IN 8 (AP Control). You could use anything with a switch on your RC transmitter, usually channel 5 or 6.

Also, a glider with a lot of dihedral, doesn't need ailerons, leaving channel 1 empty.
In a space constrained glider body, you need to make every wire exactly the right length, else the system may not fit. Also, every piece of wire is extra weight, which is another incentive to keep them all as short as possible. Two inch servo cables worked for me between the RC receiver and autopilot (Sparkfun has).

The only way that I could fit the parts into the glider body, was to slide it all in via the cockpit and then pack pieces of sponge around it, to keep the parts from moving around. A hard mounting frame of any sort just could not go in, so I gave up and cut up a bath sponge with scissors.

The complete hookup is described in the diagram below. Note that on the Engine Controller, the Brown wire is Ground, so I coloured it black with a marker pen to reduce confusion. If any wire colour codes are funny, check it out with a multi-meter!

Obviously the connector polarity is important.  On the 3-row connector, the ground (black) is always closest to the board edge.

On a test bench, power to the AP is supplied either via the USB connector (5V) or via two pins on the Red board (6V to 12V). If the available space is very narrow, as on a typical glider, then solder two power pins to the board and angle them inward at 45 degrees, instead of outward.

In the plane, the 5V power can also be supplied via the RC Receiver pins. So I simply plug the above mentioned Sparkfun BOB power supply into the RC Receiver position 7/B, which then powers the Servos and Auto Pilot.  Beware of the engine starting unexpectedly if the transmitter is off.

When mounting the things in the plane, it is important to point the IMU in the right direction, as shown below. The infamous No GPS connector must face the front:

If you install the autopilot in the cockpit, then the servo wires will be at the back, towards the servos mounted under the wing, thus keeping the wires short, as shown in the fuzzy picture below taken with my Mac webcam.  I made the test jig from a wood shelf kit and a cheap plastic spirit level that I got at Carrefour, to hold the plane horizontal in its flying position.  I'm still looking for a compass.

The battery is on the bottom, there is a piece of plywood above it, with the servos, PSU, RC Receiver and AP on top. In the cockpit there is the engine controller on the floor and the engine in the nose, with all wires as short as possible. One RC antenna is threaded to the back and the other to the front.

The AP board must be tied down immovably, otherwise the calibration could change while the plane is flying, causing the control system to do interesting maneuvers. You probably also don't want the battery to shift and change the Centre of Gravity while flying. A couple of rubber bands and some sponge can keep things in place.

Power up

The plane must be horizontal in its flying position and facing north, when the system is turned on.

Immediately after turn on, the IMU is calibrated, so you need to make a jig with a spirit level and a compass for the plane as in the picture above. Put some lead diving weights on the jig and provide straps to hold it. This is needed for static tests. You got to run the system, see how long the battery lasts and verify that everything keeps working for the duration of a mission.

You must turn the Transmitter on before turning on the plane electronics, otherwise the engine may start at full speed. If you hear the receiver Beep when you turn on, either the Throttle is wide open or the Transmitter is off – turn the plane off immediately or you may lose a finger in the propellor.

I installed two sliding switches on the side of the cockpit – one for the engine and one for the AP electronics. This way, I can run the AP with the motor in a safe position.

For the first few brief smoke tests (no more than a few seconds), I suggest that you remove the propellor from the engine for finger safety. However, do not run the engine without a load for extended periods.  If the magic smoke stays inside the electronics, then you can mount the propellor. Another old safety trick is to drop a small towel over the propellor - then if you accidentally move the throttle, it will just go 'whomp' with no damage done.

There is a safety diode in the AP.  The USB connector will only power the AP, not the receiver or servos.  However, if you plug the BOB PSU into the RC receiver, then it will power the Servos and AP through the connected wires.

Mission Planner

The next problem is the mission planner software.  It is unfortunately a legacy Windows DotNet application and takes some effort to install.  I got it to work on Virtualbox on Windows XP.

Mission Planner connects via USB to the AP.  It will check the board version and upload the correct firmware.   So that is a problem worthy of another post.

La voila! Enjoy the flight.


Monday, May 13, 2013

Using dd on a Mac to copy an ISO file

I downloaded a Fedora ISO file and needed to copy it to a USB memory stick to install on another machine, but the Mac user interface is just enough different from Linux to be annoying:

Hermans-MacBook-Pro:Downloads herman$ sudo dd if=Fedora-18-i686-Live-LXDE.iso of=/dev/disk2
dd: /dev/disk2: Resource busy

Now what?  Some googling later...

Hermans-MacBook-Pro:Downloads herman$ sudo diskutil umountDisk /dev/disk2
Unmount of all volumes on disk2 was successful

Of course, you can also use Disk Utility to unmount the thing.
Hermans-MacBook-Pro:Downloads herman$ sudo dd if=Fedora-18-i686-Live-LXDE.iso of=/dev/disk2

Even Data Definition is different and Ctrl-T will show the dd progress as records in/out.

Raspberry Pi SD Card Images

After copying a RPi image to a SD card, it may be necessary to edit the /etc/rc.local or wpa_supplicant.conf file on the SD card.  To do that, you need to mount the SD card in a Linux virtual machine, since a Mac cannot handle the ext4 file system.  However, when I launched a VM, I found that it cannot connect to the SD card - it isn't visible to the virtual machine.

Solving this is a bit of a headache.  What I eventually did, was to create a special vmdk file that points to the SD card device, then mounted that special virtual disk file in the Linux VM, as described below.

On the Mac, plug the SD card in and run the Disk Utility and unmount the SD card, if it is mounted.  You may need to do this multiple times, so keep it open.

Go to the place where you keep your Virtualbox vmdk files, open a terminal and make a special virtual disk file:
$ sudo VboxManage internalcommands createrawvmdk -filename ./sdcard.vmdk -rawdisk /dev/disk2
$ sudo chmod 777 /dev/disk2
$ sudo chmod 777 ./sdcard.vmdk

If you get a busy error, unmount it again (and again...) as shown up above.

Now open VirtualBox Manager and in the SATA Controller, add an existing hard drive and choose the sdcard.vmdk file.

Launch the Linux virtual machine and mount the rootfs partition /dev/sdb2.  If you are lucky, it will be mounted automatically by the desktop environment.  Now you can edit files on the SD card.

After going through the above, I thought that it may be easier to mount the original ISO image in a Linux VM and fix it, before writing it to the SD card - next time!

Sunday, May 12, 2013

Virtualbox file share permission problem

Virtualbox (by Oracle) is my favourite virtualizer and was the first thing I installed on my new Mac, so that I can run Fedora Linux on it.  A Mac is great for common users and I would advise anyone to buy a Mac instead of that other sad legacy system that always gets riddled with viruses and malware.

However, I am an engineer and need to be able to test and debug things and write low level programs - I am always rooting around in the weeds and need Linux for that.

So I wanted to share my Mac Documents directory.  After some sleuthing I found that it gets mounted as /media/sf_Documents, but I then got a permission problem when I tried to access it.

The solution is to add yourself to the vboxsf group and then reboot the virtual machine:
$ su -
# usermod -a -G vboxsf herman

Just logging out and loggin in again is not sufficient.

Macbook Pro file browser replacement

My little Lenovo netbook died of old age, so I picked up one of the new Apple Macbooks with a so called retina display.  The high resolution screen is absolutely worth the money.

My main gripe with a Mac is the horrid excuse for a file browser called Finder.  A file browser that doesn't allow you to browse all files, is really not a terribly bright idea - it doesn't do much of anything really and is quite useless.  Even Microsoft Windows Explorer works better than Finder.

Fortunately some kind souls have coded up a few alternatives including one called Macintosh Explorer (by Rage).  You can get it here:

Mac Explorer is free and it works - a good combination of features - although I like the Linux file browsers such as Dolphin and Thunar better.

Another well kept secret, is to extend the Finder with a plug-in called Xtrafinder (by Tran Ky Nam), which makes Finder a whole lot more useful:

The Mac keyboard is a bit crummy - the Carriage Return key is too small and there is no Delete key, only a Backspace. The Ctrl-D combination usually works as delete.  The X-Windows highlight and middle click also doesn't work - instead it is highlight drag and drop, but you can only drag and drop to something that is already visible.  Some mindless things to get used to again - fortunately there is a configuration button for the mouse to make it scroll the 'correct' way.

The desktop user experience of a Mac is OK, it just feels a bit 20th century.  I prefer KDE - I want my virtual desktops and wobbly windows!  Yeah, I know, "Small Things..."

Saturday, May 4, 2013

SSH Brute Force Attacks

Years ago, some vagrant made a SSH password brute forcer and my servers got around 10,000 SSH login attempts per hour. I fixed it with an iptables rate limit rule:
iptables -A INPUT -p tcp --dport 22 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m limit --limit 3/min --limit-burst 3 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j DROP

Airport Web Browser Security

Contrary to the popular perception, the world is not round - it is a giant polygon and my work has taken me to many a strange corner.

Travelling with a laptop computer is a risky business.  They are easily stolen and the financial cost pales into insignificance compared to the inconvenience of having to set up a new one again after having lost all your contacts and other keyboard kreature komforts.

On a Linux system, you absolutely must use 'full disk encryption'.  This is so easy to set up, that there is no excuse not to.  It only protects your data when at rest - when the machine is turned off, but your ordinary perp will try to log in, won't get past your 16 character password, then reboot and promptly get stuck at your 20 character encryption password (OK not everyone is as paranoid as me, but you should use at least 12 characters for a password).  After a few days, the machine will be re-installed with Windows XP and sold on Ebay, while your personal and financial data will be safely in data heaven.

While travelling to a distant corner of the globe, you will necessarily spend lots of time in Airports, using captive portals and coffee shop WiFi network connections.  These things are almost certainly bugged by at least three different organizations in the interest of national curiosity, but what bothers me more are my fellow bored geeks snooping my data over WiFi using things like Kismet or Firesheep (

One simple way to befuddle the snoops, or wiggle through a restrictive local firewall, is The Onion Router.  TOR provides multiple layers of SSL between you and a seemingly randomly chosen end point.  That still leaves you somewhat at the mercy of the end point operator (who can see your traffic but probably doesn't know who you are), but I suspect that a goodly number of the TOR endpoints are run by friendly police forces the world over, so you are probably quite safe:

The browser bundle is a super easy way to get going with TOR.  On a reasonably modern laptop machine it is quite fast enough.  Give it a go. 

No more printing woes

Linux uses the CUPS printing system (provided by Apple). Usually, one can just plug a printer into a Linux machine and it will be instantly recognized.  This is so much easier than downloading and installing drivers on a legacy system.

On the odd occasion that something is amiss, printing a document from the command line can pinpoint the issue. When you execute a command manually, you can see the error messages and then google them, or look for a solution on

Use lp or lpr to send a document to the default printer:
$ lp filename

or to print to a specific printer:
$  lp -d printer filename

Sometimes it is easier to send a file directly to a printer than to launch an editor just to open and print a file, for example:
$ lp -o landscape -o fit-to-page -o media=Letter filename.jpg

CUPS understands many file types directly, such as PDF, postscript, text, or pictures!

Sometimes, when you are busy installing a new machine, you may wish to print something, but the printer may not be installed yet.  Try sending the job to a different machine:
$ lp -h 192.168.x.y filename.pdf

La voila!

Friday, May 3, 2013

RS422 to RS485 Adaptor

I got a radio with a RS422 port and got to hook up a camera with a RS485 port.  Electrically, the two are much the same, but RS422 is four wire, full duplex and RS485 is two wire half duplex.

On the RS485 side, the transmitter only drives the bus while sending a byte.  It is enabled at the start bit and disabled after the stop bit, allowing another device to send.  (BTW, Maxim makes nice little devices that will do this automatically).

On the RS422 side, the transmitter is permanently enabled.  Therefore, I cannot simply hook the Tx+ to Rx+ and Tx- to Rx-, since then the transmitter will permanently clash with the RS485 transmitter.

I need to somehow disable the RS422 transmitter when it is idle, to relinquish the bus and allow the other side to respond.

Looking at it a little more carefully, the RS422 transmitter uses a push-pull output stage, so one transistor is always on and the Tx+ line idles high, while the Tx- line idles low.

The trick therefore is to use two series diodes, to disable half of each push pull circuit and then use bias resistors to pull the lines into the idle condition, as shown in the sketch below (thanks for the tip Mike).

If necessary, add a 5V voltage regulator and Bob's your Uncle.

The purpose of C3, is to prevent a constant DC current flowing and reduce the power consumption, while the bus is still AC terminated into 120 Ohm.

Depending on the transceivers, an even simpler circuit can be used (thanks Latifa).  This one actually performed best in Latifa's tests and it uses only 3 resistors.

The whole circuit will fit inside the back shell of a DE9 or DB15 connector.

La voila!