Stepper motor - skipping steps

Hello, I am building laser harp by tutorial on instructables. I copied their code and edited it for working with Easy Driver and hairless MIDI. It is almost working, but my stepper skips every second step, so beam pattern looks like on picture (there is supposed to be 8 beams but one is skipped every rotation).
I can’t see any problem with code but maybe I am wrong. Can you please help me what to do with it? → My code

I also tried another code with for command, but it was unexpectedly rotating around. With that long code above is my laser more light, so I prefer that more than shorted.

Reply, and Attach your code (Attach button below the reply box). We can't all get to pastebin.com

Owh, sorry, there it is.
Btw. that long delay is only for testing steps

LaserHarp8Beams.ino (9.12 KB)

Why not simplify the code so the same code does all the steps - it would make debugging much easier. Also, if you have a line

stepSize = - stepSize;

you can get the reverse direction with the same code.

How are you detecting the missing dot ?

…R

I set slow speed so I can see dots on paper.
I have tried simpler code what I found in comments and edited it too but it does one turn more steps than other side so it is rotating around even through ‘for’ command has same repeating variable and laser is so dimmed, almost invisible. That first code is working better now.
You can see that second code attached.

LaserHarp13BeamsED.ino (3.4 KB)

What happens if you simplify the code in loop() even further - like this

void loop() {

  for (pos = 1; pos < beams; pos++) { // turn in first direction
    beamsplitter.step(stepsize); // switch position
    //delayMicroseconds(delaymotor);
    digitalWrite(LaserPin, HIGH); // turn on laser
    delayMicroseconds(delaylaser / 2);

    if ( (analogRead(0) > sensor ))\ // If the sensor gets a signalx
    {
      digitalWrite(6, HIGH); // Switch on status led.
      noteOn(); // Play note 3
    }

    else if (analogRead(0) < sensor ) // If the sensor does not get a signal:
    {
      digitalWrite(6, LOW); // Switch off the status led.
      noteOff(); // Stop playing note 2.
    }

    delayMicroseconds(delaylaser / 2);
    digitalWrite(LaserPin, LOW); // Turn off the Laser.
  }

  stepSize = - stepSize;

}

It should at least give the same number of steps in each direction since there is only one block of code.

You will have to explain how the laser brightness is supposed to work before I can comment on why it might be dim.

…R

The skips on accelerating suggest you are accelerating too fast and causing loss of lock.

The AccelStepper library lets you set a maximum acceleration which will allow you to avoid over-loading the motor on speed changes.

Also I note you are not using microstepping, so you are at maximum risk of resonant mis-stepping. x8 or x16 microstepping is where I would start for reasonable performance.

I don't know what causes that low brightness. Btw. I forgot to say that in void setup() is it bright but in loop() is it dimmed or if I change laser delay is it sometimes turned off. I got idea now, that can be caused by fast blinking, but it works in setup, so I don't know.

I will try that code later, thanks for it.

LaXi0rCZ:
I don’t know what causes that low brightness. Btw. I forgot to say that in void setup() is it bright but in loop() is it dimmed

There is a comment at the top of the program about beam brightness - did you write that ?

I suspect it is brighter in setup() because it is never turned off.

In loop() it seems to be turned off before the motor moves to the next beam position. I presume that is necessary. I wonder what would happen if you leave it on all the time ?

…R

MarkT: It is skipping with 1s delay between steps too, so I think that fast accelerating is not problem, but maybe I am wrong. Btw. I tried microstepping but it was slower

Robin2: As I said I copied it and edited for my setup, that comment was there. Of course I tried changing that value, but it was still dimmed. I think that is supposed to work by delay how long it is on. And if I leave it on, it makes straight line instead of beams. In setup() it doesn't matter so, because it is slower there. When it goes faster, there is that line.

Sorry for that I didn't write all important things

EDIT: I arrived home now, tried your code and it is still going around but on the other side.

LaXi0rCZ:
And if I leave it on, it makes straight line instead of beams.

I don’t know how it is supposed to work so I don’t know if that matters.

My suspicion is that all that matters is where the steppr motor has positioned the beam when the line

if ( (analogRead(0) > sensor ))

is executed.

Incidentally I notice that you read the sensor twice

   if ( (analogRead(0) > sensor ))\ // If the sensor gets a signalx
    {
      digitalWrite(6, HIGH); // Switch on status led.
      noteOn(); // Play note 3
    }

    else if (analogRead(0) < sensor ) // If the sensor does not get a signal:
    {
      digitalWrite(6, LOW); // Switch off the status led.
      noteOff(); // Stop playing note 2.
    }

It would probably be better for the second one just to be

   else  // If the sensor does not get a signal:

so that both the IF and the ELSE are based on the same reading.

…R

Yes, you understand it right.

Okay, I deleted that one line.

Can you devise some way to damp down mechnical resonance? Microstepping is clearly one way, but physical damping is another.

I had solved it by physical damping. Now I tried that microstepping again, it's slow but I noticed that it's not skipping steps, but when turning on middle beam it makes little more noise and only that middle beam is more blurred. |500x41 Why? Btw. any tips for speeding it up and keep laser bright?

EDIT: I got idea now. Laser will be turned on and I will have 13 very small mirrors in 45 degrees in front of that motor, and that mirrors will make beams, like on picture. With this the motor can be running very fast and laser will be at max brightness. I only don't know how good will work the light sensor, if I put very small delay to steps. What do you think about it? |500x335