Rotation Detection from Linux

I am a computer science and art student working on my final portfolio projects, and have an idea for a project that will incorporate a box with a crank on the side. When someone turns the crank, a computer inside the box (preferably running Linux) will be sent the speed of rotation of the crank, and perform some sort of program accordingly.

I had two thoughts regarding the sensors I would need to detect the rotation of the crank. My first thought was to use some sort of light detector... A disk that rotates with the crank would have slits in it, and a lightsource would also exist such that when the the light shone through the slits, the sensor would pick up a signal and send that to the computer. This method is much like what non-optical mice use to track movement.

My other thought was to use an optical encoder, though I think this might be the less desirable solution as it appears to me that optical encoders are meant for very precise measurements and the project I am working on will likely have a fair amount of slop.

But which method do you think is best?

Also, and more importantly, how can I interface this with my computer? I am thinking that I should be able to plug this into a serial or parallel port or something like that... but I'm a complete newbie regarding this kind of interaction and would appreciate any insight you have into this matter.

From there I think I understand how to write C++ code to track the

inputs being received, but if you know of any good documenation about this process, I would be interested in that as well.

Thanks so much! Chris Mueller

Reply to
wisejedi7
Loading thread data ...

try a counter chip, it'll output binary to a parallel port, or use a uart to send to serial.

Reply to
jim dorey

Fine optical encoders can be harvested from ball mice

Reply to
fulliautomatix

This really isn't a job for linux! I think you'd be much better off using a very simple microcontroller. Poke around at

formatting link
formatting link
etc. Maybe find a friend with some embedded experience.

It'll also be much cheaper. People here or in comp.arch.embedded can help you if you choose to go that route.

ttyl,

--buddy

Reply to
Buddy Smith

I agree that Linux isn't really the easiest platform for this job - do you need it because the program(s) you wish to run only run under this operating system?

So I've described below how I'd attack this problem - certainly not the only way, and probably not the best either, but a way that I'm sure can be made to work. If you decide to use some or all of this solution, realize that the following is *untested* (although I've used each of the techniques below verbatim on previous projects), and that you can end up with a smoked computer or other problem if you're not at least a bit careful. Chalk it up to the high price of education...

Personally, I'd find an old laptop (an old P-100 would be fine) running Win-98 or earlier - maybe $30 bucks on EBay. With this vintage you can still run semi-spiffy multi-media programs, if that's what you want, but the Win-95 and Win-98 operating systems allowed direct access to the ports (for example, the parallel port), which the NT-based OS's (and Linux) make difficult. The battery will be dead, for sure, but just run it off the wall adapter. (Note that the old gray Toshiba "bricks" [Satellite 110, etc.] are particularly good for this, because the AC supply is built in [no adapter needed], and there were so many sold that they're pretty easy to find.) Any old desktop would work too, of course.

Your disk with the slits cut in it sounds like a reasonable way to go. Note that this actually *is* an optical encoder of course, just somewhat more crude than one from a mouse or a commercially manufactured one, and not providing the quadurature information needed to detect direction (which it didn't sound like you needed anyway). I'd use an infrared LED light source and a single photo-transistor (Radio Shack 276-142, $3.29 for both parts) wired as described in the "wiring list" below.

Power the infrared LED through a 330 ohm resistor (A=anode, K=cathode). The

5 volt supply can be stolen from the computer's external mouse/keyboard port (pin 3=Gnd, pin 4=+5):

+5 >---------< Gnd

Use a 2.2k or so pull-up resistor on the photo transistor (C=collector, E=emitter), again using +5 from the keyboard port. Run the sense line from the connection point of the resistor and transistor collector to pin 13 of the parallel port (_Select). It's probably a good idea to hook up one of the parallel port grounds too, although it's probably not necessary. Use pin 18 of the parallel port for this.

+5 >---------< Gnd

To identify the pin connections of the LED and phototransistor (from the Radio Shack web site): "Set the devices on a table with the lens facing up and pins facing the person looking at the devices. The dark plastic device is the detector. The emitter is on the left and the collector on the right. The clear device is the LED. The anode is on the left and the cathode on the right."

You might have to tinker with the value of the 2.2k resistor to get a good switching threshold. Use a voltmeter at the sense point (parallel port pin

13) and substitute values until you get the widest voltage swing from light to dark. If values between 1k (don't go less than this) and 22k fail to provide a good response, check elsewhere for the problem.

Then write a program that sits in a tight loop counting pulses from the parallel port, while also watching the wall clock time. Whenever a second (or other appropriate time) elapses, the count will be proportional to the crank speed. There's a 'C' code snippet below that will locate the laptop's parallel port address; this was written in Borland C/C++ for DOS (which is a totally appropriate way to go, by the way, if you don't need the [quasi-]multitasking or graphics that the Windows environment provides). It should work with minor changes using one of the Microsoft 'C's as well.

Reply to
Mark Moulding

A multi-turn potentiometer might be worth a try.

Reply to
Tim Zimmerman

Just put a small DC motor on the hand crank, and wire the output into the analog game port of an older PC. You can easily get a DC motor strong enough to mechanically support the crank, and the voltage coming out of the motor is proportional to speed.

Try this. Get two 220K 1/4W resistors. Hook them in series between pins 1 and 4 of the joystick port. Wire the motor from the point between the resistors to pin 3 of the joystick port, with a 22K resistor in series with the motor lead, and a 100K resistor from pin 3 to pin 4. Read joystick port 1 while turning the motor shaft. If the joystick port values are too large, replace the 100K resistor with a smaller value.

Here's how a joystick port works:

formatting link
John Nagle

Reply to
John Nagle

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.