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
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.