Arduino + LCD + Stepper motor

Arduino + LCD + Stepper motor (how to avoid the LCD to slow down the stepper motor)

My Arduino hit its own limits (?)… or my programming skills are crap.

And yes. My programming skills are crap, but I also think that my ATMEGA can’t handle all the requirements that I am pushing for… but I think there is a real solution for my problem.

Either I can use it for a great LCD display or an awesome-ish step motor controller, but if I dare to use both (LCD or Serial output + stepper control) the stepper motors slows down to a ridiculous rate.

Here is a code example of my problem:

I want to run a stepper motor and output information on the (LCD or Serial) at the same time.

My Setup:

  • Arduino Duemilanove
  • LCD Keypad Shield (Pins: 8,9,4,5,6,7)
  • 1 x EasyDriver (Pins 2 & 3)
  • 1 x Stepper motor + DC power supply

Here is the code without LCD output:

#include <stdio.h>
#include <LiquidCrystal.h>
// By Staedtler
#define DIR1_PIN 2 // Direction for Motor A
#define STEP1_PIN 3 // Step for Motor A
#define DELAY 160 // Delay between pulses



void setup()
   { // Open Void Setup


pinMode(DIR1_PIN,OUTPUT); // Dir Motor A
pinMode(STEP1_PIN,OUTPUT); // Step Motor B


    } // Close Void Setup
    
    
void loop()

      { // Opens 'Void loop'
int Revolutions; // We meed 'Revolutions' to be a integer number
int Steps; // We need 'Steps' to be a integer number

 // Revolutions counter
for (Revolutions = 0; Revolutions < 100000 ; Revolutions++) // This is the Revolutions counter
    {


    for (Steps = 0; Steps < 1600 ; Steps++) // This is the Stepper counter where 1600 steps = 360 degrees for this stepper motor.
  
  
    { // Opens 'Steps' semi-loop
    
// We are about to make one step for a stepper motor here ...
digitalWrite(DIR1_PIN, LOW);
digitalWrite(STEP1_PIN, LOW);
digitalWrite(STEP1_PIN, HIGH);
    
delayMicroseconds(DELAY); // Pause in between pulses (Can be changed on '#define DELAY XXX''s line.

} // Close 'Steps'



delay(2000); // Pause for 2 seconds


} // Close 'Revolutions'


}

… here is the code with Serial output only:

#include <stdio.h>
#include <LiquidCrystal.h>

// By Staedtler

#define DIR1_PIN 2 // Direction for Motor A
#define STEP1_PIN 3 // Step for Motor A
#define DELAY 160 // Delay between pulses



void setup()
   { // Open Void Setup

Serial.begin(9600); // set up the Serial
pinMode(DIR1_PIN,OUTPUT); // Dir Motor A
pinMode(STEP1_PIN,OUTPUT); // Step Motor B
// set up the LCD //////////////////////

    delay(1000); // Wait 1 second

    } // Close Void Setup
    
    
void loop()

      { // Opens 'Void loop'
int Revolutions; // We meed 'Revolutions' to be a integer number
int Steps; // We need 'Steps' to be a integer number

 // Revolutions counter
for (Revolutions = 0; Revolutions < 100000 ; Revolutions++) // This is the Revolutions counter
    {
      

    for (Steps = 0; Steps < 1600 ; Steps++) // This is the Stepper counter where 1600 steps = 360 degrees for this stepper motor.
  
  
    { // Opens 'Steps' semi-loop
    
// We are about to make one step for a stepper motor here ...
digitalWrite(DIR1_PIN, LOW);
digitalWrite(STEP1_PIN, LOW);
digitalWrite(STEP1_PIN, HIGH);

// So now, we'll thell to the Serial and LCD that you just made a step next ...
// ... go and tell Mr. Serial that we just made one step...
Serial.println("_______________________");
Serial.println("Steps:");
Serial.println(Steps);

    
delayMicroseconds(DELAY); // Pause in between pulses (Can be changed on '#define DELAY XXX''s line.

} // Close 'Steps'


delay(2000); // Pause for 2 seconds


} // Close 'Revolutions'


} // Close 'Void loop'

And here is the code with LCD output:

#include <stdio.h>
#include <LiquidCrystal.h> 

// By Staedtler

LiquidCrystal lcd(8,9,4,5,6,7); // setup for 'LCD Keypad Shield', if you have a regular LCD display change to 'LiquidCrystal lcd(12, 11, 5, 4, 3, 2);'
#define DIR1_PIN 2 // Direction for Motor A
#define STEP1_PIN 3 // Step for Motor A
#define DELAY 160 // Delay between pulses



void setup() 
   { // Open Void Setup


pinMode(DIR1_PIN,OUTPUT); // Dir Motor A
pinMode(STEP1_PIN,OUTPUT); // Step Motor B
// set up the LCD //////////////////////
lcd.begin(2, 16); // Set the size of the LCD
lcd.clear(); // Clear the screen
lcd.setCursor(0,0); // Set cursor for next line
lcd.print("StepperCalc-----"); // Print this line
lcd.setCursor(0,1); // Set cursor for next line 
lcd.print("----------------"); // Print this line
    delay(3000); // Wait 3 seconds

    } // Close Void Setup
    
    
void loop()

      { // Opens 'Void loop' 
int Revolutions; // We meed 'Revolutions' to be a integer number
int Steps; // We need 'Steps' to be a integer number
 
 // Revolutions counter
for (Revolutions = 0; Revolutions < 100000 ; Revolutions++) // This is the Revolutions counter
    { 
      

lcd.clear();
  lcd.setCursor(0,0); lcd.print("Steps:");
  lcd.setCursor(6,0); lcd.print(Steps);
  lcd.setCursor(0,1); lcd.print("Revolutions:");
  lcd.setCursor(12,1); lcd.print(Revolutions);      
      


    for (Steps = 0; Steps < 1600 ; Steps++) // This is the Stepper counter where 1600 steps = 360 degrees for this stepper motor.
   
   
    { // Opens 'Steps' semi-loop
    
// We are about to make one step for a stepper motor here ...
digitalWrite(DIR1_PIN, LOW); 
digitalWrite(STEP1_PIN, LOW); 
digitalWrite(STEP1_PIN, HIGH); 

// ... and tell Mr LCD that we just made a step here ...
lcd.clear();
  lcd.setCursor(0,0); lcd.print("Steps:");
  lcd.setCursor(6,0); lcd.print(Steps);
  lcd.setCursor(0,1); lcd.print("Revolutions:");
  lcd.setCursor(12,1); lcd.print(Revolutions);
    
delayMicroseconds(DELAY); // Pause in between pulses (Can be changed on '#define DELAY XXX''s line.

} // Close 'Steps' 


lcd.clear();
  lcd.setCursor(0,0); lcd.print("Steps:");
  lcd.setCursor(6,0); lcd.print(Steps);
  lcd.setCursor(0,1); lcd.print("Revolutions:");
  lcd.setCursor(12,1); lcd.print(Revolutions+1); 




delay(2000); // Pause for 2 seconds


} // Close 'Revolutions' 


} // Close 'Void loop'

You can actually comment out either the Serial output or LCD, but the result will make no significant effect until both are eliminated.

Now, that’s my dilemma. Every time that I try to run the code with the LCD, the stepper motor slows down.
Note that I am talking about the 360 degree process, after that there is an intended 2 seconds pause.
My beef is with the 360 degrees process with vs without LCD.

There is a technique to avoid slowing down the cycle?

My goal is simply to show the information of the stepper motor on the LCD without slowing down everything on the process.

My guts tells me that using different cycles is the key, but I am not that good.
I know there is a solution… I don’t know how.

:’( :’( :’( :’( :’(

[edit]To add a picture :slight_smile: [/edit]

The solution is to use interrupts to drive your motor, this will then slow down the LCD function but you won't notice that.

Can you give me an example?

Here's my thought from looking at you code - looks like you have 3 things that you want to do every 160uS?

Why not write your loop to do the 3 actions within a bigger loop that cycles every 160uS?

See the Blink Without Delay sketch in the playground, and put your three things where the LED on/off is. You've then got 160uS/(1/16,000,000) clock cycles to do stuff - about 2560 clock cycles. Every time you reach interval, the three things are allowed to go one time, then back to waiting for the next interval.

That may oversimplify, but it gives an idea of a different way to approach it.

Thank you CrossRoads.

That’s interesting, but it won’t work (I try and doesn’t work for this code), because basically what I am trying to do is output the information of the loop state, on this case the “Steps” value to a Serial output or LCD on the best scenario.

I also try this with the attempt to avoid using every cycle, and picking a couple of cycles like this:

#include <stdio.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,4,5,6,7); // setup for 'LCD Keypad Shield', if you have a regular LCD display change to 'LiquidCrystal lcd(12, 11, 5, 4, 3, 2);'
#define DIR1_PIN 2 
#define STEP1_PIN 3 
#define DELAY 160 // Delay between pulses

void setup()
   { 
pinMode(DIR1_PIN,OUTPUT); 
pinMode(STEP1_PIN,OUTPUT); 

lcd.begin(2, 16); 
lcd.clear(); 
lcd.setCursor(0,0); 
lcd.print("StepperCalc-----"); 
lcd.setCursor(0,1); 
lcd.print("----------------"); 
    delay(3000); 

    } 
    
 
   
void loop()

      { 
int Revolutions; 
int Steps; 


for (Revolutions = 0; Revolutions < 100000 ; Revolutions++) 
    {
      

    for (Steps = 0; Steps < 1600 ; Steps++) // This is the Stepper counter where 1600 steps = 360 degrees for this stepper motor.
  
  
    { 
    
        if (Steps == 1);
       { 
          digitalWrite(DIR1_PIN, LOW);
          digitalWrite(STEP1_PIN, LOW);
          digitalWrite(STEP1_PIN, HIGH);
       }
       
        
        if (Steps==800); 
      {
          lcd.clear();
          lcd.setCursor(0,0); lcd.print("Steps:");
          lcd.setCursor(6,0); lcd.print(Steps);
          lcd.setCursor(0,1); lcd.print("Revolutions:");
          lcd.setCursor(12,1); lcd.print(Revolutions);
    }


    
delayMicroseconds(DELAY); // Pause in between pulses (Can be changed on '#define DELAY XXX''s line.

} // Close 'Steps'


} // Close 'Revolutions'


} // Close 'Void loop'

… but it didn’t work and I have always the same result.
Only when you comment out the LCD output is when the cycle for the stepper motor is clean and works faster.

I was reading about Interrupts on Grumpy_Mike’s suggestion, but the whole thing is way over my capabilities to follow the whole story.
I have to agree that seems to be the solution, but I can’t get it yet.

If someone can solve this problem for this part of the code with ‘Interrupts’ I could go forward on this direction, otherwise I will choose the lame direction that I am going.

I think that a lot of Stepper motors projects will appreciate the right way to make this code.

Note for Googlers: Don’t let this thread die. If you find a solution post it anytime on the future.
I will, if I find it at the end.

Here we have developed and posted a similar application. I am not a good programmer, but perhaps you can find some hints how Sven has done it:

http://www.david-laserscanner.com/forum/viewtopic.php?f=6&t=2421

Here are my thoughts *withou*t looking at your code!

The problem is that the (ancient) LCD controller is a very slow device. This means that before any information (commands or data) is sent to the LCD one must make certain that it has finished dealing the previous information. The easiest way to do this is with a time delay and one way to to do this is with a software time delay. This is the way that the LiquidCrystal() library works. During a software time delay the processor can do nothing else (unless interrupted) so that's why your stepper motors slow down.

If you don't want to attempt Mike's interrupt solution then you could look into changing LCD libraries. I believe that the LiquidCrystal440() library has provisions to use the busy flag rather than software time delays. This will mean using another Arduino output pin for the R/W line on the LCD but it may solve, or at least reduce, your problem. Don't be confused by the ability to connect the R/W line with the regular LiquidCrystal() library, even when connected it isn't implemented.

Don

Floresta, I like the idea of changing libraries, and I actually try the LCD4BIT library too, but here is the big question... Why I have the same problem with Serial too?... Serial is the most basic library, and I have the same results.

So, changing LCD's libraries shouldn't change that much since the problem is the whole approach.

I'm preparing myself for the Interrupt headache.

WalterM, I am looking at the code right now. Awesome project. I'll check and analyze what could be helpful out of your code's project. Thank you!

WalterM,
I had much better results!

I’ve commented out the LCD output and there is a small difference on favor of NO-LCD, but the difference is almost nothing.
This is definitely the best reference so far.

I’ll give you some feedback later to show you on video how the LCD slightly affects the motors from your code when I go from ‘>>>>>>>>>>’ command to ‘P’ (Home?), command.
I want to know if you have the same results. If not, the problem might be my LCD display doing some extra damage.

But so far this code is not slowing down my stepper like my code does! … excellent news!

Like I said, I want to make a video showing you the pulses that I got on your code with LCD and the difference without LCD (same code, just commenting out the LCD output).
You need a smooth 3D scanning and if you are getting what I got, that might not be good for the scanning, but again I suspect that is my LCD the troublemaker after all.

Thanks again WalterM, I’m going on that direction.

I like the idea of changing libraries, and I actually try the LCD4BIT library too, but here is the big question… Why I have the same problem with Serial too?.. Serial is the most basic library, and I have the same results.

Stay away from the LCD4BIT library. To which ‘Serial’ library are you refering? Did you try the LiquidCrystal440 library using R/W?

Regardless of which library you use the ‘Clear Display’ instruction used by the lcd.clear() function is one of the most time consuming LCD operations and you are using it a lot. Also, the “Steps:” and “Revolutions:” titles never change yet you are rewriting them over and over again. You should consider restructuring your code to clear the display and write those two titles once, in setup(). Within your loop you should position the cursor to (6, 0) or (12, 1) as you did before, write a few spaces to clear the old information, reposition the cursor and write your data (Steps) or (Revolutions+1).

Don

Don, When I say Serial library I'm just making reference to 'Serial.println', sorry for the confusion. That supposed to be a light instruction, but I might be wrong too.

I've made the changes that you just suggested an its working faster, but not fast as Sven's code with the 'showState()' solution. That might not be the perfect solution like working with 'interrupts', but I have more information on Sven's code than I have on 'interrupts' at this point.

Thanks for the head´s up again with LiquidCrystal440's library. Regardless the final solution that is the sweetest library so far, and I am definitely adopting LiquidCrystal440 from now on. Well documented and probably the best. That should be part of the default Arduino package in the future.

I wish I had more information on 'interrupts' because looks to be the optimal solution working with different clocks, but I am happy with the solutions on the thread so far, and learning a lot from new code.

Thank you guys.

I suggest you not update the LCD so often as you are doing. Just do it twice a second your eyes can't follow faster updates anyway (at your rates the liquid crystals will not follow, they're sticky liquids like soap water, you know?)

Just a huntch, your display is pretty sluggish. I bought one from a....t and that was my worst display. Get one from ebay if yours is sluggish.

You should follow floresta's suggestion and only update what's changing.

You realized your programming is crap, I have to agree. What the heck is revolution doing with 100000? You know how large an integer variable holds?

Liudr,

Thanks for your notes. Floresta’s suggestion where very helpful for my learning curve on LCD’s. Although I made all the changes (and thank you for point it out), nothing worked better than Sven’s code, and that’s where I am working right now.

Just to document the changes, I’ve made a short video for this thread, (sorry, no audio)… but it’s enough to document the problem on my code with all the changes vs no LCD output at all…

This is the code used for this video:

#include <LiquidCrystal440.h> // You can use <LiquidCrystal.h> for debugging propuses. I highly recommend <LiquidCrystal440.h>, check it out! 
LiquidCrystal lcd(8,9,4,5,6,7); // setup for 'LCD Keypad Shield', if you have a regular LCD display change to 'LiquidCrystal lcd(12, 11, 5, 4, 3, 2);'
#define DIR1_PIN 2
#define STEP1_PIN 3
#define DELAY 160 // Delay between pulses

void setup()
   {
pinMode(DIR1_PIN,OUTPUT);
pinMode(STEP1_PIN,OUTPUT);

lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("StepperCalc-----");
lcd.setCursor(0,1);
lcd.print("----------------");
    delay(3000);
    lcd.clear();

    }
      
void loop()

      {
int Revolutions;
int Steps;


        for (Revolutions = 0; Revolutions < 100000 ; Revolutions++)
            {
            
                for (Steps = 0; Steps < 1600 ; Steps++) // This is the Stepper counter where 1600 steps = 360 degrees for this stepper motor.
    
                {
                  // Making one step here    
                  digitalWrite(DIR1_PIN, LOW);
                  digitalWrite(STEP1_PIN, LOW);
                  digitalWrite(STEP1_PIN, HIGH);
                  
/// Comment out this section to see the difference between LCD vs no-LCD /// From here
                   // Printing Steps on LCD here
                   lcd.setCursor(6,0); lcd.print(Steps);
                   lcd.setCursor(12,1); lcd.print(Revolutions);
/// Comment out this section to see the difference between LCD vs no-LCD /// To here


                   delayMicroseconds(DELAY); // Pause in between pulses (Can be changed on '#define DELAY XXX''s line.   

                  } // Close 'Steps'

              lcd.clear();
              } // Close 'Revolutions'

     } // Close 'Void loop'

The difference is huge, but Sven’s code doesn’t seems to affect that much the maximum speed of the motor displaying every step on the LCD. I don’t have a video with Sven’s code, but I had 1/2 second per revolution.

So, that is the way to go I guess.

You realized your programming is crap, I have to agree. What the heck is revolution doing with 100000? You know how large an integer variable holds?

Thank you for remind me that. I promise that I am learning, that is the point of this thread.
100,000 revolutions is not a random parameter, it’s actually close to the maximum parameter that I need for this application.

This project is an open source CNC coil winder. This part of the code is where I am having problems.
I was able to work flawless on this project until I added the LCD to the equation.
The whole code includes an algorithm for 3 steppers motors working at different speeds. The first motor is the one holding the coil, the second motor and third motor are wiring the coil.
For every revolution of the main stepper motor, the stepper motors moving the wires moves only 0.0159" (for AWG 26 magnet wire, just as example).

At the rate of 10 seconds per revolution its 4 hours running (crazy!). That is exactly my problem with the LCD slowing down the process.

With no LCD output, 100,000 revolutions at 1/3 Seconds per revolution the whole process will take only 9 minutes.

With Sven’s code I was close to half second per revolution. Not fast like the ideal 1/3 second, but fast enough to solve all the problems.

Visualizing the steps on the LCD is not a candy eye for this application. At some point the the speed it’s slower, so I need this feature all the time because is all part of the application. I don’t want to compromise this feature, and I don’t care if you are not able to see the numbers… is not the point. Visual feedback is really important. If I was able to have good results with Sven’s code, I don’t see why I shouldn’t try that option, so that’s what I am doing right now… understanding his code and implementing specifically the parts that will solve my problem.

I am also keep looking at interrupts, but I am not able to make any advance there.

Staedtler,

Your programming is no longer crap any more. I could easily understand what you're trying to do! Congrats!

On the other hand, you got to take my suggestion and only update LCD every second or so. You're updating LCD every 160 micro seconds. Those updates you can't read faster than one update per second.

Do this instead:

if (Steps%320==0)
{
  lcd.setCursor(6,0);lcd.print(Steps);
  if (Steps%1600==0)
  {
    lcd.setCursor(12,1); lcd.print(Revolutions);
  }
}

Plus your Revolution is defined as an integer, look for how large of a number an integer can hold. Your Revolution loop will never end.

Oh, since you're shooting for 3RPM (let's not use 1/3 second per revolution, it's backwards), you should stop displaying steps so often or even not display it at all.

Liudr,
You nail it!

I changed the formula to reflect percentages and works flawless!

if (Steps%16==0) // This reflects 1% for each true statement
{

  lcd.setCursor(13,0);lcd.print(Steps/16); // Add and print +1% each true statemnet
  if (Steps%1600==0)
  { 
    lcd.setCursor(13,0);lcd.print("   "); // Just to clear the mess after the 100%
    lcd.setCursor(13,1); lcd.print(Revolutions);
  }
}

The stepper motor is not affected!, so this is the simple way to go!

Here is the final solution for this thread (Well… nothing is final, but is the best so far):

#include <LiquidCrystal.h>


LiquidCrystal lcd(8,9,4,5,6,7); // setup for 'LCD Keypad Shield', if you have a regular LCD display change to 'LiquidCrystal lcd(12, 11, 5, 4, 3, 2);'
#define DIR1_PIN 2 // Direction for Motor A
#define STEP1_PIN 3 // Step for Motor A
#define DELAY 2500 // Delay between pulses 160 is the Maximum speed



void setup()
   { // Open Void Setup


pinMode(DIR1_PIN,OUTPUT); // Dir Motor A
pinMode(STEP1_PIN,OUTPUT); // Step Motor B
// set up the LCD //////////////////////
lcd.begin(2, 16); // Set the size of the LCD
lcd.clear(); // Clear the screen
lcd.setCursor(0,0); // Set cursor for next line
lcd.print("StepperCalc-----"); // Print this line
lcd.setCursor(0,1); // Set cursor for next line
lcd.print("----------------"); // Print this line
    delay(3000); // Wait 3 seconds
lcd.clear();
  lcd.setCursor(0,0); lcd.print("Revolution :%");
  lcd.setCursor(0,1); lcd.print("Revolutions:@");

    } // Close Void Setup
    
    
void loop()

      { // Opens 'Void loop'
int Revolutions; // We meed 'Revolutions' to be a integer number
int Steps; // We need 'Steps' to be a integer number
int Percent;

 // Revolutions counter
for (Revolutions = 0; Revolutions < 100000 ; Revolutions++) // This is the Revolutions counter
    {
      



//  lcd.setCursor(13,0); lcd.print(Steps);
//  lcd.setCursor(13,1); lcd.print(Revolutions);      
      


    for (Steps = 0; Steps < 1600 ; Steps++) // This is the Stepper counter where 1600 steps = 360 degrees for this stepper motor.
  
  
    { // Opens 'Steps' semi-loop
    
// We are about to make one step for a stepper motor here ...
digitalWrite(DIR1_PIN, LOW);
digitalWrite(STEP1_PIN, LOW);
digitalWrite(STEP1_PIN, HIGH);

// ... and tell Mr LCD that we just made a step here ...


if (Steps%16==0)
{

  lcd.setCursor(13,0);lcd.print(Steps/16);
  if (Steps%1600==0)
  { 
    lcd.setCursor(13,0);lcd.print("   ");
    lcd.setCursor(13,1); lcd.print(Revolutions);
  }
} 

    
delayMicroseconds(DELAY); // Pause in between pulses (Can be changed on '#define DELAY XXX''s line.

} // Close 'Steps'



  lcd.setCursor(13,0); lcd.print(Steps);
  lcd.setCursor(13,1); lcd.print(Revolutions+1);






} // Close 'Revolutions'


} // Close 'Void loop'

Note: I’ve reduced the speed set on the videos from 160 to 2500, just to appreciate the effect.
Change to “#define DELAY 160” to achieve the maximum speed.
Since this code will change speeds, was really important to see the estate of the motor in real time on low speeds.

Problem solved!

Thank you!

Edit: This inspired me to generate a progress bar with custom characters.
I’ll post the code as soon I get it right.

Great! I was glad you got back to us and posted new code. Now, if you want your motor to ever stop after the 100000 revolutions, do the following change: long Revolutions; //In place of int Revolutions; Integers can't hold 100000. They max out at 32767.

I didn’t know that, thank you for the tip.
Although the actually big code doesn’t work like that.
I was trying to replicate the problem without the extra junk of code. Is actually an array of 3 ‘for’ loops.

So, to be sure…

if my code goes something like:

for (A = 0; A < 1000; A++)
{
       ...
       ...
       
       for (B = 0; B < 1000; B++)
        {
             ...
             ...
             for (C = 0; C < 1000; C++)
              {
               ...
               ...
                }
           }
 }

… That is the equivalent to 1,000,000,000 loops.

… I am safe setting for ‘int’ or should I go with ‘long’ anyway?

OK, this is the final code for this thread.

Now, with the progress bar like I promised.

Feel free to simplify and make it better.

Cheers!

/* *******************************************************************************************************************************************************************
|      Stepper motor calculator by Staedtler and Arduino community.
|      The main use for this code is to precisely calculate how many steps takes for the stepper motor to complete 360 degrees (1 revolution).
|      In order to do this, make sure that the motor will stop on the same spot every revolution (360 degrees).
|      In a long period of time this will be obvious.
|      This is a tool for a longer project, but I think this code could be used to learn more about stepper motors and LCDs.
|
|      People who contributed to the code from the Arduino community: Grumpy_Mike, CrossRoads, WalterM, floresta & Liudr (who actually solved the problem).         
|      http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1290545711
\ ********************************************************************************************************************************************************************/

#include <LiquidCrystal.h> 
LiquidCrystal lcd(8,9,4,5,6,7); // setup for 'LCD Keypad Shield', if you have a regular LCD display change to 'LiquidCrystal lcd(12, 11, 5, 4, 3, 2);'

#define DIR1_PIN 2 // Direction for Motor A
#define STEP1_PIN 3 // Step for Motor A
#define DELAY 160 // Delay between pulses. (160 is the Maximum speed for this stepper motor).
#define MOTOR 1600 // This is the amount of steps for this particular motor to make 360 degrees. Change this parameter to suit your motor.


void setup()
   { // Open Void Setup


pinMode(DIR1_PIN,OUTPUT); // Dir Motor A
pinMode(STEP1_PIN,OUTPUT); // Step Motor B
// set up the LCD //////////////////////
lcd.begin(2, 16); // Set the size of the LCD
lcd.clear(); // Clear the screen
lcd.setCursor(0,0); // Set cursor for next line
lcd.print("StepperCalc witht"); // Print this line
lcd.setCursor(0,1); // Set cursor for next line
lcd.print("Progress Bar____"); // Print this line
    delay(3000); // Wait 3 seconds
lcd.clear();
  lcd.setCursor(0,0); lcd.print("[          ]%");
  lcd.setCursor(0,1); lcd.print("Revolutions:@");

    } // Close Void Setup
    
    
void loop()

      { // Opens 'Void loop'
int Revolutions; // We meed 'Revolutions' to be a integer number
int Steps; // We need 'Steps' to be a integer number
//int Percent;
int Bar;
int BarChar;
  
      //======define charset      
      uint8_t E_[8] = {0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e};
      lcd.createChar(4, E_);
      lcd.home();
         //======define charset



 // Revolutions counter
for (Revolutions = 0; Revolutions < 100000 ; Revolutions++) // This is the Revolutions counter
    {
        
      

    for (Steps = 0; Steps < MOTOR ; Steps++) // This is the Stepper counter where 1600 steps = 360 degrees for this stepper motor.
  
  
    { // Opens 'Steps' semi-loop
    
// We are about to make one step for a stepper motor here ...
digitalWrite(DIR1_PIN, LOW);
digitalWrite(STEP1_PIN, LOW);
digitalWrite(STEP1_PIN, HIGH);


// Start printing a progress bar here... ///////////////////////////////////////////////////////////////////////////////////////////
if (Steps%(MOTOR/100)==0)  // This is 1% each true statement.
{
    Bar = (Steps /(MOTOR/100));  // This set 1% to the int 'Bar'
    lcd.setCursor(13,0);lcd.print(Bar+1); // This prints every 1% of revolution.
}
if (Steps%(MOTOR/10)==0) // This is 10% each true statement
{
  
  if (BarChar>9)
  {BarChar = 0;
  lcd.setCursor(0,0);lcd.print("[          ]"); /// We are clearing the bar after a full cycle (100%)
  }  
  BarChar++;  
  lcd.setCursor(BarChar,0);lcd.write(4); // We are printing every 10% one character bar.

  if (Steps%MOTOR==0) // After a full 360 degrees of the stepper, we just made a revolution.
  {     
    lcd.setCursor(13,1); lcd.print(Revolutions); // , so we print another revolution here.
  }
} 
// Finished printing a progress bar here... ///////////////////////////////////////////////////////////////////////////////////////////  


    
delayMicroseconds(DELAY); // Pause in between pulses (Can be changed on '#define DELAY XXX''s line.

} // Close 'Steps'



  
lcd.setCursor(13,1); lcd.print(Revolutions+1);

// delay(5000); // (Pause for 5 seconds), Enable this option to check where the motor stops every 360 degrees.

lcd.setCursor(13,0);lcd.print("   ");

} // Close 'Revolutions'


} // Close 'Void loop'

Well, you should read up on data types and their limitations. The number requires a long integer, which overflows at around 2E9, a regular integer stores up to 32767.