Teensy++ Controller Board Adventures

I placed an order for a set of Teensy++ parts from PJRC quite some time ago with the understanding that it was out of stock and would likely take a least a couple of months to fill the order. That’s exactly what happened, and I ended up receiving the parts sometime in December. Because of other stuff I was working on both related and unrelated to the Keyglove, I wasn’t able to find time to really make use of the new parts until the middle of January.

Now that I’ve had a chance to, though, all I can say is: the Teensy++ is a really awesome device!

You can read up on whatever Teensy-related info you care to find using the link above, but I’ll just go into why it’s great for Keyglove purposes. It uses an Atmel AT90USB1286 for its core, and is far, far smaller than an Arduino Mega. In short, it’s glove-mountable and it can run as a native USB human input device (HID), which completely eliminates the need for extra hardware or software emulation. Because of this board (and the decline of PS/2 as a common interface), I’ve indefinitely stopped working on the PS/2 protocol. Making USB work involved almost no effort, and it eliminated the need for an intermediary driver for testing. It also means I don’t need to use my cool Processing sketch, but that’s okay with me since it also means that it’s actually working natively.

The Teensy’s physical construction makes it perfect for placing on a solderless breadboard, and that’s exactly what I’ve done. In contrast to the Arduino Mega, which has its pins broken out in female headers, the Teensy instead uses male pins for everything (except the mini USB port for power and communication). I’ve taken full advantage of this for simple and visual arrangement of prototype components and sensor lead attachment. It will also be very convenient once the breakout board for the BP20422 Bluetooth module arrives in the mail (watch for another blog post on that in a couple of weeks). Instead of having each module connected to the Arduino Mega and suspended in mid-air by M/M jumper wires, everything is placed very cleanly right on the proto board. It’s all really easy to move around as well.

It’s also to add new components that might be useful to the design. You may notice in the blurry foreground of the picture above that there is a large LED placed on the board. It’s a tri-color super-bright RGB led, which I’ve added as a status indicator. There is support in the controller code for any combination of R/G/B solid on/off values, as well as the ability to blink in four different ways: (1) long blink 1x/sec, (2) short blink 1x/sec, (3) short blink 5x/sec, (4) instant flash 5x/sec. With five different display modes combined with the fact that the LED can be red, green, blue, yellow, magenta, cyan, or white, it is capable of indicating a whole lot of different statuses. I’m thinking that different modes—like “shift,” “alt,” “mouse on,” etc.—can each have their own unique color and/or blink pattern. And, of course, this feature is easily enabled or disabled in the code itself.

One of the best improvements I made for prototyping is the addition of a 40-pin connector on a simple breakout board (visible in the picture above and in the first one, off to the left). The glove has 34 touch sensors and requires the accelerometer placed right on the back. Since it’s digital and uses the I2C protocol, the accelerometer requires a total of four wires: VCC, GND, clock, and data. Incidentally, I can also connect any other I2C devices to those same four wires if I need to later. This means I need 34 + 4 = 38 conductors for to go from the glove to the processor, meaning a standard 40-pin IDE cable would be perfect.

Of course, the majority of IDE cables to be found on Newegg or eBay are either 80-conductor (to support two IDE devices) or else very short—usually 10 inches. For convenience, I wanted a very long single-device cable, since I didn’t want more than 40 wires and I wanted more flexibility. Another important feature was that it be a round bundled cable, not a flat ribbon cable. I ended up buying from this seller and getting a lot of 5 cables for $10. I only needed one, but it’s exactly what I needed and worth $10 to me for that reason. It’s perfect.

The male connector you see plugged into the board in the picture above didn’t come that way though. It actually came as a stand-alone right-angle connector like this: (Mouser part 517-D2540-5002-AR)

Because I wasn’t paying enough attention when I ordered it, I had the pleasure of bending all of the pins back to 90 degrees before attempting to mount it on the small piece of proto board I cut. The same part with straight pins (Mouser 517-D2540-6002-AR) would have been a much simpler choice. I also created extra headache for myself by buying proto board that had solder pads on only one side of the board. As you can see in the picture, this means that I needed to solder the shrouded IDE header and the male header pin strip on the same side of the board. There was no other way to do it and still achieve the same result. Even so, it turned out well. Ah, the things I learn by making mistakes…

The end result of all of this is that I have physically separated the prototyping electronics from the actual glove, which makes everything much easier to work with while I’m still experimenting. I can simply unplug the glove if I need to. I don’t have to run sensor wires all the way from the sensors to the controller; instead, I can simply run them to the back of the glove, where the other end of the cable plugs into another 40-pin connector. It’s much, much better than what I had before. There are quite a few wires on the proto board, though.

On the software side of things, I’ve made some structural changes to my code so that the main “keyglove” sketch file is much easier to read through because of new sectional comments everywhere, and almost totally independent of whether you’re using the Arduino or the Teensy. To achieve this compatibility, I created “USE_ARDUINO” and “USE_TEENSY” macro definitions (only one of which should be defined at a time), then created a “pins.h” include file which contains all of the board-specific pin assignments. The rest of the code simply uses these macro definitions universally, so all you have to do is uncomment the appropriate board declaration and you’re good to go.

Of course, the Arduino doesn’t support USB functionality right now (and it may not ever, at least not from my code contributions). The Teensy++ is smaller, cheaper, and much more capable in this regard, so I don’t really see any reason to keep pursuing it. Why do all that extra hardware and/or programming work with a larger, more expensive board when you can just use:

code, pre { font-family: Consolas, Courier New, monospace; }

Mouse.move(mdx, mdy);

…with the Teensy? I certainly couldn’t tell you.

I’ve modified the mouse tilt/movement control code some as well to make it more useful. Specifically, I had been noticing a problem with movement speed: it was either too fast or too slow based on the speed constants I set in the code. On top of that, if it was fast enough to move at a decent speed across the screen, the individual jumps were obvious when you tried to make small movements—since it always moved, for example, 5px at a time, there was no way to get good, precise resolution even though the Kalman filtering and averaging allowed you to hold it very still. So, I implemented some simple cursor acceleration right in the hardware. If you move your hand slowly, it moves the cursor slowly (with 1px resolution, as fine as you could ever use). But if you move quickly, it detects that speed and instead jumps at 5px at a time, or even more, according to an exponential formula. The result is that you can really move fast if you want, but you can also move with great precision if necessary.

So what’s next? I still need to do some more physical tweaking with sensors on the glove itself, for one thing. I’m going to try being creative with conductive thread again to see if I can make some headway with accuracy and reliability. I’ve also been looking at more appropriate gloves, since the one I have is a bit on the flimsy side structurally (though it is quite comfortable and flexible). I checked out some racquetball gloves and golf gloves, but so far haven’t found anything that I really like, so I’m still using the handbell glove. My ideal glove would be something that has a sturdy back side, particularly on the back of the hand (not so much on the fingers though), and a thin, breathable palm and fingers. This is almost backwards from how most gloves are designed, so I’m not sure I’ll be able to find what I need without getting something custom made. Any recommendations are welcome.

More exciting is that I’ve made a little headway with the Bluetooth interface thanks to this keyboard, this blog post, and the great guys over at Wayne and Layne who have been extremely helpful with the BP20422 module interface. Russ Nelson is still out of stock on the BluePacket BP20422 modules as of right now, and he has been for a few months, which is what prompted me to look elsewhere. You just can’t get the module by itself, but you can get it inside the keyboard I linked to above. It just takes some effort to get at it, since it’s SMD technology.

I’m currently waiting on a custom breakout board to arrive for the module (courtesy of Wayne and Layne), and after that arrives in a week or two, I’ll post another update.

Leave a Reply