Tell me more ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
3  
look at my usb single chip scope here, it is difficult to do with fewer parts 1 ATTiny45 and a couple of zener, 2 chanels HID – user4047 Apr 29 '11 at 23:23
Very cool project! – Code Painters Apr 29 '11 at 23:24

5 Answers

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.

share|improve this answer

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.

#! /usr/bin/python

import serial
import pynotify

ser = serial.Serial('/dev/ttyUSB0', 9600)
while True:
  x = ser.read()
  if x == 'b':
    # Show notification
    n = pynotify.Notification("Arduino", "The button was pressed.")
    n.show()

Arduino:

void setup(){
  // Assuming button is active low and on pin 4
  pinMode(4, INPUT);
  Serial.begin(9600);
}

void loop(){
  if(digitalRead(4) == LOW){
    Serial.print('b');
  }
}
share|improve this answer
can you supply more detail on using pyserial to interface with Arduino? Code sample or links appreciated. – LeanerRocky Apr 30 '11 at 5:22
1  
Sure thing. Check out the example. – Nick Pascucci Apr 30 '11 at 16:42
I really appreciate the example. You are legend!! – LeanerRocky May 1 '11 at 9:39

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.

share|improve this answer

Here is a simple project of mine using a PIC18F2455, based on Brad Minch's USB software. PCBs are available from Olimex.

share|improve this answer

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 :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.