Pages: [1]   Go Down
Author Topic: Processing input emulation  (Read 1052 times)
0 Members and 1 Guest are viewing this topic.
Oregon
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As one of my first Arduino projects, I plan to turn the carriage (Is that what it is called? the slidey thing) from an old CD drive I got hold of into a linear webpage scroller. The motor that used to control it seems to be a simple DC motor, and is geared to the carriage. I plan to use Firmata and Processing to get the voltage from the two leads from the motor, and use Processing to emulate a hardware scroll wheel. ANy advice?
Logged

--Adam
Hacking your gadgets is not a crime. You don't own it until you have gotten past the locks and taken control of the device on which y

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I plan to use Firmata and Processing to get the voltage from the two leads from the motor,
How, exactly, do you propose to do that?
Logged

Oregon
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was planning on using the built-in pin-by-pin control. However, I decided to simplify this and just transmit the motion over serial.
void setup()
The Arduino code:
Code:
void setup()
{
  Serial.begin(9600);
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  digitalWrite(A0, HIGH);
  digitalWrite(A1, HIGH);
}

void loop()
{
  int voltin0 = analogRead(A0);
  int voltin1 = analogRead(A1);
  Serial.println(voltin0 - voltin1);
  delay(5);
}
I haven't written the Processing code yet.
Logged

--Adam
Hacking your gadgets is not a crime. You don't own it until you have gotten past the locks and taken control of the device on which y

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  digitalWrite(A0, HIGH);
  digitalWrite(A1, HIGH);
The A0 and A1 aliases are for when you want to use analog pins as digital pins. That's what this part looks like you want to do.

Code:
  int voltin0 = analogRead(A0);
  int voltin1 = analogRead(A1);
But, this part of the code looks like you want to use the analog pins as analog pins. In which case none of that crap in setup() belongs there, since analog pins are, by definition, INPUT, and you do not want to be turning on the pullup resistors. Also, you want to use 0 and 1, not A0 and A1, to make it clear you know what you are doing.

Code:
  Serial.println(voltin0 - voltin1);
  delay(5);
So, every 5 milliseconds, you want to write potentially the same value, as a string, to the serial port.

I'd think that it would make more sense to only write when the value changes.

If what is connected to the two analog pins is from the two sides of the motor, the voltage at those pins will be the same, so you will be writing a continuous stream of 0 to the serial port.

I can't see that being useful. Even if you measured accurately the voltage or current applied to the motor, how would that information be useful? What, exactly, is that motor doing?

Quote
a linear webpage scroller.
What, exactly, is a "linear webpage scroller"?
Logged

Oregon
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have the hardware side totally working at this point, the only problem is mouse emulation.
I am pulling both pins up, then hooking the two leads from the DC motor to them. When I spin the motor, which I am using as a makeshift encoder (kludgy, yeah, but I don't have an optical encoder, and it fits perfectly), one pin gets pulled down, and the serial output is (pin1 - pin2), so it outputs the difference between them. Pulling them up is to keep them from floating and randomly scrolling tiny amounts.
A "linear webpage scroller" is like http://www.instructables.com/id/Spinner-Jog-Wheel-Inside-of-a-VCR-Head/, but linear instead of circular. You know, for ebooks and long webpages.
Logged

--Adam
Hacking your gadgets is not a crime. You don't own it until you have gotten past the locks and taken control of the device on which y

Pages: [1]   Go Up
Jump to: