Talking to a stepper motor via serial
Today’s major goal of the day was to be controlling the motion of a stepper motor from the computer, preferably in Processing, thus completing the path from detection (WiiMote) to physical movement (motors) - theoretically.
I have been successful to an extent; I can control the motor from Processing - great - but not in the way I would have liked. I was aiming to be able to explicitly tell the motor to turn X number of steps and for it to unquestiongly to oblige. My downfall was serial communication…
Serial communication sends information bit by bit; as an example let’s say Iw as sending the value of 100 to the stepper motor, which on a 100 step motor should mean one complete turn. The numebr 100 is in fact three seperate bits, a 1 a 0 and another 0. The Arduino would read the first character and act, then the second and so forth. This meant that rather than one complete turn my motor was in fact moving just one step (1 step followed by 0 steps and then another 0 step). Disaster.
In a bid to try and outsmart it I wrote all sorts of loops and other clever coding bits to try and catch all the values and then apply it to the motor - all failed.
However, I have now realised that in practice I will likely not need that sort of precision. As everything happens so fast the changes between tracked points will be small so single digit values are probably going to be ok.
A little more thinking led me on to consider these serial values as ‘speeds’ and I would actually hard code the steps into the Arduino code. The theory this time is that I can constantly tell the motor to turn (say) to the right at speed 3 for as long as I transmit the number 3 on the serial port.
So imagine, if you will, that I have 7 speeds; 1-3 are clockwise speeds, 4 is stopped and 5-7 are anti clockwise speeds. The setup could have a sensitivity/speed setting which is customisable in the code on the computer - leaving me in the ideal situation where the Arduino is an interface and not actually doing much thinking for itself.
So far so good. Zoom phase seems definitely focused on getting the concept working.