Notifications
Clear all

Arduino with Stepper and LiquidCrystal Issue

Page 8 / 21

Will
 Will
(@will)
Noble Member
Joined: 11 months ago
Posts: 1764
 
Posted by: @voltage

I didn't test the last version but I did the two on the one post above. When the RPM comes down from 15, after you go past 10, the 9 shows up as a 90 and the counts down from 90, 89, 87, etc

That's because you need to write blanks over the area to clear out the last result. You'll see me writing blanks over the speed area in my old code.

I was kidnapped by mimes.
They did unspeakable things to me.


ReplyQuote
MadMisha
(@madmisha)
Reputable Member
Joined: 2 years ago
Posts: 319
 
Posted by: @will

Maybe it's worth moving all of the LCD display commands into a subroutine. That way it'll be easy to update from anywhere and the data will always be placed in the same area.

That wouldn't solve the problem. The interrupt could happen anywhere. That's why I just put all the randomly updating values on the second line in the last iteration and ended the interrupt with the cursor beginning on the second line. If it happens to be on the wrong value to write, it should write over it in the next loop.


ReplyQuote
Will
 Will
(@will)
Noble Member
Joined: 11 months ago
Posts: 1764
 

@madmisha

You'll need to use blanks overwrite any datum which may change to a shorter length (like speeds) since @voltage is already observing some field contamination.

I was kidnapped by mimes.
They did unspeakable things to me.


ReplyQuote
MadMisha
(@madmisha)
Reputable Member
Joined: 2 years ago
Posts: 319
 
Posted by: @voltage

I didn't test the last version but I did the two on the one post above. When the RPM comes down from 15, after you go past 10, the 9 shows up as a 90 and the counts down from 90, 89, 87, etc

Ok, another one to try:

 

//Test of accelstepper with LCD and pot

#include <AccelStepper.h>
#include <LiquidCrystal.h>

//Define pins
int LEFT_PIN = 11;
int STOP_PIN = 2;
int RIGHT_PIN = 3;
int driverPUL = 12;    // PUL- pin
int driverDIR = 13;    // DIR- pin
int spd = A1;     // Potentiometer
bool go = false;  //Is it running
bool dirFor = true; //Direction to go in

AccelStepper stepper(1,driverPUL,driverDIR); // This needs to change in any example(Mode, Pul, Dir)

LiquidCrystal lcd(8,9,4,5,6,7); //Setup LCD

//Interupt Handlers
void formotor (){

  dirFor = true;
  go = true;
  
}

void bacmotor (){

  lcd.setCursor(7,0);
    if (dirFor){
      lcd.print("Right");
    } else {
      lcd.print("Left ");
    }
  go = true;
  lcd.setCursor(0,1);
  
}

void stpmotor (){

  if(go){
    stepper.stop();
    go = false;
  } else {
    dirFor = !dirFor;
    lcd.setCursor(7,0);
    if (dirFor){
      lcd.print("Right");
    } else {
      lcd.print("Left ");
    }   
  }  
  lcd.setCursor(0,1);
}


void setup()
{  
   //pinMode(LEFT_PIN, INPUT_PULLUP);
   pinMode(STOP_PIN, INPUT_PULLUP);
   pinMode(RIGHT_PIN, INPUT_PULLUP);

   //attachInterrupt(digitalPinToInterrupt(LEFT_PIN), formotor, FALLING);
   attachInterrupt(digitalPinToInterrupt(RIGHT_PIN), bacmotor, FALLING);
   attachInterrupt(digitalPinToInterrupt(STOP_PIN), stpmotor, FALLING);
   
   //stepper.setPinsInverted(false, true, false);
   stepper.setMaxSpeed(1000);
   stepper.setMinPulseWidth(2.7);

   lcd.begin(16, 2);
   lcd.setCursor(1,0);
   lcd.print("Speed:");
   lcd.setCursor(13,0);
   lcd.print("RPM");
   lcd.setCursor(7,0);
   if(dirFor){
    lcd.print("Right");
   } else {
    lcd.print("Left ");
    }
}

void loop()
{
  int sp_pot = map((analogRead(spd)),0,1023,50,1000);
  if(go == true){
    if(dirFor == true){
      stepper.setSpeed(sp_pot);
    } else {
      stepper.setSpeed((sp_pot*-1));
    }
    stepper.runSpeed();
    lcd.setCursor(0,1);
    lcd.print(((sp_pot/4.25)/400)*3);
    stepper.runSpeed();
    lcd.setCursor(12,1);
    lcd.print(map(sp_pot, 0, 1000, 0, 15)+ " ");
    stepper.runSpeed();
  } else {
    stepper.stop();
    lcd.setCursor(0,1);
    lcd.print(((sp_pot/4.25)/400)*3);
    lcd.setCursor(12,1);
    lcd.print(map(sp_pot, 0, 1000, 0, 15)+ " ");
  }
}

 

 @will The diameter you be in place of the speed, if that was not needed. That way it would show Diameter and RPM. But RPM matters and changes based on the diameter of the part. So the it would be a calculation of the current RPM and what size of part would be needed for that RPM. So if you adjusted it to the size of the part, it would be spinning at the correct speed. Did that make sense at all?


ReplyQuote
Voltage
(@voltage)
Estimable Member
Joined: 10 months ago
Posts: 169
Topic starter  
Posted by: @will
Posted by: @madmisha
Posted by: @will

I'm not sure why you're displaying anything but the RPM  as speed. I doubt if @Voltage would be interested in that since I believe he's only concerned about RPM.

Only because that's what the original had. If we verify that the RPMs are working out correctly, that can always change to a diameter reading.

OK, I see.

How/where will the diameter be read in ?

I just need the final calculated RPM's of the final drive shaft which has either a platter or a lathe chuck mounted. The way I get set up is by using a piece of masking tape that I draw 1/8" increments on it and tape it to the circumference of the part. Then I hold my torch tip over the tape and run the unit while counting seconds (1,001, 1,002, 1,003) and set the speed to about 1/8" per second. Then once the part is welded and the timing is good I can note that a 3" diameter pipe has a good starting point of "x" rpm's.

 

Thanks,
Voltage


ReplyQuote
Will
 Will
(@will)
Noble Member
Joined: 11 months ago
Posts: 1764
 
Posted by: @madmisha

 @will The diameter you be in place of the speed, if that was not needed. That way it would show Diameter and RPM. But RPM matters and changes based on the diameter of the part. So the it would be a calculation of the current RPM and what size of part would be needed for that RPM. So if you adjusted it to the size of the part, it would be spinning at the correct speed. Did that make sense at all?

So what we're really trying to do is come up with a chuck's rotational speed which results in a fixed speed for a point on the circumference of the work piece ?

I was kidnapped by mimes.
They did unspeakable things to me.


ReplyQuote
MadMisha
(@madmisha)
Reputable Member
Joined: 2 years ago
Posts: 319
 
Posted by: @will

So what we're really trying to do is come up with a chuck's rotational speed which results in a fixed speed for a point on the circumference of the work piece ?

Exactly! It will take some fooling around but I bet it can be done.


ReplyQuote
Will
 Will
(@will)
Noble Member
Joined: 11 months ago
Posts: 1764
 

@madmisha @voltage

So, shall we switch over to using the pot to enter the diameter and then calculate the RPMs needed to produce a rotation of 1/8" per second on the surface ?

That should be pretty easy to do.

I was kidnapped by mimes.
They did unspeakable things to me.


ReplyQuote
Voltage
(@voltage)
Estimable Member
Joined: 10 months ago
Posts: 169
Topic starter  
Posted by: @madmisha
Posted by: @will

So what we're really trying to do is come up with a chuck's rotational speed which results in a fixed speed for a point on the circumference of the work piece ?

Exactly! It will take some fooling around but I bet it can be done.

Correct. It's still up to the end user welding to figure out and fine tune things for it to work. Small diameter and large diameter at the same exact rpm are way different. Like watching a 33 1/3 record spin on a turntable, the outer edge is going faster. Anyway, on the last update the LCD has gone goofy. Maybe too much info. Speed: XXX RPMS is all I need on one line. That is what I had and always worked before. 😀 Here are some pics of the LCD freaking out and I can make it happen with successive STOP(Direction Change) button presses.

image 2
image 3
image 1
image 5
image 4
image 6
image 7
image 9
image 8
image 12
image 10
image 11
image 13
image 14
image 15

Thanks,
Voltage


ReplyQuote
Voltage
(@voltage)
Estimable Member
Joined: 10 months ago
Posts: 169
Topic starter  
Posted by: @will

@madmisha @voltage

So, shall we switch over to using the pot to enter the diameter and then calculate the RPMs needed to produce a rotation of 1/8" per second on the surface ?

That should be pretty easy to do.

I guess we could try and see how it works but in welding there are a lot of different things going on. If you weld aluminum for example it will be different than welding steel but maybe that will work. Lets try and see what happens. 😎 

 

Thanks,
Voltage


ReplyQuote
MadMisha
(@madmisha)
Reputable Member
Joined: 2 years ago
Posts: 319
 

@voltage

I guess that's what overflow looks like.

 

//Test of accelstepper with LCD and pot

#include <AccelStepper.h>
#include <LiquidCrystal.h>

//Define pins
int LEFT_PIN = 11;
int STOP_PIN = 2;
int RIGHT_PIN = 3;
int driverPUL = 12;    // PUL- pin
int driverDIR = 13;    // DIR- pin
int spd = A1;     // Potentiometer
bool go = false;  //Is it running
bool dirFor = true; //Direction to go in

AccelStepper stepper(1,driverPUL,driverDIR); // This needs to change in any example(Mode, Pul, Dir)

LiquidCrystal lcd(8,9,4,5,6,7); //Setup LCD

//Interupt Handlers
void formotor (){

  dirFor = true;
  go = true;
  
}

void bacmotor (){

  lcd.setCursor(7,0);
    if (dirFor){
      lcd.print("Right");
    } else {
      lcd.print("Left ");
    }
  go = true;
  lcd.setCursor(0,1);
  
}

void stpmotor (){

  if(go){
    stepper.stop();
    go = false;
  } else {
    dirFor = !dirFor;
    lcd.setCursor(7,0);
    if (dirFor){
      lcd.print("Right");
    } else {
      lcd.print("Left ");
    }   
  }  
  lcd.setCursor(0,1);
}


void setup()
{  
   //pinMode(LEFT_PIN, INPUT_PULLUP);
   pinMode(STOP_PIN, INPUT_PULLUP);
   pinMode(RIGHT_PIN, INPUT_PULLUP);

   //attachInterrupt(digitalPinToInterrupt(LEFT_PIN), formotor, FALLING);
   attachInterrupt(digitalPinToInterrupt(RIGHT_PIN), bacmotor, FALLING);
   attachInterrupt(digitalPinToInterrupt(STOP_PIN), stpmotor, FALLING);
   
   //stepper.setPinsInverted(false, true, false);
   stepper.setMaxSpeed(1000);
   stepper.setMinPulseWidth(2.7);

   lcd.begin(16, 2);
   lcd.setCursor(1,0);
   lcd.print("Speed:");
   lcd.setCursor(13,0);
   lcd.print("RPM");
   lcd.setCursor(7,0);
   if(dirFor){
    lcd.print("Right");
   } else {
    lcd.print("Left ");
    }
}

void loop()
{
  int sp_pot = map((analogRead(spd)),0,1023,50,1000);
  if(go == true){
    if(dirFor == true){
      stepper.setSpeed(sp_pot);
    } else {
      stepper.setSpeed((sp_pot*-1));
    }
    stepper.runSpeed();
    lcd.setCursor(0,1);
    lcd.print(((sp_pot/4.25)/400)*3);
    stepper.runSpeed();
    lcd.setCursor(12,1);
    lcd.print("   ";
    stepper.runSpeed();
    lcd.setCursor(12,1);
    lcd.print(map(sp_pot, 0, 1000, 0, 15));
    stepper.runSpeed();
  } else {
    stepper.stop();
    lcd.setCursor(0,1);
    lcd.print(((sp_pot/4.25)/400)*3);
    lcd.setCursor(12,1);
    lcd.print("   ";
    lcd.setCursor(12,1);
    lcd.print(map(sp_pot, 0, 1000, 0, 15));
  }
}

 


ReplyQuote
Will
 Will
(@will)
Noble Member
Joined: 11 months ago
Posts: 1764
 
Posted by: @voltage
Posted by: @will

@madmisha @voltage

So, shall we switch over to using the pot to enter the diameter and then calculate the RPMs needed to produce a rotation of 1/8" per second on the surface ?

That should be pretty easy to do.

I guess we could try and see how it works but in welding there are a lot of different things going on. If you weld aluminum for example it will be different than welding steel but maybe that will work. Lets try and see what happens. 😎 

You'll still be able to vary the speed by changing the diameter up or down to speed up or slow down the rotation speed.

MadMisha, do you think there's enough time savings in using interrupts, or could this revert to if statements in the loop ?

I was kidnapped by mimes.
They did unspeakable things to me.


ReplyQuote
MadMisha
(@madmisha)
Reputable Member
Joined: 2 years ago
Posts: 319
 
Posted by: @will

MadMisha, do you think there's enough time savings in using interrupts, or could this revert to if statements in the loop ?

As long as you use stepper.runSpeed() any time you get the chance, it should be ok. But not having to check buttons all the time is usually better. Or possible missing them can be a pain too.


ReplyQuote
MadMisha
(@madmisha)
Reputable Member
Joined: 2 years ago
Posts: 319
 

I have to go tour a construction site. I will be back later to catch up. Feel free to mess around with the code all you want.


ReplyQuote
Voltage
(@voltage)
Estimable Member
Joined: 10 months ago
Posts: 169
Topic starter  
Posted by: @madmisha

@voltage

I guess that's what overflow looks like.

 

//Test of accelstepper with LCD and pot

#include <AccelStepper.h>
#include <LiquidCrystal.h>

//Define pins
int LEFT_PIN = 11;
int STOP_PIN = 2;
int RIGHT_PIN = 3;
int driverPUL = 12;    // PUL- pin
int driverDIR = 13;    // DIR- pin
int spd = A1;     // Potentiometer
bool go = false;  //Is it running
bool dirFor = true; //Direction to go in

AccelStepper stepper(1,driverPUL,driverDIR); // This needs to change in any example(Mode, Pul, Dir)

LiquidCrystal lcd(8,9,4,5,6,7); //Setup LCD

//Interupt Handlers
void formotor (){

  dirFor = true;
  go = true;
  
}

void bacmotor (){

  lcd.setCursor(7,0);
    if (dirFor){
      lcd.print("Right");
    } else {
      lcd.print("Left ");
    }
  go = true;
  lcd.setCursor(0,1);
  
}

void stpmotor (){

  if(go){
    stepper.stop();
    go = false;
  } else {
    dirFor = !dirFor;
    lcd.setCursor(7,0);
    if (dirFor){
      lcd.print("Right");
    } else {
      lcd.print("Left ");
    }   
  }  
  lcd.setCursor(0,1);
}


void setup()
{  
   //pinMode(LEFT_PIN, INPUT_PULLUP);
   pinMode(STOP_PIN, INPUT_PULLUP);
   pinMode(RIGHT_PIN, INPUT_PULLUP);

   //attachInterrupt(digitalPinToInterrupt(LEFT_PIN), formotor, FALLING);
   attachInterrupt(digitalPinToInterrupt(RIGHT_PIN), bacmotor, FALLING);
   attachInterrupt(digitalPinToInterrupt(STOP_PIN), stpmotor, FALLING);
   
   //stepper.setPinsInverted(false, true, false);
   stepper.setMaxSpeed(1000);
   stepper.setMinPulseWidth(2.7);

   lcd.begin(16, 2);
   lcd.setCursor(1,0);
   lcd.print("Speed:");
   lcd.setCursor(13,0);
   lcd.print("RPM");
   lcd.setCursor(7,0);
   if(dirFor){
    lcd.print("Right");
   } else {
    lcd.print("Left ");
    }
}

void loop()
{
  int sp_pot = map((analogRead(spd)),0,1023,50,1000);
  if(go == true){
    if(dirFor == true){
      stepper.setSpeed(sp_pot);
    } else {
      stepper.setSpeed((sp_pot*-1));
    }
    stepper.runSpeed();
    lcd.setCursor(0,1);
    lcd.print(((sp_pot/4.25)/400)*3);
    stepper.runSpeed();
    lcd.setCursor(12,1);
    lcd.print("   ";
    stepper.runSpeed();
    lcd.setCursor(12,1);
    lcd.print(map(sp_pot, 0, 1000, 0, 15));
    stepper.runSpeed();
  } else {
    stepper.stop();
    lcd.setCursor(0,1);
    lcd.print(((sp_pot/4.25)/400)*3);
    lcd.setCursor(12,1);
    lcd.print("   ";
    lcd.setCursor(12,1);
    lcd.print(map(sp_pot, 0, 1000, 0, 15));
  }
}

DSCF3278  resized

Image above is from my first build of this and how the LCD display outputted the RPM's.

This version has the LCD all messed up. The compiled code when uploaded to the UNO shows the RPM number lower right in red or some other color. Did you program that like that?

I think it may be best to just set it like I used to have it:

SPEED: xx.x RPMS

Thanks,
Voltage


ReplyQuote
Page 8 / 21