Monday, April 11, 2011

Deconstructing the AR.drone: Part 5

In this article I will describe some of the tools I've been using in my quest to understand the AR.drone. Some of them I had to build myself; that's part of the fun.

Radio Shack 12V Power Source

When it's engines aren't rotating, the 11.1 volt AR.drone battery lasts considerably longer than the nine to twelve minutes of flight time you typically get. But I wanted to spend as much time as necessary poking around in the drone's software without having to worry about losing power. Unable to find the battery connector locally, I bought the cheapest used battery I could find off EBay, snipped the connector off of it, and attached it to a 12V power supply I got from Radio Shack.

Important safety tip: I probably voided the warranty on my drone as soon as I hooked it up. But it seemed to work fine and it permitted me to work at a much more leisurely pace. If I'd had an expensive lab bench-quality power supply, I probably would have used that instead.

Saleae Logic Analyzer and AR.drone Detail

The AR.drone has an eight-pin (one pin missing) diagnostic connector accessible from its underside, covered with a rubber plug with a USB symbol on it. This shows my drone lying upside down with the plug removed and a logic analyzer hooked up to three of the pins.

Important safety tip: the AR.drone really doesn't like sitting at much of an angle and its software will complain bitterly and eventually refuse to do useful things. But placing it upside down was relevant to my interests.


This is Parrot's diagram describing the USB cable you can build that allows you to flash new software onto your drone without relying on the wireless network connection. What this diagram doesn't tell you is that pins 4 and 6, shown unconnected here, are receive data (a.k.a. RX, RD, RXD) and transmit data (a.k.a. TX, TD, TXD) respectively for a TTL-level serial port right off the drone's microprocessor. Pin 7 is ground just as with the USB cable. This serial port is configured to be a console terminal for the system.

Important safety tip: the serial port pins are transistor-transistor-logic (TTL) level, which on the drone's ARM-based Parrot P6 processor means something like zero to 3.3 volts. RS-232 peak signal levels vary widely, but logic values can range from -15 to 15 volts, and the standard requires that hardware tolerate voltages as high as 25 volts. Standard compliant RS-232 ports will not recognize the input signal levels of the drone's serial port, and peak RS-232 output voltages may damage the microprocessor in the drone. More on this below.


This is the USB flash cable I fabricated using the Parrot cable diagram above. I just bought a USB cable at Radio Shack, hunted down another cable that had the right eight-pin Molex connector on it, snipped the ends off both cables and did a bit of soldering. I've successfully used this cable, and some software tools developed by others, to flash my drone with the latest drone software from Parrot. I'll describe that process in a later article.

Molex Eight-Pin to DB9 Serial

This is a DB9 null-modem serial cable that I fabricated using the same approach as the USB cable, using the transmit and receive pins and the same ground pin as the USB cable. After using these cables for a bit it occurred to me that an even better approach would have been to build a single Y-cable with a the eight-pin Molex connector on one end and both a DB9 and a USB cable on the other end. That would have given me console access while reflashing my drone.

FTDI USB Serial to DB9 TTL Converter

This is a commercially available USB to 3.3 volt TTL DB9 adaptor that uses an IC from Future Technology Devices International, Limited (FTDI). It automatically does the conversion from the TTL signal level to USB serial. Otherwise it works just like any other USB serial adaptor.

This is not my first experience with FTDI products, and it won't be the last; I'm an FTDI fanboy. This cable uses one of their ICs embedded in the DB9 hood. This same or similar FTDI chip can be surface mounted in a embedded application. This is a huge win. First, you can use one of the mini or micro USB B connectors, which have a tiny footprint compared to other serial connector alternatives, as a console port for your application. Second, USB cables with the right connectors are easier to come by these days than serial cables, and it is impossible to hook them up wrong. Third and most importantly, the FTDI chip is powered not from your embedded application, but over the USB cable from your laptop or desktop; this means it doesn't draw power when it's not being used, and it's active and running long before your microprocessor comes out of reset and the boot loader configures and starts using the serial port. (A big Thank You to my hardware colleagues for introducing me to this.)

Important safety tip: this is the third such device I've tried on the AR.drone, and is the only one that has worked, which it did flawlessly. The others, made by companies I'd never heard of, were crap. (This is in fact the reason for the long pause between articles on this project.)

Saelae Logic with HP 110 Mini Netbook

It may sound like overkill, but I used a logic analyzer to make sure I had the pins right on the serial console port. But at around US$150 for an eight channel logic analyzer, that you can fit in your laptop bag, with a 24MHz sampling rate and serial decoders, doing so was kind of a no-brainer. I used a Saleae Logic, one of many USB-connected logic analyzer pods and software packages used in conjunction with a laptop. This is the Logic pod hooked up to my little HP 110 Mini netbook running the Logic software.

Saleae Logic Case

Saleae Logic Contents

Here is the nice zippered case (complete with cat hair, I now notice) that the Logic comes in, and its contents, along with my little key ring pocket knife just for scale. The Logic pod is about one inch or so square and is shown here with a company property sticker on it that almost covers the entire unit.

Saleae Logic Analyzer and AR.drone Serial Decode

This is a screen snapshot of the actual hexadecimal serial decode when the Logic was hooked up to the AR.drone while the drone was booting. It captured part of a "BMI Write Memory" message.

Radio Shack Digital Multimeter

When you're building cables it pays to check voltages and continuity before committing yourself to your soldering. I use a Radio Shack digital multimeter. It's probably the slowest reading digital multimeter I've ever used. But it's also a fraction of the price of the nice lab bench-quality units I've used in the past, and otherwise seems to work fine.

WESD51 Soldering Iron

If you're going to solder, particularly if you're going to solder digital components (as I did when adding an expansion connector to my Beagle Board), a quality soldering iron is an absolute must. And it'll make cables too. This is a Weller WESD51 Digital Soldering Station with digital temperature control. I really like the fact that I can just dial in the recommended soldering temperature right from the manufacturer's data sheet, and the unit heats up in seconds.

Weller 6966C Electric Heat Gun

This is a Weller 6966C 250 Watt Industrial Heat Gun. It's overkill for use on shrink wrap when making cables. But it's ESD safe and gets hot enough to melt solder, so it is not one of Alton Brown's dreaded uni-taskers. Alton would also use it to brown the top of Creme Brulee.

There are also some tools in my AR.drone arsenal that I haven't quite needed yet, or which are more in the experimental stages.

Parrot AR.drone Tool Kit

Parrot sells a small tool kit with the specialized parts necessary to take the AR.drone apart and to replace parts like the propellers likely to be damaged during normal use. I'll be using these when I follow in other's footsteps and open the drone up to take a closer look at its digital components.

Field Service ESD Mat

For sure when I open the AR.drone up I'll be using a grounded Electro-Static Discharge (ESD) or anti-static mat and wrist strap. I have a permanent one wired up on the computer desk where I do most of my poking around (you can see it in some of my other articles). But I like to keep this fold-up field service model in my big tool kit.

Vinyl Chess Board, IR LED, IR Viewer

In one of my more speculative side-projects, I'm experimenting with how the AR.drone uses its ventral camera to stabilize itself during hovering. Consensus opinion on the web is that it is using edge detection, so I am using a vinyl checker board as a high contrast take off pad. Others have suggested that sometimes the drone has problems seeing the take off pad in dim light, so I'm trying to illuminate it with a tiny button cell-powered flashlight whose LED emits in the infrared (IR). Finally, I'm using an IR night vision viewer to see the LED myself; remarkably, this viewer can be found in your local toy store. You may also be surprised to find, as I did, how many LEDs in objects around the house emit in the IR portion of the spectrum.

Next up: I describe how I flashed new software into my AR.drone over its diagnostic port via the USB cable by depending upon the kindness of strangers.


TekSuppTom said...

Do you recall where you found the molex connector?

Great write-up, btw :)

Chip Overclock said...

Oh, yes, that damned Molex connector.

Like me, you may have figured out that to do this right requires a $300 crimping tool. 30+ years ago I used to do stuff like this with a pair of needle nosed pliers. But the pins are smaller and more fragile, and my eyes are older. So no luck with that.

So I did the next best thing: I found a cable on the web that, while not perfect (it didn't use all the pins), it had enough of them that I could just order it, cut it off, and solder the stub onto a cable that I bought from Radio Shack and cut the end off of. That worked for both the USB cable and the serial cable, with a little jerry rigging of the index plug in the Molex connector.

Here's the info:

Diamond Systems Corporation
555 Ellis Street
Mountain View CA 94043 USA
1 650 810 2500 (had to order via phone)

P/N# 6981087
Cable, Poseidon Speakers
2mm 2x5 to tinned leads
$5 each, $25 minimum order

I ordered 5 and consumed 3, will use the other 2 making an "all-in-one" serial + USB cable.

Good luck!

TekSuppTom said...

I'm a little confused on the serial pinout. You mention pins 2 & 3, but 2 is declared as in use by the USB. Another article I found references pins 4 & 6 as the serial pins on the drone.

I know pins 2 & 3 are the correct RX/TX pins on a DB9 connector, is that from where the confusion stems?

Chip Overclock said...

I plead an inability to read my own notes (which I see included a hand-drawn picture of the connector with big arrows and labels pointing to the correct pins). Really, I have no excuse. I've made this correction in the article.


Anonymous said...

I've got an arduino uno and I would use it to send data into Ar Drone via serial port.
In order to connect the arduino uno to the serial port, Do I need a max232 or Can I simply connect
TX Arduino Uno -> Rx Ar Drone
RX Arduino Uno <- Tx Ar Drone?
Does someone has a schematic?
As reported in "The ATmega328 provides UART TTL (5V) serial communication". So, if I'm not mistaken, it's seems that also serial port on Ar Drone is TTL. Is this correct? In case of yes, I could connect them directly. Right?

Thanks in advance

Chip Overclock said...

I'm jealous. Arduino is on my list of things to play with, but haven't found the time yet.

If both are 5V TTL (I'd hook up a multimeter and make sure before I damaged something), then you should be able to hook up TX, RX, and GND (ground). I'd start with three wires and see what happens. I think you're on the right track.

Good luck!

Chip Overclock said...

Oh, and please report back on success or failure. And if you write about your project using the Arduino (which, for other readers, is an awesomely cool and very inexpensive microcontroller development board specifically for hobbyists), please pass along a URL here as a comment. I'd enjoy reading about your work. Stuff like this thrills me!

TekSuppTom said...

I just picked up a couple of the FTDI TTL-232R-3V3-WE cables, some Molex 051110-0851 Milli-Grid connectors, and the 50394-8052 terminals, in an attempt to make a one-piece cable for the drone serial port. It was actually much easier than I thought, even without the $300 crimp-tool.

I'm sure I'll get better at it as I do more, but my first try worked well. The cable has pre-tinned wires, so my next attempt at the cable will include a bit of time with a soldering iron once I have the wires securely clamped into the terminals.

Here's a pic of the finished cable:

Thanks for all of the great work, I learned a lot by reading through your entries regarding the drone.

Chip Overclock said...

I am delighted to hear it! Please keep me posted as you continue to work on the AR.drone. (If you write about it elsewhere on the web, feel free to post a URL in a comment.)

I'm guessing you have steadier hands and keener eyes than I do. (At my advanced age, that would pretty much be true of everyone.) I remember doing this kind of thing way back in my college days decades ago. I tried your route and managed to destroy several terminals and connectors before I went with Plan B.

Building an all in one cable is still in my list of things to do.