simple guidance: control 3 steppers with joystick

Hi guys, I need advice! I want to control 3 motors using a Joystick (for a 3D micro-positioning system). I have all the electronics and I'm about to start with the mechanical cutting & assembly.

The problem is, I can program but I don't know much about electronics and I'm afraid to mess up and burn some of the components. It guess what I need is quite simple and many folks must have done it already, but so far found tutorials for moving only 1 and 2 motors with a joystick. All of the 3-axis examples I have found so far are intended for CNC which uses GRBL, ie it is designed to run a pre-defined motion (g code), but I want instead to move the 3 motors realtime, freely with the joystick.

So, can you please point me to a tutorial, video, anything, so I can see how to connect all the parts and then maybe I can check out some code for the Arduino?

No GRBL and no computer should be involved (only to of course compile and load the code into the arduino).

This is what I have:
3x stepper motors Nema17
6x end-stop switches
1x CNC Shield 3.03
3x Pololu - A4988 Stepper Motor Driver
1x ITEAD Joystick shield
1x Arduino UNO

Ideally I would set 3 velocities, and use the joystick for X and Y movements, while one set of buttons will be for the Z axis... but I can figure out all of that in the code, first I need to get the system working with simple movement of each motor according to the input of the joystick.

Thanks!!!

Is this a correct interpretation of your requirement - you want to control two stepper motors with the two axes of a joystick and you want to control a 3rd stepper motor with one (or is it two?) buttons.

If that is correct it should be straightforward.

How do you want the joystick (just think of one axis for the moment) to control the motor. Do you want the distance the joystick is moved to control the speed of the motor or its position?

How do you want the 3rd motor to respond when a button is pressed?

It would be a big help if you describe the machine you want to make so we have a clear picture in our minds.

...R
Stepper Motor Basics
Simple Stepper Code

Hello! Thanks for your reply.

you want to control two stepper motors with the two axes of a joystick and you want to control a 3rd stepper motor with one (or is it two?) buttons.

Yes it is correct. I want to control two steppers with the two axes of a joystick and at the same time control a third motor(1) with two buttons.

The purpose of this device is to freely move a small platform in XZY directions. The movements are not pre-definined but depend only on two inputs: joystick and end-stop switches. The platform will carry a DSLR camera, so that is all the weight I need. I don't need CNC-like levels of "strength" (sorry if not the appropriate term) because the steppers only have to counteract camera weight, gravity and friction. BUT I do need to be able to set VERY fine movements because if I use big magnifications I will have very narrow depth of field, thus I need to move in the sub-mm ranges to have great sharp focus.

Imagine a horizontal plane formed by X and Y axes; this plane can move upwards or downwards (it along the Z axis). I want to control the position of the camera along the Y axis (left-right) by moving the joystick towards left or right; in the same way I want to control the position over X axis (front-backwards, which will ultimately control focus on the object located at a fixed position from the front of the camera) when I move the joystick towards or away from me (let's imagine I'm situated behind the camera and pointing towards the object, thus moving the joystick in the X axis will change the distance between camera and object). The joystick shield has four buttons (2), thus I would control the position over Z axis (up-down) by pressing let's say button 1 and button 2. Maybe buttons 3 and 4 could be for moving up and down using twice the speed, but I can take care of that later.

Do you want the distance the joystick is moved to control the speed of the motor or its position?

Thanks for getting into the details! Let's do this:
NO, I do not want the speed to be proportional to the extent of the joystick being moved (if that is what you meant). I want that every time the joystick is moved in one axis, the corresponding stepper moves one unit of distance. I assume one can do that with Arduino: the arduino takes the analog signal from the joystick, and when it detects that the joystic has moved in one axis (no matter how much is moved, just if its negative or positive with respect to the "rest position") then sends the signal to the CNC shield to move the motor one unit of distance in the positive or negative direction with respect to the current direction of the camera. Repeat until joystick is back in rest position. Simple: you move the joystick away from you, the camera moves toward the object until you leave the joystick alone. You move the joystick towards you and the camera moves backward (away from the object), until you leave the joystick. When you leave the joystick, the camera just stops (ie it doesn't get back to a given position). The unit of distance is set as a constant at the beginning of the code, so if I need to change it I can just modify the code, compile, upload and use it. There could be some use, now I think about it while I write, if I define two different units of distance, one for X, one for Y and one for Z, just in case I need to move faster in the Z direction for example or if I need even more precise movements for focusing but not for traveling sideways.

For the Z axis, it's similar but with the buttons: you press let's say button 1 and the camera moves upwards until you stop pressing. Press button 2 and camera goes down until you leave the button. Maybe buttons 3 and 4 can act in the same way but twice the speed (ie move 2x unit of distance).

Note that no GRBL and no computer is involved during the operation. I need it to be autonomous device (ie the computer will be connected only to upload new code).

That is how I envision the device. I just never did it like this before. I assume that I need to download the joystick library and learn how to do it, but I have never sent signals to a motor thourgh CNC shields and I have never used drivers or steppers (I used a single knob joystick once a few years ago to move a cursor in the screen just for fun... but I want to get more serious now!)

Thanks so much for reading and commenting!

  1. actually it'll be two motors because it's the Z axis (upwards-downwards) and I need some more strength, but I will simply clone the 4th motor from the 3rd motor in the CNC shield.

  2. File:Joystick Shield kit .jpg - ITEAD Wiki

Simple: you move the joystick away from you, the camera moves toward the object until you leave the joystick alone. You move the joystick towards you and the camera moves backward (away from the object), until you leave the joystick.

That should be straightforward to arrange.

You need to experiment to find what value you get from analogRead() when the joystick is in the middle.

Then your program can check the analogRead() value and if it is different from the middle position it can set a variable - let's say xMove = 1; (and -1 if the move is in the other direction AND 0 when it should not move).

And your stepper motor function can cause the stepper to move in the appropriate direction whenever it sees that xMove is not 0.

You can use exactly the same system with the buttons for the Z axis.

You can adapt the code in the second example in my Simple Stepper Code to make the moves happen. Make a separate copy of the singleStep() function for each motor and add a little code to set the direction depending on whether xMove is +1 or -1

...R

Have you never seen a 3 axis joystick? 3rd axis is the throttle lever.

With digitised sticks you also get to deal with dithering. Don't react if an analog read comes up 1 different than last time then flips between the two states like a blade of grass in the breeze.

How did you wire it up? I've got the code ready (buttons all worked on the arduino). but as soon as I put the cncshield I'm at a loss as to how to cable the buttons?

ie with the shield on I can send code to move the motors
without the shield I can simulate the motors and switches by using leds for motors

combining the 2 is proving to be a problem

@whatthecrappin, I have suggested to the Moderator to move your question to its own Thread as it is a new question and the Thread where you started your question never seemed to get to a conclusion.

Post your program and post a diagram showing how you are connecting things. See this Simple Image Guide

...R

A bit difficult to move to another new topic, when the post begins

How did you wire it up?

AWOL:
A bit difficult to move to another new topic, when the post begins

Fair enough. You da boss :slight_smile:

...R

Does or does not the shield pass through unused pins like it's supposed to?

So, you basically want your joystick to work just as if it was only comprised of 4 buttons, and pushing the stick in a direction activates that button for a single press, and you have to return the stick to neutral before you can 'press a button' again?

Sounds squiffy and unnecessary to use a joystick. It is very possible that as you try to just activate 'left' on the joystick, you inadvertently activate 'up' or 'down' because it's entirely up to your control to keep the floppy stick along the axis you want. There will be floopishness in the diagonals.

You talk about sub-mm changes. That may require you to get a set of gears to play with.

INTP:
So, you basically want your joystick to work just as if it was only comprised of 4 buttons, and pushing the stick in a direction activates that button for a single press, and you have to return the stick to neutral before you can ‘press a button’ again?

Not necessary if you read the button as down and auto-repeat the press at timed intervals, but that’s a bit crap.

An old analog stick read through 2 analog pins would work way better!

We seem to have lost the OP.

...R