accelStepper vs Display?

Hi,

I've got a setup consisting of:

  • Arduino MEGA
  • stepper motor
  • Leadshine hybrid servo controller HSS86
  • appropriate Meanwell DC source

So far my Arduino is quite able to make the motor run by sending step and direction signals to the Leadshine motor controller.

However now I somehow got the idea that my arduino should do a bit more than just send spikes to the controller and attached two 0,96" I²C OLED displays.

However when the motor is spinning any attempt to update the display results in a short pause. The motor just stops. I suppose display activities take too long so that some spikes are missing?

Is there any way around this?

Do I have to use more than one Arduino to split the activities? One doing GUI and the other one handles the steps?

Any help would be great.

That's my main routine (and of course there are no delays in the code..)

void loop() {  
  if (millis()-tlastRefresh > tDisplayRefresh)  updateDisplays(stepper.currentPosition(), stepper.speed());
  if (stepper.distanceToGo() == 0)
      stepper.moveTo(-stepper.currentPosition());
    stepper.run();
}

Things I have tried:

  • display refresh time variations: usually set to 100ms (but generally this makes no difference - I can just vary the pauses,
  • remove the displays because the'yre powered through the arduino board - but this doesn't make a difference at all.

Best regards,
Wonko.

Ok things I've also unsuccesfully tried:

  • increase baud rate (38400)
  • update displays alternately

I think physikcally removing the display does have an effect.. unfortunately I can't really measure what's going on. Guess I will need to invest in a scope?

Hmpf.. annoying.

Best regards,
Wonko.

this is the complete code..

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <AccelStepper.h>

#define OLED_RESET 4
Adafruit_SSD1306 display1(OLED_RESET);
Adafruit_SSD1306 display2(OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
AccelStepper stepper(1, 3, 6); // pin 3 = step, pin 6 = direction

long tDisplayRefresh = 200; //in milliseconds
unsigned long tStart;
unsigned long tlastRefreshd1;
unsigned long tlastRefreshd2;

void setup()   {                
  Serial.begin(76800);

  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display1.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3D ox3C(for the 128x64)
  display2.begin(SSD1306_SWITCHCAPVCC, 0x3D);  

  // Change these to suit your stepper if you want
  stepper.setMaxSpeed(1000);
  stepper.setAcceleration(2000);
  stepper.moveTo(1000);
  tStart = millis();
  
  display1.clearDisplay();
  display2.clearDisplay();
  display1.display();
  display2.display();
  tlastRefreshd1 = millis();
  tlastRefreshd2 = millis() - tDisplayRefresh/2; // 2nd display to start half refresh time later
  // init done
  
}


void updateDisplay1(int pos){
  display1.clearDisplay();
  display1.setTextColor(WHITE);
  display1.setCursor(10,0);
  display1.println("Pos: ");
  display1.setTextSize(2);
  display1.setCursor(10,25);
  display1.println(pos);
  display1.display();
  tlastRefreshd1 = millis();
}

void updateDisplay2(int rate){
  display2.clearDisplay();
  display2.setTextSize(2);
  display2.setTextColor(WHITE);
  display2.setCursor(10,0);
  display2.println("speed: ");
  display2.setCursor(10,25);
  display2.println(rate);
  display2.display();
  tlastRefreshd2 = millis();
}


void loop() {  
  if (millis()-tlastRefreshd1 > tDisplayRefresh)  updateDisplay1(stepper.currentPosition());
  if (millis()-tlastRefreshd2 > tDisplayRefresh)  updateDisplay2(stepper.speed());
  if (stepper.distanceToGo() == 0)
      stepper.moveTo(-stepper.currentPosition());
    stepper.run();
}

Post a link to the datasheet for the Leadshine device you are using.

...R

Hmm..

I don't see anything around that. How can the Leadshine see if I've got a display attached..
Anyway - that's the best datasheet like document, I think. It's at least using western letters.. :slight_smile:

Wonko.

Wonko:
I don't see anything around that.

I don't think there is but I was confused by your use of the words "servo controller"

My guess is that your display update functions take too long.

What happens with a very short display function that just has this in it

void updateDisplay3() {
  display1.println("Pos: ");
}

...R

They claim to use servo like technology to really control the position.. This thing hasn't been terribly expensive and people used it successfully.

Problem is I plan to use a lot more on the arduino. If troubles now already start I will probably use two arduinos - one for simply taking care of ONLY creating steps and the other one for GUI and all that stuff - would make some sense?

I've tried to shorten everything already. Will just for fun test your very short version..

Ok - now the ramps sound (?) funny with the stepper motor.

I really think it's timing trouble senying anything on I2C. Don't know why.

Thanks,
Wonko.