Thursday, December 29, 2011

First Bluetooth Data!

My Android app to read the PakTrakr data is complete, except for the actual reading of the battery data - kind of an important feature to get working!  I can pair the phone to the Bluetooth transmitter and open a connection in software, but can't get the code to read the data stream - nothing shows up.  I confirmed this with an Android Bluetooth testing app called Bluetooth SPP.  It will connect, but no data flows.

The Bluetooth transmitter has multiple switches and software settings and I tried every combination I could think of.  I know the PakTrakr serial port is working since I can plug it into the COM port of my laptop and see the data streaming through.  So the problem is the link between the PakTrakr serial cable and the Bluetooth transmitter.

I got a pointer from Steve Dolan, a potential user of my app with an awesome electric catamaran, to a similar project for PakTrakrs and Windows CE devices called EVDashboard.  The directions say to solder a wire from pin 4 (DTS) to pin 7 (RTS).  In desperation I did it this afternoon and BINGO!  I see the PakTrakr data flowing in the Bluetooth SPP app!  Thanks a million Steve!  You win 100 Internets!

Serial ports, formally known as RS-232, are a 40-year old technology with most of the behaviour shrouded in mythology and magic.  I believe this fix has something to do with constantly signaling that data is ready to flow.  I don't really care why this works, but it does, so I can move forward by finalizing the data reading and handling in the app.  I hope Ken Hall will offer a USB connector or a native Bluetooth solution so developers and users don't have to go through this pain.

Here are the components of the PakTrakr - Serial Cable - Gender Changer - Bluetooth Transmitter - Android phone data flow.  I can't support any other combination of parts or settings, unless you prove it and I can easily recreate it.  I'd love to avoid soldering the wire so anything that avoids that is greatly appreciated.
  • Buy a "Serial Bluetooth Adapter" from
    • Note that the IOGear Serial to Bluetooth unit is popular but I wasn't able to find a supplier and have no experience or advice on using it.
  • Set the following switches on the Serial Bluetooth Adapter
    • DCE - DTE switch to DTE (Data Terminal Equipment)
    • N/G - G switch to N/G (Non-Group)
    • S - M switch to S (Slave)
  • Buy a DB9 Male-To-Male gender changing adapter from Radio Shack
  • Gently pop the two sides of the PakTrakr serial cable connector apart
  • Solder a single small wire into the PakTrakr serial port circuit board as shown in the picture below.  This will connect Pin 4 (DTR) to Pin 7 (RTS).  We benefit from the Pin 4 circuit coming through the circuit board to the leg of the chip, and just jumper from there to the connector's Pin 7.  If you aren't confident with soldering the wire, contact me and we can work something out.

Here's a closeup of the jumper in place.  The angle is deceiving - it comes up from the pin of the chip and loops back down to Pin 7 - it's not touching the next pin on the connector.

Snap the two sides of the connector back together again.  Put the three parts together into a sandwich.  I don't trust the ridiculously tiny and hard to turn screws built into the parts, so I used two small zip-ties to hold the three pieces together, then two more around the assembly which pulls the zip-ties tighter and locks everything together.  You should end up with something that looks like this.  Boy would a single cable with Bluetooth be a great PakTrakr option!

Place this assembly into the vehicle and run power to it, and set the power switch appropriately.  I used the USB hub I installed earlier to drive power to it with the supplied USB-to-MiniUSB cable.

When you run the app, you'll see the blue Status LED flash then go solid once the Android phone is paired.  More info to come once I debug the data stream handling.