Al Williams

Dr. Dobb's Bloggers

Fidgety USB

October 01, 2013

Linux-based boards like the Raspberry Pi or the Beagle Bone usually have some general-purpose I/O capability, but it is easy to forget they also sport USB ports.

A few weeks ago I was lamenting how everything is built into my PC, so I don't get the chance to go shopping for goodies to plug into it as much as in the past. However, it is relatively easy to plug in USB devices, although it is somewhat less satisfying to my inner geek.

Linux-based boards like the Raspberry Pi or the Beagle Bone usually have some general-purpose I/O capability, but it is easy to forget they also sport USB ports. Adding a hub offers a wide range of expansion options. It wasn't long ago that I used a USB sound card and a Raspberry Pi to decode touch tones. That's a pretty obvious USB peripheral. There are more exotic ones, though.

A few years ago, I worked on a system for a museum that needed to identify different cast rubber livers. A patron would insert the liver into a mannequin's body cavity, and a face would appear along with audio describing if the liver was healthy or not. Imagine the character saying, "I drank too much and now I have cirrhosis."

The original system (that I inherited) used a strange and error-prone method to determine which liver was present. It relied on magnets, reed switches, and a cannibalized PC keyboard. My search for a better solution led me to a company called Phidgets. They make a wide range of USB sensors including some for load cells, pH, temperature, voltage, current, and many other quantities and functions. They are also fairly inexpensive as these sort of things go.

The one I was especially interested in was the RFID reader. Once connected to the PC and an RFID chip stuffed in each liver, detecting which one was inserted was a piece of cake. In this particular case, I was using a Windows-based PC but the RFID interface has example code for a variety of situations including Linux, Mac, LabView, Java, and even Flash.

I haven't tried any of these on a Raspberry Pi or Beagle, but there's no reason they shouldn't work like any other USB device will. If you crave something more custom (or otherwise unobtainable), an Arduino Leonardo would be another option to bring custom I/O into a USB port. It is easy to make these send keyboard or mouse input, which you can read very easily.

In the past, SPI or I2C have served to some degree as an embedded system bus. Larger systems rely on things like CAN. However, with the price of hardware falling and operating systems moving towards Linux and similar operating systems, maybe USB is the bus of choice for simple systems.

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task.
However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Video

This month's Dr. Dobb's Journal

This month,
Dr. Dobb's Journal is devoted to mobile programming. We introduce you to Apple's new Swift programming language, discuss the perils of being the third-most-popular mobile platform, revisit SQLite on Android
, and much more!