Loading...
Pages: [1]   Go Down
Author Topic: Stepper Motor control with Proccesing  (Read 437 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there!

I wanna control one stepper motor hooked to my motorshield r 3 / arduino uno with a processing interface.

It works as follows:

I built a lift for scientific usage which is driven by a stepper motor.
Now i need an PC interface where the user can type in a specific range and the lift will drive this distance up or down.
The distance is checked by a range sensor.

I am new to PC interfacing, so my question is, which would be the right library to use? I read that Firmata isn't the right one for me.

Thanks for your help!
Logged

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

Quote
I am new to PC interfacing, so my question is, which would be the right library to use? I read that Firmata isn't the right one for me.
The assumption here is that someone else has already created a library for your specific application. I have some bad news for you...

Defining a protocol - an agreed upon means of exchanging data - and implementing it is pretty easy, if you give some thought to everything that the PC application needs to tell the Arduino to do.
Logged

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

The only thing it really needs to do is "go x steps when button y on the gui is pressed"

So, instead of pressing my physical button on digital pin 2 like i've got it in my code now, i want a virtual button to be pressed.

I just need a point where or how to start, so i can dive in deeper. Any suggestions?

Code:
// Include the Stepper Library
#include <Stepper.h>

// Map our pins to constants to make things easier to keep track of
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int dirA = 12;
const int dirB = 13;

const int buttonPin = 2;

// The amount of steps for a full revolution of your motor.
// 360 / stepAngle
const int STEPS = 200;

int buttonState = 0;

// Initialize the Stepper class
Stepper myStepper(STEPS, dirA, dirB);

void setup() {
  // Set the RPM of the motor
  myStepper.setSpeed(40);

  // Turn on pulse width modulation
  pinMode(pwmA, OUTPUT);
  digitalWrite(pwmA, HIGH);
  pinMode(pwmB, OUTPUT);
  digitalWrite(pwmB, HIGH);

  // Turn off the brakes
  pinMode(brakeA, OUTPUT);
  digitalWrite(brakeA, LOW);
  pinMode(brakeB, OUTPUT);
  digitalWrite(brakeB, LOW);

  // Log some shit
  Serial.begin(9600);
  pinMode(buttonPin, INPUT);
}

void loop() {
  // Move the motor X amount of steps
  //myStepper.step(STEPS);
  //serial.println(STEPS);
  // Pause
  // delay(2000);

  // Move the motor X amount of steps the other way
 buttonState = digitalRead(buttonPin);
 if (buttonState == HIGH) {
  myStepper.step(-STEPS);
  Serial.println(-STEPS);
 }
 else {
  // Pause
  delay(0100);
 }
}
Logged

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

Code:
The only thing it really needs to do is "go x steps when button y on the gui is pressed"
The same number of steps every time? Then, send the Arduino a "command", like "S" so it knows it needs to step.

What about "The distance is checked by a range sensor."? Does the GUI need to know anything about this distance?
Logged

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

What about "The distance is checked by a range sensor."? Does the GUI need to know anything about this distance?

Sooner or later, yes, but for now i just want it to spin smiley


Just to check that i got this right:

Processing is an interface which sends messages to my arduino. To let my arduino know what to do with these "mails", i will have to upload a corresponding code to the arduino board.

Example:
I press Button A on my processing interface. A gets send to my board, and the code tells it "if you got mail a, spin x steps"
is this about right?
Logged

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

Quote
Processing is an interface which sends messages to my arduino.
Processing is an application development platform that can be used to define such an interface.

Quote
To let my arduino know what to do with these "mails", i will have to upload a corresponding code to the arduino board.
Yes.

Quote
I press Button A on my processing interface. A gets send to my board
If you code the button callback to do that, yes.

Quote
and the code tells it "if you got mail a, spin x steps"
Yes. Case matters, though. If you send 'A', you must plan to receive 'A' (not 'a').
Logged

Pages: [1]   Go Up
Print
 
Jump to: