If I wanted to make a simple device that communicates with my computer, say maybe a switch that could mute my computer when turned on and off and plug it in via USB, what would be the cheapest and easiest way to accomplish this?
|
|
Build a USB Human Interface Device Class device. That is the same class used by keyboards, mice, joysticks, game pads, and the like. Your PC already has full device driver support for HID devices, so software access is easy. Lots of pointers and even sample code can be found at Jan Axelson's HID page. Browse around her site for lots of good information related to USB device development. Many of the small microprocessor families can do HIDs. I've even seen it done at USB Low Speed with an ATtiny 8-pin AVR entirely in software. Pick your preferred chip, then search its "usual resources" for HID samples. Another approach is to make a serial communications device. Several single chip solution from FTDI exist. The FT232R is a popular choice. Drivers are required, but Windows Certified drivers are known to the Found New Hardware wizard so installation isn't hard. Once installed, you have a device that looks like a COM port. Alternate drivers are available that will let you access its GPIO pins and use it in more advanced modes. |
|||
|
|
|
Easiest? Grab an Arduino and write a couple of lines of Python. Arduino's are incredibly easy to program, don't require any additional hardware to work with, and are quite popular. Python has a very straightforward serial library and is a breeze to write in. Example Code Python: Run this script as a service. I'm using Ubuntu, so this script will pop up a notification telling you when a button has been pressed on the Arduino.
Arduino:
|
|||||||||
|
|
Here is a very detailed blog post http://msdn.microsoft.com/en-us/devlabs/dd491992 with software to use an under $5 PIC18F4550 to interface via USB as a standard HID device. The software provided can be used to interface to any HID device, so if you want an alternate chip the software will still work. An added plus is that the blog post shows you how to do bi-directional communication so not only can you interface a switch you can turn an LED on and off. |
|||
|
|
|
Here is a simple project of mine using a PIC18F2455, based on Brad Minch's USB software. PCBs are available from Olimex. |
|||
|
|
|
If you don't mind Cortex-M3 based microcontroller, take a look at NXP's LPC1343. It's only $6.30 at Digikey (1 piece). There's one very cool feature - firmware for storage and HID devices in chip's ROM! Compared to a solution with FTDI chip + microcontroller, there's one chip less :) |
|||
|
|
