Friday, March 12, 2010

Talk to 'The Judge'

This should have been a really simple project, maybe an hour max. It really should not have taken all last Sunday afternoon, if I had just remembered one key fact....
Click to view full picture
I've been involved in putting on the annual Pinewood Derby for the Novi Girl Scouts for the last 7 years or so, and I did a few years of Cub Scout Derbys before that. I'm the Bernie Ecclestone of Novi Pinewood. Our current setup is a 4 lane BestTrack, with The Judge race timing hardware (above) and Grand Prix Manager software. This combintation that works great, except for one small issue....

Back when I started doing Pinewood Derbys, every computer had at least one serial port available for connecting the race timing hardware to the computer. But now it's 10 years later. The timing hardware still uses serial communications, but serial ports are pretty rare especially on laptops. Trying to scrounge up a computer with a serial port, or a USB-Serial converter in the week or so before the race was getting to be a pain. I wanted to put together something that would stay with the track, and I had an idea.



I've used various FTDI breakout boards from Sparkfun for Arduino projects. They're cheap, small. and, more importantly, I had an extra FT232RL in my parts box. At $15, they're $20-$30 cheaper than a USB-Serial from Best Buy or Radio Shack. It's also small enough to build right onto The Judge's Junction Box (see photo below). I could build it right into the track, put the driver software on a USB stick to stay with the track. Problem solved. And since the DB9 connector on the Junction Box got ripped out last year when someone stepped on the serial cable, I didn't even have to remove anything - just solder TX, RX, and ground connections between the Junction Box and the FT232RL Breakout Board, plug it in and start getting race results.






After the serial connections were made, I connected the USB cable, started up Windows Hyperterminal, selected the USB to Serial COM port, set the port to 9600/8/1/None per the New Directions website, put the batteries in 'The Judge', and went online with Hyperterminal. What should have been a readable status message from The Judge was just a garbled mess. Hmmm... 

The garbled characters look like a baud rate issue. Try Hyperterminal with various baudrates from 1200 up. Same results. Back to 9600 baud. And now I start to go into the wilderness for a couple hours.

The Judge runs on 3 AA batteries; 4.5 volts on a good day. The batteries check out OK, could it be that the logic level on The Judge isn't close enough to what the FTDI breakout board is expecting? The breakout board has a VCCIO pin to allow you to provide a different reference voltage, and the Junction Box exposes it's VCC for the magnetic switch supply - connecting those should.... dang not do it either!

Did I really get the wires connected correctly between the Junction Box and the FTDI breakout? Yep, looks good. In retrospect, this check should have been done sooner in the process, but since it was OK it didn't hurt me.

Maybe The Judge is messed up - it's been in the basement all year after all. Find a computer with a serial port, desolder the FTDI board, find a serial cable, hook up The Judge to the new computer... this is starting to take longer than I expected.... The serial port setup works, so the Judge is good, and it is communicating at 9600/8/1/None. Not a complete loss, since 2 variables (does the Judge work, and is the baud rate correct) have been eliminated.

Reconnect the FTDI breakout into the Junction Box wiring, this time on a breadboard so I can change wiring easier. Same results, a garbled mess.

At this point I get a little smarter and decide to use my Saleae Logic analyzer. Connect the Logic to the serial line, select the Asynchronous Serial analyzer in ASCII mode so I can see the characters. Start up The Judge and.... Logic sees junk too! Is it the FTDI messing things up? Disconnect the FTDI breakout, reconnect The Judge to the serial port on the computer. Start Hyperterminal and The Judge and.... Hyperterminal sees the diagnostic message, but Logic still sees junk! How is this possible?!

At this point I'm beginning to get a little nervous. It's Sunday afternoon, I've burned 3 or so hours on a one hour project and I'm stuck. The Pinewood Derby is Thursday evening. I've got a somewhat minor surgery scheduled for Tuesday and I'm not sure how much I'll be able to do on Tuesday and Wednesday. Time to rethink the process.

Change the logic analyzer to show hex instead of ASCII. Hmmm... now we're getting somewhere. The hex values of the junk characters are all 0x80 or higher (128 decimal). Regular ASCII characters should below 0x80 (128). If we invert that 0xB5, we get 0x4A. That's a 'J'! Inverting the next few bytes gives me 'u', 'd', 'g', and 'e'. I don't think this is a coincidence!

Being a software guy, I'm not sure I ever knew you could invert the sense of a serial line - low votage means 1, high voltage means 0. If I did, I had certainly forgotten it by last Sunday! But a little research on the FTDI site showed me how to make the FT232RL understand inverted logic levels coming from The Judge. Reset the FT232RL, reconnect everything, it works!

Moral of the story - go to the Logic Analyzer sooner. Oh, and don't leave checking out the hardware to the last possible minute.

Next year, maybe I'll convert everything to wireless with a couple of XBee modules....

Brian
The Black Dog

P.S. - the derby went off without a single hardware problem!

Wednesday, March 10, 2010

Yet another robotics blog

Although I'm a software developer by profession (over 30 years now?!), I've been working with hobby robotics/electronics since getting a Lego RCX set for "the kids" around 1999. The purpose of this blog is to document the projects I've been working on or pretty much anything I find interesting.

My interest in electronics really took off when I started mentoring teams for Lawrence Tech Robofest in 2005. Our teams started off with pretty much standard Lego RCX and Mindstorms NXT, but as we progressed we found we needed more sensors, and ended up developing some using the I2C interface available on the NXT. This year I started working with Frog Force 503 - Novi High for FIRST Robotics, helping the kids develop a 512 3 color LED cube and a Meccanum drive for a demonstration robot.

I've been attending GO-Tech meetings in Ann Arbor (a seriously eclectic group of people!) on and off for a couple of years, doing a lot of little projects with the Arduino development platform, getting plenty of little red boxes from Sparkfun, and reading MAKE magazine since the first issue.

Enough name dropping! Next post will document connecting 'The Judge' (a Pinewood Derby timer) to a USB port using a FTDI breakout board from Sparkfun (I have a feeling name-dropping will be unavoidable for this blog...)

Brian
The Black Dog