Xbox Controller + Stepper motors

Hello everyone,
my name is Taniq, I am from Slovakia, Bratislava.I would like to ask for help. Recently I found a video on youtube, demonstration how to control with Xbox360 servo motors.I was very impressed from the interface of Processing and how easy actually works to control a servo motor.
Here is the link of the video:

My question is:
Is there a library that I can use for a Stepper motors? Example code will be helpful.
Thanks in advance.

ps.
I’ve build a robot arm that is using 6 stepper motors and since i don’t have a pedant I do believe with a controller like Xbox will work out :slight_smile:

1 Like

Hello!

And welcome to the forum!

Great to have you here!

Actually the recommended hardware is Arduino (not Xbox), processing related.

As the title says it:

  • Controlling Arduino with Javascript Using the Johnny Five Library

Also, please read the description on YouTube:

  • Build guide, diagrams, code etc over on the written article…

See also:

https://www.processing.org/tutorials/electronics/

https://www.arduino.cc/

Hello Chrisir,
maybe my question wasn’t so clear. I know arduino and i can work with it. But I am not sure that using the Gamecontrol from Processing for the controller will work out same way with stepper motors, as for the servo motor in the article? In the video the man explains brefly how many libraries are included in order to use arduino and communication with it, but it seems to me that all of them are for the servo motors…
Commands in the his program like digitalWrite(10, High) and etc…are related to a servo motor. Calling line arduino.Servo and etc…as well…
So this is what made me to aks for a help. Can I use the same method with xbox controller processing and arduino to control stepper motor? :slight_smile:
thanks for the links…
I am about 2 days already searching for information … but since everyone has different ideas(world is big and creative) i still cannot find helfpul artcile.
Smile,
Taniq

Oh maybe you mean this one. I will have a look more detials now. Thank you

1 Like

Did you read the description on YouTube?

So you want to run the Arduino code on a Xbox? Why. Arduino is cheap.

Yes I read it.
No I want to use my xbox controller to operate an robot arm with stepper motors.
In his examples and in mostly every robotic projects he works with a servo motor. The difference between servo and stepper motors is quite big.
I want to use the gamecontrol option from processing(as shown on that video) but for stepper motors.
And yes Arduino is cheap and really powerful! It’ is not necesarely every home project to be part of rocket science :))
Cheers
Taniq

1 Like

Hi @Name_itT – to confirm:

xbox controller --> arduino --> stepper motors --> robot arm

This is what you want to do, right?

Which links in that chain are you asking for help with first? Which ones are you pretty confident about? I would suggest breaking this down into smaller sub-projects and stages.

It sounds like you have an xbox controller and an arduino – do you already have the robot arm with steppers? Have you been controlling it in some other way?

1 Like

Hello Sir.
Yes I do. You understood me well. I was just very confused from all information and insane amount of programs that everyone were posting as “the best” solution, but at the end not really the case. Yes I am new in programing but I just dont like to copy paste something which I dont understand from where it comes, why it is setup this way and etc.
So before jump into something big I started with a small steps, related to my knowledge.

Here is a short video. My first try.
If you would like to see the program, please do let me know. I will post it. I tried to keep it simple.
My background is fanuc CNC programing.

1 Like

Great!!

Does the video mean that you have solved your problem, or do you still have a question?

Thank you.
Well I do believe I am on the right way. However I am not sure that topic should stay open. I hope of it’s a conitnue discussion maybe would be helpful for other people. However is this require something more from me. To provide for example the final solution or ?
Thank u …
Have a nice evening and smile.
Taniq

Yes, you may ask follow-up questions about the project here on this thread. Or you may share your solution here if you wish.

You can also post the project to the Gallery if you want to share it whenever it is finished.

/// Beginner program for controlling stepper motors with a joystick.

int driverPUL1 = 22; // driver slot for Pulses
int driverDIR1 = 24; // driver slot for Directon
int driverPUL2 = 26;
int driverDIR2 = 28;
int driverPUL3 = 30;
int driverDIR3 = 32;
int driverPUL4 = 34;
int driverDIR4 = 36;
int driverPUL5 = 38;
int driverDIR5 = 40;
int button = A11;
int buttonPos = 0;
int pd = 100; //pulse delay

// Anlog Pins: A8=button, A9=Y, A10=X, A11=button, A12=Y, A13=X

void setup() {
  Serial.begin(9600);
  pinMode(driverPUL1, OUTPUT); // Driver PUL1 ON
  pinMode(driverDIR1, OUTPUT); // Driver DIR1 ON

  pinMode(driverPUL2, OUTPUT); // Driver PUL2 ON
  pinMode(driverDIR2, OUTPUT); // Driver DIR2 ON

  pinMode(driverPUL3, OUTPUT); // Driver PUL3 ON
  pinMode(driverDIR3, OUTPUT); // Driver DIR3 ON

  pinMode(driverPUL4, OUTPUT); // Driver PUL4 ON
  pinMode(driverDIR4, OUTPUT); // Driver DIR4 ON

  pinMode(A11, INPUT);
  pinMode(driverPUL5, OUTPUT); // Driver PUL5 ON
  pinMode(driverDIR5, OUTPUT); // Driver DIR5 ON

}


void moveJ1() {
  int stickPos; // stick postion
  int steps = 0; // steps
  int dir;    // direction

  stickPos = analogRead(A10); // reading stick position 0 to 1023

  if (stickPos > 520 || stickPos < 480) steps = (stickPos - 500) / 50; // lower divider will make high speed higher
  //Serial.println(steps);
  delay(4);    // larger number of delay will make low speed lower

  if (steps > 0) dir = 1; else {
    steps = -steps;
    dir = 0;
  }

  digitalWrite(driverDIR1, dir);

  for (; steps > 0; steps--) {

    digitalWrite(driverPUL1, HIGH);
    delayMicroseconds(pd);
    digitalWrite(driverPUL1, LOW);
    delayMicroseconds(pd);
  }
}

void moveJ2() {
  int stickPos; // stick postion
  int steps = 0; // steps
  int dir;    // direction

  stickPos = analogRead(A9); // reading stick position 0 to 1023

  if (stickPos > 520 || stickPos < 480) steps = (stickPos - 500) / 50; // lower divider will make high speed higher
  //Serial.println(steps);
  delay(4);    // larger number of delay will make low speed lower

  if (steps > 0) dir = 1; else {
    steps = -steps;
    dir = 0;
  }

  digitalWrite(driverDIR2, dir);

  for (; steps > 0; steps--) {

    digitalWrite(driverPUL2, HIGH);
    delayMicroseconds(pd);
    digitalWrite(driverPUL2, LOW);
    delayMicroseconds(pd);
  }
}

void moveJ3() {
  int stickPos; // stick postion
  int steps = 0; // steps
  int dir;    // direction

  stickPos = analogRead(A12); // reading stick position 0 to 1023

  if (stickPos > 520 || stickPos < 480) steps = (stickPos - 500) / 50; // lower divider will make high speed higher


  //Serial.println(steps);
  delay(4);    // larger number of delay will make low speed lower


  if (steps > 0) dir = 1; else {
    steps = -steps;
    dir = 0;
  }

  digitalWrite(driverDIR3, dir);

  for (; steps > 0; steps--) {

    digitalWrite(driverPUL3, HIGH);
    delayMicroseconds(pd);
    digitalWrite(driverPUL3, LOW);
    delayMicroseconds(pd);
  }
}

void moveJ4() {
  int stickPos; // stick postion
  int steps = 0; // steps
  int dir;    // direction

  stickPos = analogRead(A13); // reading stick position from 0 to 1023

  if (stickPos > 520 || stickPos < 480) steps = (stickPos - 500) / 50; // lower divider will make high speed higher


  //Serial.println(steps);
  delay(4);    // larger number of delay will make low speed lower


  if (steps > 0) dir = 1; else {  
    steps = -steps;
    dir = 0;
  }

  digitalWrite(driverDIR4, dir);

  for (; steps > 0; steps--) {

    digitalWrite(driverPUL4, HIGH);
    delayMicroseconds(pd);
    digitalWrite(driverPUL4, LOW);
    delayMicroseconds(pd);
  }
}

void moveJ5() {
  int stickPos; // stick postion
  int steps = 0; // steps
  int dir;    // direction

 // This part below of the code I am not sure if it is correct. I have to test
  stickPos = analogRead(A10); // reading stick position 0 to 1023

  if (buttonPos > 520){ 
    if(stickPos > 520 || stickPos < 480);
  steps = (stickPos - 500) / 50; // lower divider will make high speed higher
  }

  //Serial.println(steps);
  delay(4);    // larger number of delay will make low speed even slower


  if (steps > 0) dir = 1; else {
    steps = -steps;
    dir = 0;
  }

  digitalWrite(driverDIR5, dir);

  for (; steps > 0; steps--) {
    if (analogRead(A11) > 500) {
      digitalWrite(driverPUL1, HIGH);
      delay(pd);
      digitalWrite(driverPUL1, LOW);
      delay(pd);
    } else {
      digitalWrite(driverPUL5, HIGH);
      delay(pd);
      digitalWrite(driverPUL5, LOW);
      delay(pd);
    }
  }
}

void loop() {
  moveJ1();
  delay(pd);
  moveJ2();
  delay(pd);
  moveJ3();
  delay(pd);
  moveJ4();
  delay(pd);
  moveJ5();
  delay(pd);

}
1 Like

The Robot Arm is 6DOF industrial-scale robot created by Chris Annin.


Motors specification:

This is my tinkerswork bench at home :)) I have one lion and pip boy as helpers ; )))) they never complain :stuck_out_tongue:

1 Like

Short video how the program and robot works together:)

1 Like

Hello,

Please format your code:
https://discourse.processing.org/faq#format-your-code

You can go back and edit it.

I am interested but don’t look at code that is not formatted these days.

:)

1 Like

Hello
It didnt give me an error in the post … but I will do check your page and try my best to edit and post it in proper way. Thank u. Have a smile,
Taniq

ps. I think now it looks much better. ; )

1 Like

It does!

I will share more later.

:)

hey!!! I have exactly the same “problem”, i think at the end i will use an serial data connection like: xbox controller - processing - arduinoIDE - stepper motor for the arm… but surely only have the firmdata schetch on the arduino and controlling everything directly from Processing would be much better… did u found at the end the “mystical” stepper library?:wink: Or we have do to create our own??

Helllo,

I do not use Firmata.

I send serial data from Processing to Arduino, parse it and use that data for control.

https://www.arduino.cc/en/reference/stepper

:)

ok i will probably do the same… it seems the only solution…Thanks