first to let you guys know thet my skills arent high in programming but i try!
My project:
1 - Servo motor
1 - Stepping motor
1 - webcam
1 - mouse + processing
I already did it to let my servo motor run on this program (like 180 decrees)
My program in arduino:
#include <Servo.h>
Servo One;
Servo Two;
int incomingPos = 0;
int servoX = 0;
int servoY = 0;
void setup()
{
byte incomingPos;
Serial.begin(9600);
One.attach(9);
Two.attach(10);
}
void loop()
{
if (Serial.available() >= 2)
{
servoX = Serial.read(); // Put the serial input into the message
servoY = Serial.read(); // Put the serial input into the message
One.write(servoX);
Two.write(servoY);
}
}
My processing code:
import processing.serial.*;
Serial port;
void setup() {
size(180, 180);
println("Available serial ports:");
println(Serial.list());
port = new Serial(this, "COM3", 9600);
}
void draw() {
// draw a gradient from black to white
for (int i = 0; i < 180; i++) {
stroke(i);
line(i, 0, i, 180);
}
// write the current X-position of the mouse to the serial port as
// a single byte
port.write(mouseX);
port.write(mouseY);
}
Now, my the question is i got a step motor (i dont have another servo motor) what i have to get work with digitalWrite and a puls like 200 for a round.
How do i combined this kind of things.. i really searched alot on the internet but i cant find it.
There are plenty of people with the skills, but they will want more information from you. What type of stepper motor is it? How is it connected to your Arduino? Are you using a motor shield? How are you powering the motor? An arduino isn't capable of powering most stepper motors without an external power source.
hi, yea ok but it is difficult to say what kind of information i need to give
I use a microstep driver, so i only need to give a direction and a pulse. Like this:
int pulpin = 9; // Puls to microstep driver
int revPin = 8; // direction
int i = 0;
void setup() {
pinMode(pulpin, OUTPUT); // sets the digital pin as output
pinMode(revPin, OUTPUT);
}
void loop()
{
do
{
i = i + 1;
digitalWrite(pulpin,1);
delayMicroseconds(650);
digitalWrite(pulpin,0);
delayMicroseconds(650);
} while (i < 200);
digitalWrite(revPin,0);
delay(1000);
i = 0;
do
{
i = i + 1;
digitalWrite(pulpin,1);
delayMicroseconds(2400);
digitalWrite(pulpin,0);
delayMicroseconds(2400);
} while (i < 200);
digitalWrite(revPin,1);
i = 0;
delay(2000);
}
My problem is how i can control a servo motor and a stepper motor with X and Y from a Mouse.
I got this working with 2 servo motors, only i wanne use a steppermotor for one of the 2 servo's.
So like:
Servo = mouseY
Steppermotor = mouseX
But i use the servo.h and i dont know how to script my steppermotor at thet point. So i got a signal from processing trough serial port, and wanne translate it to my servo and my steppermotor.
You keep a variable with the current stepping motor position in it. When a request comes along to move it to a new location you take the current position and work out how many steps you need to go and in what direction to get to the new position. Then you give the motor the required nu ber of steps to get to the new position. Then update the current position.
#include <Stepper.h>
#include <Servo.h>
Servo One; // Servo Motor
Servo Two; // Stappen Motor
int revPin = 7; // direction
int i = 0; // counter
int incomingPos = 0;
int servoX = 0; // Servo motor
int servoY = 0; // Stappen motor
void setup()
{
byte incomingPos;
Serial.begin(9600);
One.attach(9); // Servo motor
Two.attach(10); // Stappen motor
}
void loop()
{
if (Serial.available() >= 2)
{
servoX = Serial.read(); // Put the serial input into the message
servoY = Serial.read(); // Put the serial input into the message
One.write(servoX); // Servo motor
digitalWrite(servoY, 1); // Stappen motor
delayMicroseconds(650); // Delay
}
}
Now i wanne use pinMode(Two, OUTPUT); but it says he cant recognize it because he doesn't read 1 or 0. How do i convert this?
Yes i understand that. But what i mean, i need to know what i need to do. To change the serial input (from processing) to a variable what i can use for my stepper motor.
If you are still using the Processing code posted in the first post, that code is sending binary data, not ASCII data, to the Arduino. So, the process you have for reading the data, and passing the value directly to the servo is correct.
This, however is wrong:
digitalWrite(servoY, 1); // Stappen motor
The value being sent for the Y coordinate is NOT a pin number.
#include <Stepper.h>
#include <Servo.h>
Servo One; // Servo Motor
int pulpin = 10; // Stappen Motor
int revPin = 7; // direction
int i = 0; // counter
int incomingPos = 0;
int servoX = 0; // Servo motor
int servoY = 0; // Stappen motor
void setup()
{
byte incomingPos;
Serial.begin(9600);
One.attach(9); // Servo motor
pinMode(pulpin, OUTPUT);
}
void loop()
{
if (Serial.available() >= 2)
{
servoX = Serial.read(); // Put the serial input into the message
servoY = Serial.read(); // Put the serial input into the message
One.write(servoX); // Servo motor
[color=red] digitalWrite(pulpin,1);
delayMicroseconds(650);
digitalWrite(pulpin,0);
delayMicroseconds(650);[/color]
}
}
The red part, is the part what i really dont know what to do with. My skills are to low, to make a connection between (my servoY valua) and the digitalWrite() code.
I hope some of you know it (The google says nothing :|)
The red part, is the part what i really dont know what to do with.
All that code does is to pulse the motor one time, this will move the motor only 1 step.
What you need to do here is to call a function to write as many pulses to the motor as you need to. Like I said in an earlier reply you need to work out how many pulses to give the motor to get it from where it is to where you want it to be.