A4988 with potent. & hd44780 display

I have made a nema17 motor at 16x stepping controlling rpm from a 10 turn potentiometer. I have add a display hd44780 and everything is working perfect!! I want around 15 rpm but i want to be very stable

I am trying to display those 0-15 rpm with map fuction to display 0-15000 on display but i cannot find it
can anyone help

/*     Simple Stepper Motor Control Exaple Code
 *      
 *  by Dejan Nedelkovski, www.HowToMechatronics.com
 *  
 */
 #include <Wire.h>  // Comes with Arduino IDE
#include <LiquidCrystal_I2C.h>
 LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

 
// Defines pins numbers
const int stepPin = 3;
const int dirPin = 4; 
int a = stepPin * 4 ;
int customDelay,customDelayMapped; // Defines variables
 
void setup() {

Serial.begin(9600);  // Used to type in characters


    lcd.begin(16,2);   // initialize the lcd for 16 chars 2 lines, turn on backlight


  for(int i = 0; i< 1; i++)
  {
    lcd.backlight();
    delay(250);
    lcd.noBacklight();
    delay(250);
  }
  lcd.backlight(); // finish with backlight on   


  lcd.setCursor(4,0); //Start at character 4 on line 0
  lcd.print("PANTELIS");
  delay(2000);
    lcd.setCursor(3,1);
  lcd.print(a);
  delay(1000);
 //lcd.clear();


    
  // Sets the two pins as Outputs
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
 
  digitalWrite(dirPin,HIGH); //Enables the motor to move in a particular direction
}
void loop() {


      //lcd.setCursor(3,1);
       //lcd.write(customDelay);
  customDelayMapped = speedUp(); // Gets custom delay values from the custom speedUp function
  // Makes pules with custom delay, depending on the Potentiometer, from which the speed of the motor depends
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(customDelayMapped);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(customDelayMapped);
}
// Function for reading the Potentiometer
int speedUp() {
  int customDelay = analogRead(A0); // Reads the potentiometer
  int newCustom = map(customDelay, 0, 1023, 50,800); // Convrests the read values of the potentiometer from 0 to 1023 into desireded delay values (300 to 4000)
  return newCustom; 


}

alfadex:
I am trying to display those 0-15 rpm with map fuction to display 0-15000 on display but i cannot find it

I don't understand from that what you want to do or what you can't find.

I don't see anything in your code that tries to display any values.

I notice you are using delayMicroseconds() to control the speed of the motor. That may get in the way of updating the display. Look at the non-blocking code in the second example in this Simple Stepper Code

...R
Stepper Motor Basics
also look up the AccelStepper library

Hi and tnx for your help with this map fuction
int newCustom = map(customDelay, 0, 1023, 50,800);
i can control motor rpm from around 0-15 rpm.

I want to display on hd44780 for example

rpm hd44780

3 rpm 3000

5.7 5700

12 12500

alfadex:
I want to display on hd44780 for example

rpm hd44780

3 rpm 3000

And what part of that are you having difficulty with?

...R

sorry but i am very new in programming and i try it
i add in void loop

lcd.setCursor(3,1);
lcd.print(analogRead(A0)*15);

but speed of the motor now is very slow

edit:

i add it at void setup() and speed is normal now but speed now is not updated when i change it

lcd.setCursor(3,1);
lcd.print(analogRead(A0)*10);

i add in void loop

lcd.setCursor(3,1);
lcd.print(analogRead(A0)*15);

but speed of the motor now is very slow

The analogRead() function is not very fast. Of course it will slow down loop().

What is connected to that pin, and why does it need to be read on EVERY pass through loop()?

  for(int i = 0; i< 1; i++)

Why on earth do you have a for loop to iterate once?

You
really
need
to
get
your
tab
key
fixed.

Or use Tools + Auto Format. Your code looks like crap.

alfadex:
sorry but i am very new in programming and i try it
i add in void loop

lcd.setCursor(3,1);
lcd.print(analogRead(A0)*15);

but speed of the motor now is very slow

You need to learn how to experiment to see where the problem is. Try this in loop()

lcd.setCursor(3,1);
lcd.print("1234");

then you can see if it was the analogRead() that is the problem.

However the problem is almost certainly due to the way you are timing the stepper pulses - as I surmised in Reply #1. You need to stop using delayMicroseconds() because that just adds another delay on top of the time taken by the other code in loop().

You probably also need to ensure that the LCD is only updated maybe once or twice per second. And if there are still problems you could do the lcd.setCursor() in one iteration of loop() and the lcd.print() in a different iteration. The human eye won't notice.

Have a look at the examples I linked to in Reply #1 and also at Several Things at a Time and Planning and Implementing a Program

...R