Hi all,
I have my project working but there is room for improvement. I'm posting my project here "tutorial style" for anyone interested in building it. At the same time it provides insight into the workings that might help answering question about improvements.
I'll post my questions as a reply.
Disclaimer: I built this project as described and it works for me. I'm not claiming it's 100% perfect and flawless, but it works.
What does it do and why?
I use a Wacom tablet and I missed a convenient scrolling device. So I decided to build one from a hard disk motor. When turning the motor by hand it generates pulses on the leads. These pulses are read into an Arduino Pro Micro which sends the scroll commands over USB using the mouse library.
What do you need?
-- A hard disk motor with 4 leads
-- An LM324 quad opamp to amplify motor pulses to logic level
-- An Arduino Pro Micro or another board with a 32U4 chip
Hooking it up.
My circuit/schematic drawing skills might be a bit odd but you should get the idea
NOTE: When hooking up the leads it does not matter which lead goes to which pin. The sequence can easily be changed in the code. Just make sure to find the 3 signal pins on the motor and connect these to pins 3, 5 and 10 on the LM324. To find the signal pins, get your multimeter, measure resistance and google a bit.
-- Turning the motor will generate millivolt pulses on leads A, B and C
-- The negative inputs on the LM324 are tied to ground
-- If a pulse on a lead is only slightly above ground the LM324 will "amplify" it to a logic level on the corresponding output (3.3 or 5V depending on your board)
-- The logic level triggers an interrupt and the code will process it. On the Pro Micro I used a library to use regular inputs as interrupt pins. Not exacly sure why pin 7 didn't work but 16 is fine too.
The signals.
First you need to find the right sequence. To do so use this sketch:
HDDScrollwheel__PinSequence.ino (705 Bytes)
In this sketch, change around the pin numbers until the output is:
...4,6,2,3,1,5,4,6... for one direction and
...6,4,5,1,3,2,6,4...(reversed) for the other direction
NOTE: (Counter)ClockWise, scrolling up down could be just the other way around for you. It depends on the pin sequence and code, just fiddle around with it.
Now for the processing. If you turn the motor at a good speed the signals can be visualized as follows:
When a signal on one of the leads rises or falls, an interrupt is triggered. Immediately after the interrupt the binary state of the leads is converted to an integer.
So if the current state is 3, the previous state was 2 and the state before that was 6
or T0=3 and T-1=2 and T-2=6 >> Your motor is making a valid spin.
The way my code works:
-- The current state, previous state and the state before that are stored in an array
-- The current state is shifted in at the back, pushing values to the left
-- An integer is calculated from that array, for example:
{3,2,6} > 100 * 3 + 10 * 2 + 6 = 326, This would be a valid sequence when rotating
-- The integer (sequence) is check against valid sequences stored in constant arrays for CW and CCW
-- There are 6 valid sequences for each direction:
{326,264,645,451,513,132} and
{231,315,154,546,462,623}
I found that storing 3 values works fine. Storing only 2 can lead to irregular behavior. Especially when just slightly moving the disc or rotating too slowly.
That is the basic concept. This is the complete code:
HDD_Motor_Scrollwheel.ino (4.9 KB)
View the complete code in the next reply.
Thanks for making it this far!
if(you think you have tips on improvement or different concepts)
{
pleasePost();
}