Has this been done before or is it even possable

Hi I am trying to do the following I want to control a nema 23 to raise and lower a platform I have the motor and controler and both a nano and uno to control it now the difficult bit.

  1. I want top and bottom limits
  2. I want to be able to store positions in height around 20 would be ok
  3. I would like it to go to a home position touching the top limit
  4. I would like to use an encoder or keypad to select the position I want and also control manual up and down
  5. Use an LCD screen to show position that platform is at
    Is this an easy or hard project to do I have very limited programming experience
    6 has it been done before
    Thank you
    Albert

Very standard goal, it has been done literally millions of times on various platforms. Do that for 3 axes and you have most of a 3D printer.

Google "arduino single axis stepper controller" for about 200,000 hits.

Start here: Robin's Stepper Motor Basics

  1. You will need at least one limit switch.
  2. Yes.
  3. Sounds good. Maybe that's where you put the limit switch.
  4. Yes. Pretty much any encoder will work with the Arduino Encoder.h library. Keypads are easy too.
  5. Then pick out a screen from the range at Adafruit.
  6. Probably.

The LCD screen is likely to be the most time-consuming part after you've got the basic mechanics and limit switch working.

Hi I have all the mechanics and electrics all sorted including limit switches top and bottom.
It just the code I am struggling with I was going to use the uno with button shield with it built in 2 line display
Albert

bigal999:
I was going to use the uno with button shield with it built in 2 line display

You should probably treat learning to control the motors and learning to use the shield and display as two completely separate learning exercises.

And, when it comes time to build the composite program make sure to keep all the different activities in separate functions so our code does not end up tangled like a bowl of spaghetti. Have a look at Planning and Implementing a Program

...R

can any tell me what i am doing wrong here i think it should work now i have downloaded the library
Accelstepper.h
it has me baffled just learning to code
albert
const int buttonpin = 12;// jog button clockwise
const int buttonpin1 = 11;// jog button counter clockwise
int buttonState = 0;
#include <AccelStepper.h>

// define the stepper and the pins it will use
AccelStepper stepper1(1, 9, 8); // 9= step ,8= direction
AccelStepper stepper2(1, 9, 8); // 9= step ,8= direction
// define our 3 input buttons
#define LEFT_PIN 4
#define STOP_PIN 3
#define RIGHT_PIN 2

// Define our analog pot input pin
#define SPEED_PIN 0

// Define our maximum and minimum speed in steps per second (scale pot to these)
#define MAX_SPEED 5000
#define MIN_SPEED .01

void setup() {
// The only Accelstepper value we have to set here is the max speed, which is higher than you will ever go
stepper1.setMaxSpeed(10000.0)

// set up the three button inputs, with pullups
pinMode(LEFT_PIN, INPUT_PULLUP);
pinMode(STOP_PIN, INPUT_PULLUP);
pinMode(RIGHT_PIN, INPUT_PULLUP);
pinMode(buttonPin,INPUT);
pinMode(buttonPin1,INPUT);
}

void loop() {
buttonState = digitalRead(buttonPin);
static float current_speed = 0.0; // holds current motor speed in steps/second
static int analog_read_counter = 1000; //counts down to 0 to fire analog read
static char sign = 0; // holds -1, 1 or 0 to tirn motor on/off and control direction
static int analog_value = 0;

// if a switch is pushed down (low), set the sign value appropriately
if (digitalRead(LEFT_PIN) == 0) {
sign = 1;
}
else if (digitalRead(RIGHT_PIN) == 0) {
sign = 1;
}
else if (digitalRead(STOP_PIN) == 0) {
sign = 0
}

// we only want to read the pot every so often (because it takes to long time we dont
// want to do it every time trough main loop).
if (analog_read_counter > 0) {
analog_read_counter--:
}
else {
analog_read_counter = 6000;
// now read the pot (from 0 to 1023)
analog_value = anologRead(SPEED_PIN);
// give the stepper a chance to step if it needs to
stepper1.runSpeed();
// and scale the pots value from min to max speed
current_speed = sign * ((analog_value/1023.0) * (MAX_SPEED - MIN_SPEED)) + MIN_SPEED:
// UPDATE THE STEPPER TO RUN AT THIS NEW SPEED
stepper1.setSpeed(current_speed);
}

stepper1.runSpeed();

// jog button clockwise
if (digitalRead(buttonPin) ==HIGH){
current_speed = ((analog_value/1023.0) * (MAX_SPEED - MIN_SPEED)) + MIN_SPEED:
stepper1.setSpeed(-current_speed);
stepper1.runSpeed));

}
// jog button conter clockwise
if (digitalRead(buttonPin1) ==HIGH){
current_speed = ((analog_value/1023.0) * (MAX_SPEED - MIN_SPEED)) + MIN_SPEED:
stepper1.setSpeed(-current_speed);
stepper1.runSpeed));

}

}

can any tell me what i am doing wrong here

You're not using code tags, and you're not telling us what the problem is.

After 45 posts, you hadn't figured this out?

You have some nice smileys with sunglasses in your code

Opps so sorry I when trough the code again and foun some typo errors got it all working now next step it to add limits top and bottom to to be able to recorded set positions measured from home should I start a new post for this?
Albert

Forgot to say top limit will be home so all recorded positions will be measured from top limit

bigal999:
Opps so sorry I when trough the code again and foun some typo errors got it all working now next step it to add limits top and bottom to to be able to recorded set positions measured from home should I start a new post for this?
Albert

No just post the new code here in code tags.

hi all got a program thats works after a lot of head scratching,
but need to add the following

  1. top and bottom limit switches top limit switch being home position when a limit switch is hit to only move away from that position
  2. the ability to store positions any where along the track up around 20 positions
  3. to return to home position on start up
    4.to be able to select those positions by rotary encoder menu and lcd display i would like to use the Arduino uno button shield with its 2 line display.
    i plan to do this in steps so i learn as i go along i want to understand the progam not just some one do it for me?
    any ideas or help fully appreciated.
    i suffer from chronic depression and am using this as part of my therapy to make me focus on other things. so can only work on it for short spells and only on good days.
    albert

sorry here is the code so far

const int buttonPin = 12;// jog button clockwise
const int buttonPin1 = 11;// jog button counter clockwise
int buttonState = 0;
#include <AccelStepper.h>

// define the stepper and the pins it will use
AccelStepper stepper1(1, 9, 8); // 9= step ,8= direction
AccelStepper stepper2(1, 9, 8); // 9= step ,8= direction
// define our 3 input buttons
#define LEFT_PIN 4
#define STOP_PIN 3
#define RIGHT_PIN 2

// Define our analog pot input pin
#define SPEED_PIN 0

// Define our maximum and minimum speed in steps per second (scale pot to these)
#define MAX_SPEED 5000
#define MIN_SPEED .01

void setup() {
  // The only Accelstepper value we have to set here is the max speed, which is higher than you will ever go
stepper1.setMaxSpeed(10000.0);


// set up the three button inputs, with pullups
pinMode(LEFT_PIN, INPUT_PULLUP);
pinMode(STOP_PIN, INPUT_PULLUP);
pinMode(RIGHT_PIN, INPUT_PULLUP);
pinMode(buttonPin,INPUT);
pinMode(buttonPin1,INPUT);
}

void loop() {
  buttonState = digitalRead(buttonPin);
static float current_speed = 0.0; // holds current motor speed in steps/second
static int analog_read_counter = 1000; //counts down to 0 to fire analog read
static char sign = 0; // holds -1, 1 or 0 to tirn motor on/off and control direction
static int analog_value = 0;




// if a switch is pushed down (low), set the sign value appropriately
if (digitalRead(LEFT_PIN) == 0) {
  sign = 1;
}
else if (digitalRead(RIGHT_PIN) == 0) {
  sign = 1;
}
else if (digitalRead(STOP_PIN) == 0) {
  sign = 0;
  }


// we only want to read the pot every so often (because it takes to long time we dont
// want to do it every time trough main loop).
if (analog_read_counter > 0) {
  analog_read_counter--;
}
else {
  analog_read_counter = 6000;
  // now read the pot  (from 0 to 1023)
  analog_value = analogRead(SPEED_PIN);
  // give the stepper a chance to step if it needs to
  stepper1.runSpeed();
  // and scale the pots value from min to max speed
  current_speed = sign * ((analog_value/1023.0) * (MAX_SPEED - MIN_SPEED)) + MIN_SPEED;
  // UPDATE THE STEPPER TO RUN AT THIS NEW SPEED
  stepper1.setSpeed(current_speed);
}

stepper1.runSpeed();

// jog button clockwise
if (digitalRead(buttonPin) ==HIGH){
  current_speed = ((analog_value/1023.0) * (MAX_SPEED - MIN_SPEED)) + MIN_SPEED;
  stepper1.setSpeed(-current_speed);
  stepper1.runSpeed();

}
// jog button conter clockwise
if (digitalRead(buttonPin1) ==HIGH){
  current_speed = ((analog_value/1023.0) * (MAX_SPEED - MIN_SPEED)) + MIN_SPEED;
  stepper1.setSpeed(-current_speed);
  stepper1.runSpeed();


}

}/code]

bigal999:
hi all got a program thats works after a lot of head scratching,
but need to add the following

  1. top and bottom limit switches top limit switch being home position when a limit switch is hit to only move away from that position

You already have code to read jog buttons. Something very similar will work for the limit switches.

Create a variable (let's call it permittedDirection) and it can have values of 'U' (up) 'D' (down) or 'B' (both). when th up limit switch is pressed the permittedDirection should be 'D'. When it is released the value can go back to 'B'.

The motions selected by the jog buttons should first check the value of permittedDirection.

  1. to return to home position on start up

Create a moveToHome() function that contains a WHILE loop that moves the motor in single steps until the HOME limit switch is triggered. You can then call the function from setup(). I am assuming you won't want to do anything else while the home position is being set.

...R

I am still new at this could you show me in code so I can adapt it to my needs
Thank you albert

void moveToHome(void) {
set_stepper_direction();  //forward or reverse, as appropriate
while (digitalRead(limit_switch) == 0) step_one_step();
}

I have posted the code in my post here
https://forum.arduino.cc/index.php?topic=519455.new#new
Albert

bigal999:
I am still new at this could you show me in code so I can adapt it to my needs

That could be interpreted as "I'm lazy, please do the work for me"

On the other hand if you are a genuine beginner I suggest you start learning by studying the various example programs that come with the Arduino IDE and also study some of the many introductory tutorials that are available on the web. Then return to this project when you have more knowledge and experience.

...R

bigal999:
I have posted the code in my post here
Has this been done before or is it even possable - Project Guidance - Arduino Forum

Why have you two different Threads on the same project? That really p***es off people here.

Click Report to Moderator and ask to have the two Threads merged.

...R

Hi sorry if think I am lazy but due to my mental health problems and the medication I have to take I am in a constant state of struggling to lean new things once I am shown the way I can carry on by myself.
I takes me lots of attempts to do things from scratch where As before I could pick up things fast
Albert