Pulling a pin LOW with resistor; then pulling HIGH through code

Hello All,

I have two linear actuators that I want to make sure that they are aligned after "homing".
I'm trying to do that using two end-stops (W1_Home & W2_Home), one on each actuator. When one end-stop is reached I want to disable the stepper:
when W1_Home goes LOW > W1_Disable goes HIGH.

So I made a little test program which works (sort of). The output from the serial monitor shows W1_Disable going HIGH, then LOW, then HIGH again and staying there. Same for W2.
Can anyone see why that might be happening?

int W1_Home = 2;
int W2_Home = 3;
int W1_Disable = 6;
int W2_Disable = 7;

void setup() {

  Serial.begin(9600);

  pinMode(W1_Home, INPUT_PULLUP);
  pinMode(W2_Home, INPUT_PULLUP);
  pinMode(W1_Disable, INPUT);
  pinMode(W2_Disable, INPUT);
}

void loop() {

  if (digitalRead(W1_Home) == LOW) {
    W1_Disable = HIGH;
  }

  if (digitalRead(W2_Home) == LOW) {
    W2_Disable = HIGH;
  }

  Serial.print("W1");
  Serial.print("\t");
  Serial.print(digitalRead(W1_Home));
  Serial.print("\t");
  Serial.print(digitalRead(W1_Disable));
  Serial.print("\t");
  Serial.print("\t");
  Serial.print("W2");
  Serial.print("\t");
  Serial.print(digitalRead(W2_Home));
  Serial.print("\t");
  Serial.println(digitalRead(W2_Disable));
}

Also, after I get this to work , I'll want to do something like:

if (digitalRead(W_Home1) != LOW && digitalRead(W_Home2) != LOW) { // Both end-stopsLOW
    SetDisabledPinsLOW();
  }

But I can't seem to get that AND statement to work.
Schematic for the test program

Also,

What is keeping pins 2 and 3 in a known state when the buttons are not pressed ?

@UKHeliBob ,
Using the INPUT_PULLUP

pinMode(W1_Home, INPUT_PULLUP);
pinMode(W2_Home, INPUT_PULLUP);

No?

int W1_Disable = 6;
int W2_Disable = 7;

These are meant to be pin numbers but then you write them HIGH which is a value of 1 and is one of the serial pins.

if (digitalRead(W1_Home) == LOW) {
    W1_Disable = HIGH;
  }

  if (digitalRead(W2_Home) == LOW) {
    W2_Disable = HIGH;

You need to sort out your pins and your states.

Hi,
You are using the PULLUP command, that is an internal resistor is between input pin and 5V.
You need to put your Home switches between digital input and GND.

What do the two 10K resistors do?

Instead of calling your variable W1_Disable, you should call it W1_HOME, likewiser with W2, it is more descriptive of what it is.
You do not want to Disable the actuator, just stop it going in the Home direction, you still need to be able to reverse off the Home switch.

Can you please post a link to specs/data of your actuators?

Thanks. Tom.. :smiley: :+1: :coffee: :australia:

@TomGeorge Thank you, yes sorry, I made the schematic incorrectly. I do have the endstop switches going to GND pulling them LOW.


.
I think that the variables are aptly named. W1_Home is one of the endstops @ the "home" position, and the W1_Disable is a pin that "disables" the stepper motor.

I probably should have mentioned that the two actuators are controlled by two stepper controllers but both controllers are stepped by signal (pin) from the Arduino.
Here is what I' am trying to get to happen:
W1 actuator and W2 actuator are running parallel with one another. I'm using W (width) here but think X as in X-Y. So if W1 & W2 get "out of sync" then I want both W1 & W2 to travel toward HOME, if one (W1 or W2) gets to the endstop before the other, I want to disable that motor and continue to drive the other motor to it's endstop, then enable both motors to get ready to travel in the other direction.

I hope I'm am being clear. I have everything else working but I can't seem to workout the homing of two motors using two controllers but only one pin for pulses.

Thanks,
Muggs

@TomGeorge
Also, Actuator: uses a standard NEMA 23 motor
Effective Stroke: 400mm
Total Length: 599mm
Tatal Height: 80mm
Slide Width: 40mm
Maximum Horizontal Load: 25kg
Maximum Vertical Load: 15kg
Max Horizontal Speed: 150mm/s[max loading]
Max Vertical Speed: 88mm/s[max loading]
Ball Screw Model: G1610
Ball Screw Accuracy Class: C7

Stepper Motor Parameter:
Rated Voltage:
1.7v
Step angle:1.8°
Motor flange size: 57mm
Motor length: 56mm
Holding torque: 0.95 N.m
Current: 2.0A
Resistance: 1.32Ω
And Controller: DM542T

What is the purpose of the 10K resistors and the connections to pins 6 and 7 ?

@UKHeliBob
They are to insure that they stay in a stable LOW state until I pull the pins HIGH via
W1_Disable = HIGH
Those pins (6 & 7) are connected to the enable/disable connection on the controllers and are pulled HIGH to disable them.

Am I doing this wrong?

Have you read page 3 of the DM542T manual?

I have no idea, but when drawing a schematic it is usual for it to include all of the components in the circuit

@UKHeliBob Sorry! you're right.

@JCA34F This is how I understand it (Or Don't understand it more likely!)

Please post your latest code.

@cattledog This code is based on what I thought to be true; which is that pulling the Enable pin on the controller HIGH would disable the motor. However after reading @JCA34F comment, I'm not sure and getting more confused by the minute! Thanks!

int W1_Home = 2;
int W2_Home = 3;
int W1_Disable = 6;
int W2_Disable = 7;

void setup() {

  Serial.begin(9600);

  pinMode(W1_Home, INPUT_PULLUP);
  pinMode(W2_Home, INPUT_PULLUP);
  pinMode(W1_Disable, INPUT);
  pinMode(W2_Disable, INPUT);
}

void loop() {

  if (digitalRead(W1_Home) == LOW) {
    W1_Disable = HIGH; // OR Should it be (digitalWrite(W1_Disable, HIGH)
  }

  if (digitalRead(W2_Home) == LOW) {
    W2_Disable = HIGH;
  }

  Serial.print("W1");
  Serial.print("\t");
  Serial.print(digitalRead(W1_Home));
  Serial.print("\t");
  Serial.print(digitalRead(W1_Disable));
  Serial.print("\t");
  Serial.print("\t");
  Serial.print("W2");
  Serial.print("\t");
  Serial.print(digitalRead(W2_Home));
  Serial.print("\t");
  Serial.println(digitalRead(W2_Disable));
}

If you write an input pin HIGH it will only turn on the internal pullup resistor (about 30k) so 30k in series with a 10k pulldown resistor will put about 1.25V on the DM542T enable pin, too low for a HIGH.
Remove the 10k resistors and set the W1 and W2 disable pins to:

pinMode(W1_Disable,OUTPUT);
pinMode(W2_Disable,OUTPUT);

If I were doing that, I would just stop stepping in that direction when the switch is tripped, then step backward until the switch is cleared and call that home. You may have to back step the other motor a different number of steps to get them exactly even.
There are many homing algorithms in the Arduino help sites.
Search "Arduino stepper homing".
And please post your complete code. TNX

@JCA34F

Thank you, however, That still doesn't work. I'm obviously missing something in the code, but I can't for the life of me figure out why this doesn't work!

int W1_Home = 2;
int W2_Home = 3;
int W1_Disable = 6;
int W2_Disable = 7;

void setup() {

  Serial.begin(9600);

  pinMode(W1_Home, INPUT_PULLUP);
  pinMode(W2_Home, INPUT_PULLUP);
  pinMode(W1_Disable, OUTPUT);
  pinMode(W2_Disable, OUTPUT);
  W1_Disable = HIGH;
  W2_Disable = HIGH;
}

void loop() {

 CheckPins();

  Serial.print("W1");
  Serial.print("\t");
  Serial.print(digitalRead(W1_Home));
  Serial.print("\t");
  Serial.print(digitalRead(W1_Disable));
  Serial.print("\t");
  Serial.print("\t");
  Serial.print("W2");
  Serial.print("\t");
  Serial.print(digitalRead(W2_Home));
  Serial.print("\t");
  Serial.println(digitalRead(W2_Disable));
}
void CheckPins(){
 if (digitalRead(W1_Home) == LOW) {
    W1_Disable = LOW;
  }

  if (digitalRead(W2_Home) == LOW) {
    W2_Disable = LOW;
  }
}

BTW, for all intents and purposes, this the complete code as for right now I'm just trying to hold these pins at 5v until I pull them to GND.


Also, the below works when I set the switching voltage to 5v, tie the ENA+ to 5v, and just physically connect the ENA- to GND. That WILL disable the stepper!

So, the reason that I can't just do that, is because I'm using one PULSE pin to drive both steppers.

int W1_Disable = 6;
int W2_Disable = 7;

W1_Disable = HIGH;
W2_Disable = HIGH;
}

You have still not corrected the issue pointed out in reply 5.
You are confusing pin numbers with states set by digitalWrite() of the pin numbers.

@cattledog
Thank you! This works a treat! I'm so sorry I missed that!

int W1_Home = 2;
int W2_Home = 3;
int W1_Disable = 6;
int W2_Disable = 7;

void setup() {

  Serial.begin(9600);

  pinMode(W1_Home, INPUT_PULLUP);
  pinMode(W2_Home, INPUT_PULLUP);
  pinMode(W1_Disable, OUTPUT);
  pinMode(W2_Disable, OUTPUT);
  digitalWrite(W1_Disable,HIGH);
  digitalWrite(W2_Disable,HIGH);
}

void loop() {

 CheckPins();

  Serial.print("W1");
  Serial.print("\t");
  Serial.print(digitalRead(W1_Home));
  Serial.print("\t");
  Serial.print(digitalRead(W1_Disable));
  Serial.print("\t");
  Serial.print("\t");
  Serial.print("W2");
  Serial.print("\t");
  Serial.print(digitalRead(W2_Home));
  Serial.print("\t");
  Serial.println(digitalRead(W2_Disable));
}
void CheckPins(){
 if (digitalRead(W1_Home) == LOW) {
    digitalWrite(W1_Disable,LOW);
  }

  if (digitalRead(W2_Home) == LOW) {
    digitalWrite(W2_Disable,LOW);
  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.