ARDUINO UNO + STEPPERMOTOR +DRIVER + DISPLAY

MY PROJECT IS TO HAVE A STEPPER MOTOR CONTROL FROM ARDUINO USING MICROSTEP DRIVER AND A POTENTIOMETER TO VARIE THE SPEED WHICH IS DISPLAYED ON AN LCD DISPLAY .

The problem is that when I control the stepper motor without display the motor works perfectly but when introduce the display " the refesh rate of the display " is effecting the speed and performance of the motor.

Is there any way how to tackel this problem?

Thanks

Post a schematic. Post your code according to the forum guidelines (that you apparently did not bother to read).

Please do not shout at us.

PADDYMALTA:
Is there any way how to tackel this problem?

Not unless you are prepared to post your program.

...R

The "how to use this forum" postings are there to prevent this sort of Q&A session - post all the details, circuit, code, datasheet links etc, up front - we can't guess these details and details always matter.

Hi ALL --

This is my Code - :slight_smile:

//---------------LCD --------------------------
#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>
LiquidCrystal_PCF8574 lcd(0x27);

#define ok 8
#define up 9
#define down 10
int count = 0;
int PBdelay = 200;
int state = 0;
int stateA = 0;
int push =0;
int qty =0;
int len = 0;
int countA = 0;
int countB = 0;
int i = 0;
//------------- STEPPER ------------------

const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 13; // Analog output pin that the LED is attached to

int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)

int PUL = 7; //define Pulse pin
int DIR = 6; //define Direction pin
int ENA = 5; //define Enable Pin

void setup() {
pinMode (PUL, OUTPUT);
pinMode (DIR, OUTPUT);
pinMode (ENA, OUTPUT);

// Serial.begin(9600);
//------------LCD -------------------
lcd.begin(16, 2); // initialize the lcd
//-----------------------------------
}

void loop() {
digitalWrite(ENA, LOW); // not to let the Stepper Energised when not

//Serial.println(value_potentiometer);

// read the analog in value:
sensorValue = analogRead(analogInPin);
// Serial.println( sensorValue);

// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 500);
// Serial.println(outputValue);

// change the analog out value:
// analogWrite(analogOutPin, outputValue);

digitalWrite(DIR, LOW);
digitalWrite(ENA, HIGH);
digitalWrite(PUL, HIGH);
delayMicroseconds (outputValue);
digitalWrite(PUL, LOW);
delayMicroseconds(outputValue);

// wait 2 milliseconds before the next loop for the analog-to-digital
// converter to settle after the last reading:
delay(1);

//Serial.println(outputValue);

//--------lcd-------------------

lcd.setBacklight(255);
lcd.home(); lcd.clear();
lcd.print(outputValue);

delay(1000);
// lcd.clear();
// delay(1000);
// lcd.setCursor(1,2);
// lcd.cursor();
// delay(1000);

//------------------------------------

}

PADDYMALTA:
Hi ALL --

This is my Code

This is the culprit I'm sure:

//--------lcd-------------------

    lcd.setBacklight(255);
    lcd.home(); lcd.clear();
    lcd.print(outputValue);
  
   delay(1000); // <<<<<<<<<<<<<<<<<<<<<<
--------------------------------

You'll have to do your update delay()-lessly. Have a look at blink without delay, but intead of toggling a led, write the lcd.

IT worked . Thanks alot :slight_smile: :slight_smile:

Is that Mini in your pic of your namesake Paddy Hopkirk?

12Stepper:
Is that Mini in your pic of your namesake Paddy Hopkirk?

YES mini wwwwooooommmmmmmm ............ :slight_smile:

12Stepper:
This is the culprit I'm sure:

//--------lcd-------------------

lcd.setBacklight(255);
    lcd.home(); lcd.clear();
    lcd.print(outputValue);
 
  delay(1000); // <<<<<<<<<<<<<<<<<<<<<<




You'll have to do your update delay()-lessly. Have a look at [blink without delay](https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay), but intead of toggling a led, write the lcd.

12Stepper, Im noticing that when the display refresh there is a slightly bit of change in the motor performance.. You can listen to it changing a bit due to refresh of display.. It is not as it was with the delay function .... How could I solve it ? should I use 2 arduinos one to control the Stepper and another one for the display ?

THanks alot

This is the code ---

This is the code ---




//---------------LCD --------------------------
#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>
LiquidCrystal_PCF8574 lcd(0x27);

#define ok 8
#define up 9
#define down 10
int count = 0;
int PBdelay = 200;
int state = 0;
int stateA = 0;
int push =0;
int qty =0;
int len = 0;
int countA = 0;
int countB = 0;
int i = 0;



unsigned long previousMillis = 0;        //
const long interval = 1000;           //
int DISPLAYrefreshstate = LOW;             //


//------------- STEPPER ------------------

const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
const int analogOutPin = 13; //

int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)

int PUL = 7; //define Pulse pin
int DIR = 6; //define Direction pin
int ENA = 5; //define Enable Pin





void setup() {
  pinMode (PUL, OUTPUT);
  pinMode (DIR, OUTPUT);
  pinMode (ENA, OUTPUT);

 // Serial.begin(9600);
//------------LCD -------------------
lcd.begin(16, 2); // initialize the lcd
//-----------------------------------
}








void loop() {
  digitalWrite(ENA, LOW); // not to let the Stepper Energised when not

  //Serial.println(value_potentiometer);



  // read the analog in value:
  sensorValue = analogRead(analogInPin);
 // Serial.println( sensorValue);
 
 
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 140, 1000);
 // Serial.println(outputValue);
 
 
  // change the analog out value:
// analogWrite(analogOutPin, outputValue);












   
 
  digitalWrite(DIR, LOW);
  digitalWrite(ENA, HIGH);
  digitalWrite(PUL, HIGH);
  delayMicroseconds(outputValue);
  digitalWrite(PUL, LOW);
  delayMicroseconds(outputValue);

 
 



  // wait 2 milliseconds before the next loop for the analog-to-digital
  // converter to settle after the last reading:
  delayMicroseconds(10);

//Serial.println(outputValue);


//--------lcd-------------------

 
 
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
     previousMillis = currentMillis;


    if (DISPLAYrefreshstate == LOW) {
      DISPLAYrefreshstate = HIGH;
    } else {
      DISPLAYrefreshstate = LOW;
    }

    // set the LED with the ledState of the variable:

  lcd.setBacklight(255);
  lcd.home(); lcd.clear();
  lcd.print(outputValue);
 
 
 //  delay(1000);
 //  lcd.clear();
//    delay(1000);
  //lcd.setCursor(1,2);
 //  lcd.cursor();
 //   delay(1000);

//------------------------------------

}

}

PADDYMALTA:
This is the code ---

To make it easy for people to help you please modify your post and use the code button </>
codeButton.png

so your code 
looks like this

and is easy to copy to a text editor. See How to use the Forum

...R

Robin2:
To make it easy for people to help you please modify your post and use the code button </>
codeButton.png

so your code 

looks like this


and is easy to copy to a text editor. See [How to use the Forum](http://forum.arduino.cc/index.php?topic=149014.0) 

...R

Thanks

Thanks for fixing up the code, but by now I'm afraid I have forgotten the question.

...R