Electronic USB device resetter


After the marathon job I had setting up a webcam recently (talk about making a meal out of a simple project), I was disappointed to find there were reliability problems with my chosen camera, a Logitech Quickcam Pro 5000, and the Linux server it was operating from.

There is a known fault with the Pro 5000 SPCA5xx chipset under Linux and there is a patch out there which attempts to correct it however I didn't have much luck with that. The nature of the fault is that the camera will lock up tight and stop talking to the computer at random times of the day. Sometimes it would work for days without failing, other times it would fail twice in 24 hours.

The upshot was that I had to constantly keep an eye on the thing and, if I noticed it had fallen over, it would have to stay fallen over until I was in a position to get back to the server and physically reset it by disconnecting it from the USB port and then reconnecting it.

Originally I looked for a command line answer for this. Something along the lines of:
/etc/init.d/dbus restart

...however this is a bit like using a sledgehammer to crack a nut and besides, it didn't work. Only a physical reset would get the camera back into operation. If there is a way to fully reset a USB device via the command line, I don't know what it is.

What I needed therefore was a bit of automation. Something cheap, low power, unattended and could be built from parts that were in my junk box.

The answer lay in the good old 555 timer.

I've used this versatile little chip before but always for applications where a square wave output (i.e. near equal mark/space ratio) was required. An example was with the nightlights I knocked up on my renewable energy installation where a 555 was used to 'flash' the LED lights at a rapid rate to reduce their energy consumption.

What I needed here was something a little different however. I wanted to reset the webcam every couple of hours so if it locked up it would be down for only two hours at the most before my 555 timer gave it a quick kick-up-the-pants and got it working again.

The circuit below was constructed to achieve this.

Schematic



This circuit has a USB plug (left) allowing it to take its power from the host computer USB bus. A second USB plug (right) connects straight through to a USB socket with the exception of the 5V (+) line that passes through a Normally Closed relay. The load (a webcam in my case) will be connected over this.

The left side of the schematic is a normal 555 timer circuit with one exception - the diode in parallel with R2 (the 1MegaOhm resistor). The inclusion of this diode means that the 1MegaOhm resistor is effectively bypassed during the capacitor charging cycle however during the discharge cycle the current from the capacitor cannot flow back through the diode and is forced to go through R2.

The inclusion of the diode has the following effect on the mark space ratio of the timer output:

Duty Cycle


It can be seen that with the diode the Mark time (Tm) is a lot shorter than the Space time (Ts). In practice, as the values of R2 and the capacitor are very high for a 555 circuit at 1M Ohm and 10000uF respectively, Tm is about 2.3 seconds while Ts is nearly two hours.

We can use this timer to control the webcam simply by fitting a relay onto the output of the 555 timer and running the 5V (power) line of the 'load' USB bus that the webcam is using through the relay.

As you can see from the schematic, the D+, D- and GND lines on the 'load' USB bus are connected from a USB plug to a USB socket. The 5V line connects to the relay COMmon contact while the Normally Closed (NC) contact connects to the USB socket. This means that when the timer circuit is powered, the long Ts period keeps the 555 output low and the relay off. The webcam USB power line therefore flows uninterrupted through the relay powering the webcam normally.

Every couple of hours however, the 555 output goes high for a couple of seconds. This energises the relay and switches the 5V power line from the load USB bus away from the NC contact and over to the Normally Open (NO) contact. This physically disconnects the webcam from its power source. A LED indicator is connected to the NO contact and illuminates for the duration that the relay is switched.

After a couple of seconds, Tm is over and the 555 output drops low again. The relay is no longer energised, switching back into its NC position to allow the USB power line to flow from COM to NC powering the webcam back up again. Ts remains in effect for a couple of hours and then the cycle restarts.

We can calculate the actual timings this circuit provides as below:

In a normal 555 circuit where the diode isn't fitted, Tm would be calculated as:

Tm (sec) = 0.693 x (R1 + R2) x C
... with time in seconds, resistance in Ohms and Capacitance in Farads.

As R2 is being bypassed by the diode during Tm, we can cut it from the equation. There will be a 0.6V drop over the diode but I'm ignoring that for the purposes of these sums, so...

Tm (sec) = 0.693 x R1 x C            therefore....  Tm = 0.693 x 330 x 10000x10-6 = 2.2869

So the mark time of my circuit (i.e. the period when the timer output will be high and the relay energised) is just short of 2.3 seconds.

Similarly, Ts can be calculated as:
Ts (sec) = 0.693 x R2 x C          therefore....   Ts = 0.693 x 1x106 x 10000x10-6 = 6930

So the space time of my circuit is 6930 seconds or 115.5 minutes - just off two hours. In practice this circuit isn't that precise and normal small variations in the timing cycle caused by component tolerances are amplified when the timer starts running over hours meaning the space time can be several minutes out from the above calulation.

Notice how the 555 timer circuit is run from a separate USB connector to the webcam. They could both be run from the same USB connector however some USB ports only provide 100mA and the timer circuit takes close to this when the relay is energised. I didn't want to blow any USB ports on my computer so two USB connectors were provided, one to provide power for the timer and the other to power and communicate with the webcam. The pin outs for USB are shown below for anyone interested.


USB pin outs
[see footnote for image credit]



And this is the circuit itself laid out on stripboard....

Circuit board



A problematic build as I used a ridiculously small bit of stripboard. Still, it's all in now and I need never worry about having to manually reset the flippin' webcam again.

Wanna know more about my webcam shenanigans??  No..??

Related articles on this site:
Project Homepage
Using a Video4Linux (V4L) compliant webcam with camE
Using a Video4Linux2 (V4L2) compliant webcam with fswebcam
Refreshing a webcam image with Java and using a webcam with Joomla 1.5
Making a weatherproof webcam for outdoors
The view from my corner of Leamington Spa via my TV aerial mounted webcam!
One year on...


USB Connector Image author: Simon Eugster, modified from original image at
http://en.wikipedia.org/wiki/Image:USB.sv