stepper run is not smooth with display

You could consider this test. Instead of the line

myNextion.setComponentText("t0", String(pozice));

and with the Nextion device disconnected from the Arduino try

nextion.print("this is a test");

In effect this is just exercising SoftwareSerial to find out if useful data could be sent without interfering with the stepper motor.

If that works then one option is to use a separate Arduino to manage the display and just send to it the messages that need to be displayed.

...R

Hi, What are you using to control the stepper? Link to data/specs would help.

Tom.. :)

hi CNC shield by protoneer, but i also tried last Easy Stepper v4.4 https://www.sparkfun.com/products/12779 http://blog.protoneer.co.nz/arduino-cnc-shield-v3-00-assembly-guide/

I have noticed that my steppers slow down dramatically as well (I'm using accelstepper). But in my case it is due to LED strings with data (fastled). I have not noticed a slow down using 1306 old, but I only update the display when a button is pressed. I also rewrote my led calls so the led animations only get updated when something changes (1/24th of a second). That helped my steppers.

You haven't mentioned your MCU clock cycle. Are you using an uno or a higher speed clock. If not, give it a try. I like the tiny or esp12e. Both have high clock speeds.

thank you, i tried Uno, Mega, Nano, it is strange, but the situation is same on all MCU. So it looks like it is not depend on MCU speed

pfifferling: thank you, i tried Uno, Mega, Nano, it is strange, but the situation is same on all MCU. So it looks like it is not depend on MCU speed

Have you tried the diagnostic test that I suggested in Reply #20?

...R

Robin, yes right now, it is the same. does not matter what i send to serial. Now i tried it with two arduinos - one is for stepping and second for display, and it is ok :) but it is not so clean solution, i think, here must be a better way :)

pfifferling: Robin, yes right now, it is the same. does not matter what i send to serial.

Please post that program.

...R

it is the same, but without encoder reading and sending just a text. i tried it also without display, sending only to serial.

#include <SoftwareSerial.h>
#include <Nextion.h>
SoftwareSerial nextion(2, 3);
Nextion myNextion(nextion, 9600);
//#include <Encoder.h>
#include <AccelStepper.h>
#define EN 8
AccelStepper stepper(1, 4, 7);
//float pozice = 0;
//Encoder posEnc(18, 19);
//long kroky = 0;
long millisOld = 0;
//float koeficient = 1.99795;

void setup(){
Serial.begin(115200);
myNextion.init();
stepper.setMaxSpeed(1000);
stepper.setAcceleration(500);
pinMode(EN, OUTPUT);
stepper.moveTo(-3000);

}

void loop(){
//pozice = posEnc.read()/koeficient;
// kroky = stepper.currentPosition();
if (stepper.distanceToGo() == 0)
stepper.moveTo(-stepper.currentPosition());

stepper.run();
myNextion.setComponentText(“t0”, “test”);
}

Thanks. That is not the test I wanted - it is still using the Nextion library.

Try the following. I have restored (I hope) the encoder code but eliminated the Nextion code. I am just using “nextion” as SoftwareSerial because that is what you called it.

#include <SoftwareSerial.h>
//~ #include <Nextion.h>
SoftwareSerial nextion(2, 3);
//~ Nextion myNextion(nextion, 9600);
#include <Encoder.h>
#include <AccelStepper.h>
#define EN 8
AccelStepper stepper(1, 4, 7);
float pozice = 0;
Encoder posEnc(18, 19);
long kroky = 0;
long millisOld = 0;
float koeficient = 1.99795;

void setup(){ 
    Serial.begin(115200);
    nextion.begin(9600)
    //~ myNextion.init();
    stepper.setMaxSpeed(1000);
    stepper.setAcceleration(500);
    pinMode(EN, OUTPUT);
    stepper.moveTo(-3000);
}

void loop(){   
    pozice = posEnc.read()/koeficient;
    kroky = stepper.currentPosition();
    
    if (stepper.distanceToGo() == 0) {
        stepper.moveTo(-stepper.currentPosition());
    }

    stepper.run();
    //~ myNextion.setComponentText("t0", "test");
    nextion.print("this is a test");
}

…R

understand, i tried it also without nextion library. And without nextion display. with 1602 LCD and built in library. It is the same.

pfifferling: understand, i tried it also without nextion library. And without nextion display. with 1602 LCD and built in library. It is the same.

You are not being sufficiently precise for diagnostic purposes.

Do you mean that you tried the code I suggested in Reply #29 (if so, what exactly happened?) or do you mean that you wrote your own code and if so, please post it and say what exactly happened.

...R

understand, but it is same :) here is a video. In first part is without sending data to serial and motor rotate quickly and smooth. In second part it is with sending data to serial and motor is slower.

https://www.youtube.com/watch?v=9L2QgiK3jhI

pfifferling: understand, but it is same

Sorry, but from where I am you don't understand. THE SAME AS WHAT?

Just post the code that you are using at each stage of the process.

...R

same like in all cases when i will try to send anything to serial

one code is pure copy from you and second is the same but the row with serial is in comment //

pfifferling: same like in all cases when i will try to send anything to serial

If you can't do better than that I can't help you.

...R

thank you for your helping, but the problem is simple - communication through serial slowing stepper motors. Does not matter if it is to serial port, i2c, spi. I did not found any application with stepper and lcd with online data sending. Do you know any application where it is realized? the problem is general, not only for one type of display. And same probleme have everyone who tried it. If you have code, where it is working good and did you tried it, please post it. If it will be working i will send you good bottle of whiskey. Thank you very much.

As I have not seen your latest code I continue to harbour a suspicion that the problem is different. Of course that does not mean I am right.

...R