The USB-Servo is a device to control a servo via USB. A servo is a motorized device that is commonly used in remote controlled cars and planes. I built this device to activate a toy puppet. The puppet has a button on its bottom, if you press the button the puppet collapses. When the computer is able to press the button, I can use the puppet to signal information like someone’s online-state in the Jabber-network: when my friend goes online, the puppet stands up, when he logs off it collapses.
Servos are connected with three-wire-cables. A red and a black one for the power, and a yellow one for the signal. Power has to be between 4.8 and 6 volts, so the 5 volts from the USB-port is in the range. The signal doesn’t take much current, so you can connect it directly to the controller. The angle of the servo is controlled with pulse width modulation (PWM). It gets a signal of about 50Hz (one pulse every 20ms), the length of the pulse tells the servo the angle to adjust.
A problem that I didn’t really solve is the power consumption: I don’t know the current that runs through the motor. It seems to be low enough not to cause any problems, but I don’t know how high it will get when the servo is blocked. YOU HAVE BEEN WARNED, I don’t feel responsible for USB-ports catching fire… :-/
There are three parts included in the distribution: The firmware for an ATmega8 microcontroller, a commandline-client that can be run under Linux, and the circuits needed to build the device.
This project is based on my USB-LED-Fader, which itself is based on the PowerSwitch example application by Objective Development. Like those, it uses Objective Development’s firmware-only USB driver for Atmel’s AVR microcontrollers.
Objective Development’s USB driver is a firmware-only implementation of the USB 1.1 standard (low speed device) on cheap single chip microcomputers of Atmel’s AVR series, such as the ATtiny2313 or even some of the small 8 pin devices. It implements the standard to the point where useful applications can be implemented. See the file “firmware/usbdrv/usbdrv.h” for features and limitations.
Building and installing
The circuit contains only a few standard components. There’s no special USB-chip involved.
The installation is described in the documentation.
Connect the device to the USB-port. If it isn’t already, the servo will move to the 0-position.
Then use the commandline-client as follows:
usb-servo set <angle>
angle: The angle you want to set the servo to. 0 is full left, 255 is full right.
Get the status of the servo:
This will tell you the angle the servo is currently put to.
Current servo angle: 42
Set a new angle:
The device from behind
Behind the scenes
usb-servo set 23
This sets the servo to the angle 23. 0 is full left, 255 is full right, so with 23 the servo will be almost on the left side.
Test the device:
This function sends many random numbers to the device. The device returns the packages, and the client looks for differences in the sent and the received numbers.
Demo application xservopointer
This is a pure fun thing, nobody will need it. That was reason enough to write it…
To use it, you have to position the servo centered above the screen (with a little tweaking in the source, you can change that position). Then, you attach a pointer to the servo and start the application.
You’ll never ever have to search for your mouse cursor in the future. The pointer on the servo will always show you where to search.