Notifications
Clear all

Arduino with Stepper and LiquidCrystal Issue

Page 11 / 21

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

@voltage @madmisha

To help illustrate the calculations I use for converting diameter into RPM, let's use an example with stock diameter 5".

5" diameter gives a circumference of 5 x pi = 15.71 inches (close)

15.71 inches has 15.71 x 8 eight'ths of an inch = 

so there are 125.68 eights of an inch along the circumference of the bar

but the circumference equal 5100 steps (3 x 4.25 x 400)

5100 steps = 125.68 eight'ths of an inch

1 eight'th/second = 5100/125.68 = 40.58 steps/second

40.58 steps/second x 60 seconds per minute = 2434.8 steps/minute

then 2434.8 steps/min = 0.477 RPM

Ok, I compiled and ran the last sketch and I counted 13.75 RPM's with the same setting of 0.50 diameter and 4.76 RPM which is about right on @4.58 after the chain and sprockets. Good job! Yours is most likely more accurate than my finger hitting the flag tape on the output shaft and counting. 😋 Let me think on this overnight and further soak it in but it looks great to me. But my wife will be here shortly to cook supper. 🍺 I appreciate all the work from both of you guys helping me with this.

 

Don't change anything as it seems correct but I will make a bunch of tests tomorrow and take notes. Earlier the output was less as noted but sometimes we may be talking about the sketch before or after a mod. I have been marking the sketches at the top so I know which one we are using with this format:

sketch_aug06e-Will-Mod-4

That is the current final one for today.

 

Thanks,
Voltage


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

@voltage

Sounds like we have the problem on the run.

I have one more new version which has some slight improvements, but I'll wait until you say you're ready for it tomorrow.

I'd also like @madmisha to check it over as well to see what improvements he can suggest.

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: @will

@voltage

Sounds like we have the problem on the run.

I have one more new version which has some slight improvements, but I'll wait until you say you're ready for it tomorrow.

I'd also like @madmisha to check it over as well to see what improvements he can suggest.

Ok great. All the stuff is put up for today. I appreciate you and madmisha. Take a break for today. I may check in later but won't able to test anything until tomorrow. Thanks again!

 

Thanks,
Voltage


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

@voltage

That's what we're here for.

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


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

@voltage @will

That jitter in the pot was why I suggested an encoder before. Store the value as an int and adjust it up and down. If you want to experiment with that then I look into a way of having the move go into a buffer so that we wouldn't miss steps. Or try it without and see how it does. I do not have a spare LCD like that around so I can't test right away.

Now that I know it only has 2 interrupts, my 4 button idea won't work. I really liked that one too.

 

That error you saw that was like 5000 when it was actually 50 was an update error. I did not clear the last 2 digits when it went down to a 2 digit number. There might be something in the sprint function that can always print it as a 4 digit number. It might be better than if statements. It will still be an issue now though.

 

Before going any further, I would test out the largest, smallest and heaviest pieces to make sure you get the speeds you need when it has a load. You wouldn't want to have to rework your formulas because you needed more torque.

 

You could also use and E-Stop button and pass the enable signal through it. That will take care of your stop and start and the 2 interrupts can be up and down speed. Precise and responsive. There would be no need for updating the screen if it wasn't pressed. That would also mean the ability to do more to make the screen better. Direction can be a quick poll of a button or even a toggle switch in an if statement. Instead of go, it can pull the 5V signal looped back from the E-stop. That's where you can check direction before starting and prevent it from reversing while it's going full speed. Many option and configurations.

 

And/Or, you can always use the 4 buttons on the LCD board. I will have to look up some things on that. I kind of wish I had one so I can see what the delay is if polled once in a loop.

 

Just some random thoughts.


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

@voltage @will

That jitter in the pot was why I suggested an encoder before. Store the value as an int and adjust it up and down. If you want to experiment with that then I look into a way of having the move go into a buffer so that we wouldn't miss steps. Or try it without and see how it does. I do not have a spare LCD like that around so I can't test right away.

Now that I know it only has 2 interrupts, my 4 button idea won't work. I really liked that one too.

 

That error you saw that was like 5000 when it was actually 50 was an update error. I did not clear the last 2 digits when it went down to a 2 digit number. There might be something in the sprint function that can always print it as a 4 digit number. It might be better than if statements. It will still be an issue now though.

 

Before going any further, I would test out the largest, smallest and heaviest pieces to make sure you get the speeds you need when it has a load. You wouldn't want to have to rework your formulas because you needed more torque.

 

You could also use and E-Stop button and pass the enable signal through it. That will take care of your stop and start and the 2 interrupts can be up and down speed. Precise and responsive. There would be no need for updating the screen if it wasn't pressed. That would also mean the ability to do more to make the screen better. Direction can be a quick poll of a button or even a toggle switch in an if statement. Instead of go, it can pull the 5V signal looped back from the E-stop. That's where you can check direction before starting and prevent it from reversing while it's going full speed. Many option and configurations.

 

And/Or, you can always use the 4 buttons on the LCD board. I will have to look up some things on that. I kind of wish I had one so I can see what the delay is if polled once in a loop.

 

Just some random thoughts.

The jitter bothers me too because it means that the LCD display code will be called even when the pot hasn't been moved. The code, as it stands, will execute irregularly because it won't pass through the loop in the same time every pass. That's because sometimes it will have to read the pot, recalculate and display both the speed and RPM.

That's why I wanted to move those calculations out of the loop and into the stop button, so it could be done external to the loop. Then the loop would always take the same time to execute and the resulting speed would be more steady and reliable (and closer to the calculated speed).

The current code can be improved by declaring a jitter limit and only entering the speed calc when the absolute difference between the current pot reading and the previous pot reading exceeds the limit (e.g. 5). That reduces the time that's wasted in recalculating changes caused by small jittering.

If the speed calculation and display were performed in the "!go" section of the loop then even the pot jitter would have no material effect on loop time, unless the motor was stopped in which case it couldn't be slowed anyway. Unfortunately, loss of the ability to "fine tune" the rotation while it's actually occurring seems like a heavy penalty 🙁

I'm not sure that an encoder would work in this case. The pot value ranges from 0 to 1023 and I think it would be very tedious turning the encoder 1023 clicks get the maximum 🙂

So far I think that the LCD display is working. The pot is now reading a diameter in hundredths of an inch and calculating the steps/second which is sent to the stepper and the RPM. It displays the diameter on the first line and the RPM on the second line. The LCD is wiped with blanks before the next value is displayed and seems to be working satisfactorily from the few tests done.

Preliminary tests seem to indicate that the RPMs reflect a fairly appropriate value for the diameter selected, but a lot more testing is required.

I don't think that a live test will be possible at this point, I believe it's all just loosely wired pieces on his kitchen table 🙂

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


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

@voltage @will

Ok, I have a test. I want to see how bad of a delay there is using the buttons on the shield. It will also let us know how some of the following things interact: Switch case(great if we want/need to add more buttons), screen update as a function, screen update without the interrupt changing the cursor location, digital selection of speed.

 

I do not know what version you have so if you have the 1.0 instead of the 1.1 do the comment and uncomment in the asterisks.

 

Display will only show the 50-1000 value right now so that you see that it is working properly. Small increment go up and down 1 and large up by 10. It is easy to drop in the formulas later that you both have been working on.

 

Select Button: Start and Stop

Left Button: Change direction

Right Button: How fast it increments when changing value(can be adjusted or changed to digit instead)

Up Button: Increment up based on slow or fast that is selected by right button

Down Button: Increment down based on slow or fast that is selected by right button

 

Up and down could eventually change it by the finest parameter when go is active. So diameter at first but after it starts it will adjust RPM? Or something like that. Whatever mean you want.

 

There is another method of doing this if you like the concept but it doesn't register the presses right. Or a delay is not right.

 

 

//Shield button test. Ripped off of:
//Voltage Version sketch_aug06e-Will-Mod-4
//Test of accelstepper with LCD and shield buttons

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

//Define pins
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5
int driverPUL = 12;    // PUL- pin
int driverDIR = 13;    // DIR- pin
//int spd = A1;          // Potentiometer
//int dia, old_dia = 0;  // Last pot reading
bool go = false;  //Is it running
bool dirFor = true; //Direction to go in
int smInc = 1;      //Small increase
int lgInc = 10;      //Large increase
bool slChange = true; //Slow change
int drive = 70;     //Raw Speed Number
//float sps;             // Sets per second for this diameter
//float RPM;             // RPM for this diameter 

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

//Shield buttons read (IF VERSION 1.0 SHIELD, LET ME KNOW!)
int read_LCD_buttons() {
 adc_key_in = analogRead(0);      // read the value from the sensor
 // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
 // we add approx 50 to those values and check to see if we are close
 if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
 
 
 //********************Block comment here is need changing based on version******
 // For V1.1 us this threshold
 if (adc_key_in < 50)   return btnRIGHT;
 if (adc_key_in < 250)  return btnUP;
 if (adc_key_in < 450)  return btnDOWN;
 if (adc_key_in < 650)  return btnLEFT;
 if (adc_key_in < 850)  return btnSELECT;
 //********************End Block comment*************************************

//*************Uncomment if you have the V1.0***********************************
  // For V1.0 comment the other threshold and use the one below:
/*
 if (adc_key_in < 50)   return btnRIGHT;
 if (adc_key_in < 195)  return btnUP;
 if (adc_key_in < 380)  return btnDOWN;
 if (adc_key_in < 555)  return btnLEFT;
 if (adc_key_in < 790)  return btnSELECT;
*/
//************************End of uncomment*****************************************

return btnNONE;  // when all others fail
}

void screen() {
  lcd.setCursor(5,0);                               // Update LCD
  lcd.print("      ");                              //Only a test
  lcd.setCursor(5,0);
  lcd.print(drive);
  lcd.setCursor(5,1);
  lcd.print("      ");
  lcd.setCursor(5,1);
  lcd.print( (dirFor) ? drive : -drive);
}

void setup() {  
   stepper.setMaxSpeed(1000);
   stepper.setMinPulseWidth(2.7);
   stepper.setSpeed(drive);

   lcd.begin(16, 2);
   lcd.setCursor(1,0);
   lcd.print("Dia:");
   lcd.setCursor(1,1);
   lcd.print("RPM:");
}

void loop() {
  if (go){
    stepper.runSpeed();
  } else {
    stepper.stop();
  }
  int lcd_key = read_LCD_buttons();

  switch (lcd_key)               // depending on which button was pushed, we perform an action
  {
   case btnRIGHT:
     {
     !slChange;
     break;
     }
   case btnLEFT:
     {
     !dirFor;
     break;
     }
   case btnUP:
     {
     if(slChange){
      if(drive <= (1000 - smInc)){
        drive = drive + smInc;
      }   
     } else if (drive <= (1000 - lgInc)){
        drive = drive + lgInc;
     }
     if (dirFor){
        stepper.setSpeed(drive);
     } else {
        stepper.setSpeed(!drive);
     }
     screen();
     break;
     }
   case btnDOWN:
     {
     if(slChange){
      if(drive >= (1000 + smInc)){
        drive = drive - smInc;
      }   
     } else if (drive >= (50 + lgInc)){
        drive = drive - lgInc;
     }
      if (dirFor){
        stepper.setSpeed(drive);
     } else {
        stepper.setSpeed(!drive);
     }
     screen();
     break;
     }
   case btnSELECT:
     {
     !go;
     break;
     }
     case btnNONE:
     {
     break;
     }
  }  
}

 

 


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

@madmisha @voltage

Voltage has run preliminary tests on the existing version and everything tested seems to be OK. He said he's going to do more detailed testing and make notes tomorrow.

Unless tomorrow's testing goes badly or unless Voltage feels that the extra buttons for setting the target whatever would be better for him than using a potentiometer, there seems little point in starting over with a brand new sketch.

We'll have to wait for Voltage's decision tomorrow.

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

@voltage @will

That jitter in the pot was why I suggested an encoder before. Store the value as an int and adjust it up and down. If you want to experiment with that then I look into a way of having the move go into a buffer so that we wouldn't miss steps. Or try it without and see how it does. I do not have a spare LCD like that around so I can't test right away.

Now that I know it only has 2 interrupts, my 4 button idea won't work. I really liked that one too.

 

That error you saw that was like 5000 when it was actually 50 was an update error. I did not clear the last 2 digits when it went down to a 2 digit number. There might be something in the sprint function that can always print it as a 4 digit number. It might be better than if statements. It will still be an issue now though.

 

Before going any further, I would test out the largest, smallest and heaviest pieces to make sure you get the speeds you need when it has a load. You wouldn't want to have to rework your formulas because you needed more torque.

 

You could also use and E-Stop button and pass the enable signal through it. That will take care of your stop and start and the 2 interrupts can be up and down speed. Precise and responsive. There would be no need for updating the screen if it wasn't pressed. That would also mean the ability to do more to make the screen better. Direction can be a quick poll of a button or even a toggle switch in an if statement. Instead of go, it can pull the 5V signal looped back from the E-stop. That's where you can check direction before starting and prevent it from reversing while it's going full speed. Many option and configurations.

 

And/Or, you can always use the 4 buttons on the LCD board. I will have to look up some things on that. I kind of wish I had one so I can see what the delay is if polled once in a loop.

 

Just some random thoughts.

Random thoughts have been read. I won't be able to test it for a while in use as it's just a project on the counter based on the one I already built. I am going to build a portable version using this and thought I would start with a new build. I don't mind the idea of other code to test but simple is good and I am just a hobbyist welder so no production issues here. At the moment with the last code the display looks pretty stable and could likely be made better with a multi-turn pot but I have a bunch of new Bourn 10k 280 degree turn pots so I may as well use one. All your ideas sound great but I don't always understand everything you say until I put it to the test. The display at the moment sometimes will display a number after I change directions (like a 22), but I it doesn't look like a buffer overflow. I also noticed with this current code when I unplug and plug back in the usb cable to the laptop, the code runs. More info in the next posts...

 

Thanks,
Voltage


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

@voltage @will

That jitter in the pot was why I suggested an encoder before. Store the value as an int and adjust it up and down. If you want to experiment with that then I look into a way of having the move go into a buffer so that we wouldn't miss steps. Or try it without and see how it does. I do not have a spare LCD like that around so I can't test right away.

Now that I know it only has 2 interrupts, my 4 button idea won't work. I really liked that one too.

 

That error you saw that was like 5000 when it was actually 50 was an update error. I did not clear the last 2 digits when it went down to a 2 digit number. There might be something in the sprint function that can always print it as a 4 digit number. It might be better than if statements. It will still be an issue now though.

 

Before going any further, I would test out the largest, smallest and heaviest pieces to make sure you get the speeds you need when it has a load. You wouldn't want to have to rework your formulas because you needed more torque.

 

You could also use and E-Stop button and pass the enable signal through it. That will take care of your stop and start and the 2 interrupts can be up and down speed. Precise and responsive. There would be no need for updating the screen if it wasn't pressed. That would also mean the ability to do more to make the screen better. Direction can be a quick poll of a button or even a toggle switch in an if statement. Instead of go, it can pull the 5V signal looped back from the E-stop. That's where you can check direction before starting and prevent it from reversing while it's going full speed. Many option and configurations.

 

And/Or, you can always use the 4 buttons on the LCD board. I will have to look up some things on that. I kind of wish I had one so I can see what the delay is if polled once in a loop.

 

Just some random thoughts.

The jitter bothers me too because it means that the LCD display code will be called even when the pot hasn't been moved. The code, as it stands, will execute irregularly because it won't pass through the loop in the same time every pass. That's because sometimes it will have to read the pot, recalculate and display both the speed and RPM.

That's why I wanted to move those calculations out of the loop and into the stop button, so it could be done external to the loop. Then the loop would always take the same time to execute and the resulting speed would be more steady and reliable (and closer to the calculated speed).

The current code can be improved by declaring a jitter limit and only entering the speed calc when the absolute difference between the current pot reading and the previous pot reading exceeds the limit (e.g. 5). That reduces the time that's wasted in recalculating changes caused by small jittering.

If the speed calculation and display were performed in the "!go" section of the loop then even the pot jitter would have no material effect on loop time, unless the motor was stopped in which case it couldn't be slowed anyway. Unfortunately, loss of the ability to "fine tune" the rotation while it's actually occurring seems like a heavy penalty 🙁

I'm not sure that an encoder would work in this case. The pot value ranges from 0 to 1023 and I think it would be very tedious turning the encoder 1023 clicks get the maximum 🙂

So far I think that the LCD display is working. The pot is now reading a diameter in hundredths of an inch and calculating the steps/second which is sent to the stepper and the RPM. It displays the diameter on the first line and the RPM on the second line. The LCD is wiped with blanks before the next value is displayed and seems to be working satisfactorily from the few tests done.

Preliminary tests seem to indicate that the RPMs reflect a fairly appropriate value for the diameter selected, but a lot more testing is required.

I don't think that a live test will be possible at this point, I believe it's all just loosely wired pieces on his kitchen table 🙂

Some new things to work on. The project is loosely wired on the kitchen counter but I cut a circle close to 3" diameter for testing(I have to make one more accurate this one is 2-7/8"), and when I set it for that diameter is seems the stepper is twice as fast...Yikes. I forgot the 3:1 part in my test. Ok, here are the numbers anyway. In order to get the output shaft on the gearbox to move 1/8" per second, I have to set the diameter to 7.10 and that leaves an output RPM of 0.33 so we should be able to do the math from there. So if we divide that by 3 it equals 0.11 which is close to (.125 or 1/8"). I think I need to do another test. 😋 What would be a good test? Try again with a more accurate circle like 3" and we could do the math from there? This test may be tricky to accomplish.

 

edit: Maybe easier than I thought. Just mark 3/8 increments on the test wheel as that would end up divided by 3 with the sprockets...Back to the kitchen!

 

Thanks,
Voltage


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

Some new things to work on. The project is loosely wired on the kitchen counter but I cut a circle close to 3" diameter for testing(I have to make one more accurate this one is 2-7/8"), and when I set it for that diameter is seems the stepper is twice as fast...Yikes. I forgot the 3:1 part in my test. Ok, here are the numbers anyway. In order to get the output shaft on the gearbox to move 1/8" per second, I have to set the diameter to 7.10 and that leaves an output RPM of 0.33 so we should be able to do the math from there. So if we divide that by 3 it equals 0.11 which is close to (.125 or 1/8"). I think I need to do another test. 😋 What would be a good test? Try again with a more accurate circle like 3" and we could do the math from there? This test may be tricky to accomplish.

 

edit: Maybe easier than I thought. Just mark 3/8 increments on the test wheel as that would end up divided by 3 with the sprockets...Back to the kitchen!

To fix the problem of extra digits when you reverse, change the 5 blanks to 6 blanks in the loop where it displays the RPM. (I forgot to add an extra blank for the +/- sign).

For timing, you could also just mark the disk at one point, spin it and count the time it makes to make 1 rev. You know the diameter so you can calculate how many eights of an inch it traveled in that time. Dividing out will give you distance per second.

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

@voltage @will

Ok, I have a test. I want to see how bad of a delay there is using the buttons on the shield. It will also let us know how some of the following things interact: Switch case(great if we want/need to add more buttons), screen update as a function, screen update without the interrupt changing the cursor location, digital selection of speed.

 

I do not know what version you have so if you have the 1.0 instead of the 1.1 do the comment and uncomment in the asterisks.

 

Display will only show the 50-1000 value right now so that you see that it is working properly. Small increment go up and down 1 and large up by 10. It is easy to drop in the formulas later that you both have been working on.

 

Select Button: Start and Stop

Left Button: Change direction

Right Button: How fast it increments when changing value(can be adjusted or changed to digit instead)

Up Button: Increment up based on slow or fast that is selected by right button

Down Button: Increment down based on slow or fast that is selected by right button

 

Up and down could eventually change it by the finest parameter when go is active. So diameter at first but after it starts it will adjust RPM? Or something like that. Whatever mean you want.

 

There is another method of doing this if you like the concept but it doesn't register the presses right. Or a delay is not right.

 

 

//Shield button test. Ripped off of:
//Voltage Version sketch_aug06e-Will-Mod-4
//Test of accelstepper with LCD and shield buttons

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

//Define pins
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5
int driverPUL = 12;    // PUL- pin
int driverDIR = 13;    // DIR- pin
//int spd = A1;          // Potentiometer
//int dia, old_dia = 0;  // Last pot reading
bool go = false;  //Is it running
bool dirFor = true; //Direction to go in
int smInc = 1;      //Small increase
int lgInc = 10;      //Large increase
bool slChange = true; //Slow change
int drive = 70;     //Raw Speed Number
//float sps;             // Sets per second for this diameter
//float RPM;             // RPM for this diameter 

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

//Shield buttons read (IF VERSION 1.0 SHIELD, LET ME KNOW!)
int read_LCD_buttons() {
 adc_key_in = analogRead(0);      // read the value from the sensor
 // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
 // we add approx 50 to those values and check to see if we are close
 if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
 
 
 //********************Block comment here is need changing based on version******
 // For V1.1 us this threshold
 if (adc_key_in < 50)   return btnRIGHT;
 if (adc_key_in < 250)  return btnUP;
 if (adc_key_in < 450)  return btnDOWN;
 if (adc_key_in < 650)  return btnLEFT;
 if (adc_key_in < 850)  return btnSELECT;
 //********************End Block comment*************************************

//*************Uncomment if you have the V1.0***********************************
  // For V1.0 comment the other threshold and use the one below:
/*
 if (adc_key_in < 50)   return btnRIGHT;
 if (adc_key_in < 195)  return btnUP;
 if (adc_key_in < 380)  return btnDOWN;
 if (adc_key_in < 555)  return btnLEFT;
 if (adc_key_in < 790)  return btnSELECT;
*/
//************************End of uncomment*****************************************

return btnNONE;  // when all others fail
}

void screen() {
  lcd.setCursor(5,0);                               // Update LCD
  lcd.print("      ");                              //Only a test
  lcd.setCursor(5,0);
  lcd.print(drive);
  lcd.setCursor(5,1);
  lcd.print("      ");
  lcd.setCursor(5,1);
  lcd.print( (dirFor) ? drive : -drive);
}

void setup() {  
   stepper.setMaxSpeed(1000);
   stepper.setMinPulseWidth(2.7);
   stepper.setSpeed(drive);

   lcd.begin(16, 2);
   lcd.setCursor(1,0);
   lcd.print("Dia:");
   lcd.setCursor(1,1);
   lcd.print("RPM:");
}

void loop() {
  if (go){
    stepper.runSpeed();
  } else {
    stepper.stop();
  }
  int lcd_key = read_LCD_buttons();

  switch (lcd_key)               // depending on which button was pushed, we perform an action
  {
   case btnRIGHT:
     {
     !slChange;
     break;
     }
   case btnLEFT:
     {
     !dirFor;
     break;
     }
   case btnUP:
     {
     if(slChange){
      if(drive <= (1000 - smInc)){
        drive = drive + smInc;
      }   
     } else if (drive <= (1000 - lgInc)){
        drive = drive + lgInc;
     }
     if (dirFor){
        stepper.setSpeed(drive);
     } else {
        stepper.setSpeed(!drive);
     }
     screen();
     break;
     }
   case btnDOWN:
     {
     if(slChange){
      if(drive >= (1000 + smInc)){
        drive = drive - smInc;
      }   
     } else if (drive >= (50 + lgInc)){
        drive = drive - lgInc;
     }
      if (dirFor){
        stepper.setSpeed(drive);
     } else {
        stepper.setSpeed(!drive);
     }
     screen();
     break;
     }
   case btnSELECT:
     {
     !go;
     break;
     }
     case btnNONE:
     {
     break;
     }
  }  
}

 

 

Madmisha,

 How do I know what version shield I have. I have looked at all the screen printing on the shield and it does not say anything about a version number.

 

Thanks,
Voltage


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

Some new things to work on. The project is loosely wired on the kitchen counter but I cut a circle close to 3" diameter for testing(I have to make one more accurate this one is 2-7/8"), and when I set it for that diameter is seems the stepper is twice as fast...Yikes. I forgot the 3:1 part in my test. Ok, here are the numbers anyway. In order to get the output shaft on the gearbox to move 1/8" per second, I have to set the diameter to 7.10 and that leaves an output RPM of 0.33 so we should be able to do the math from there. So if we divide that by 3 it equals 0.11 which is close to (.125 or 1/8"). I think I need to do another test. 😋 What would be a good test? Try again with a more accurate circle like 3" and we could do the math from there? This test may be tricky to accomplish.

 

edit: Maybe easier than I thought. Just mark 3/8 increments on the test wheel as that would end up divided by 3 with the sprockets...Back to the kitchen!

To fix the problem of extra digits when you reverse, change the 5 blanks to 6 blanks in the loop where it displays the RPM. (I forgot to add an extra blank for the +/- sign).

For timing, you could also just mark the disk at one point, spin it and count the time it makes to make 1 rev. You know the diameter so you can calculate how many eights of an inch it traveled in that time. Dividing out will give you distance per second.

Good morning Will. I did another test on the rpms and cut a 3" circle and made 3/8" increments and set it to Diameter 3.0 and the RPM showed 0.79. I ran it and tried to look back and forth to the clock on the laptop as I counted and it seemed to be between 10 and 11 increments in 10 seconds. I will try the 1 rev test and see what I get.

edit: 3.0 DIA, 0.79 RPM- 28 seconds for 1 rev

 

Thanks,
Voltage


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

@voltage @madmisha

If you can make a cardboard test circle of 4.76 inches, it should come out to close to 0.5 RPM. So if you mark it on the circumference, you should see the mark back at almost exactly two minutes. That will avoid having to glance back and forth all the time.

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: @will

@voltage @madmisha

If you can make a cardboard test circle of 4.76 inches, it should come out to close to 0.5 RPM. So if you mark it on the circumference, you should see the mark back at almost exactly two minutes. That will avoid having to glance back and forth all the time.

Ok, I will see if I can make one that size and test it. It's easy to glance back and forth on the one rev test. Counting the 1/8 or 3/8" increments a whole different story. Back to the kitchen.

edit: Made approximate 4.76" circle. Display said 4.74-4.76 (flickers a little at first) RPMs 0.49 and for 1 revolution it took 43 seconds and 2 revolutions took 1 min 25 seconds (85 secs).

 

Thanks,
Voltage


ReplyQuote
Page 11 / 21