Paint Sprayer using XY Plotter, Orion board

Greetings..

Please excuse an old man who has limited social media or forum experience.

I've spent some time going over this forum, and I'm starting this thread.. knowing full well it may be old news. If so, please be so kind as to direct me to previously posted answers so I don't waste too much of your time.

A friend has built a paint sprayer (for spraying small test plates) using a Makeblock XY Plotter and Orion controller board. He put together a simple program using Arduino 1.8.5. I'm including the entire program with this post.

Currently, this program successfully allows him to set up his plotter with a Y-axis "A", "B" or "C" height setting of his choosing, using those particular keys on his keyboard. Once he has chosen his height, he uses his numeric keyboard to move to the left with "4", right with "6", up with "8" and down with "2". This all works perfectly well in the programming example.

He asked if I could come up with a way to use "5" on the keyboard to perform a zig-zag pattern with one keystroke. I used his moveTo and move commands to perform this, but we get no result. The best we get is a quick upward movement on the Y-axis, followed by a long X-axis movement, then a 5-second delay (owing to the 'delay(5000)' command). But no zig-zag. In my attempt, I tried to pause each movement with a 5-second delay so we could watch the progress.. and be sure the plotter arrived at each location with time to spare before implementing another movement. Not working.

If I could please have a working example of a zig-zag pattern and how it might work in this program example, it would be so appreciated.

If this were a simple G-code arrangement, I wouldn't be bothering you with my questions

Thank you in advance! I've been trying to get this going since mid-November off-and-on.

#include "MeOrion.h"
#include <SoftwareSerial.h>

MeStepper stepperx(PORT_2);
MeStepper steppery(PORT_1);
MeLimitSwitch xlimit1(PORT_3,SLOT1);
MeLimitSwitch xlimit2(PORT_3,SLOT2);
MeLimitSwitch ylimit1(PORT_6,SLOT1);
MeLimitSwitch ylimit2(PORT_6,SLOT2);

void setup()
{
Serial.begin(9600);
Serial.println("Spray OS V. 1.xp");
delay(2000);
Serial.println("COM SPEED SET to 9600");
delay(500);
stepperx.setMaxSpeed(1000);
Serial.println("X AXIS INITIALIZING");
delay(500);
stepperx.setAcceleration(20000);
steppery.setMaxSpeed(500);
Serial.println("Y AXIS INITIALIZING");
delay(500);
steppery.setAcceleration(20000);
delay(500);
Serial.println("Activating Spray Control");
pinMode(8, OUTPUT);
delay(1000);
digitalWrite(8, 3);
delay(1000);
digitalWrite(8, LOW);

Serial.println("Please select from the following");
Serial.println("Enter x to reset X axis");
Serial.println("Enter y to reset Y axis");
Serial.println("Enter a for Height A");
Serial.println("Enter b for Height B");
Serial.println("Enter c for Height C");
Serial.println("Enter 4 to move left");
Serial.println("Enter 6 to move right");
Serial.println("Enter 8 for move UP");
Serial.println("Enter 2 for move DN");
Serial.println("Enter + to spray");
Serial.println("Enter - to stop spray");
Serial.println("Enter 5 for test zig-zag");

}

void loop()
{
if(Serial.available())
{
char a = Serial.read();
switch(a)
{
case 'x':
stepperx.moveTo(0);
break;
case 'y':
steppery.moveTo(0);
break;
case 'a':
steppery.moveTo(400);
break;
case 'b':
steppery.moveTo(800);
break;
case 'c':
steppery.moveTo(1200);
break;
case '4':
stepperx.moveTo(2000);
break;
case '8':
steppery.move(200);
break;
case '6':
stepperx.moveTo(0);
break;
case '2':
steppery.move(-200);
break;
case '+':
digitalWrite(8, 3);
break;
case '-':
digitalWrite(8, LOW);
break;
case '5': <-- this is where my zig-zag routing resides
stepperx.moveTo(2000);
delay(5000);
steppery.move(200);
delay(5000);
stepperx.moveTo(0);
delay(5000);
steppery.move(-200);
delay(5000);
stepperx.moveTo(2000);
delay(5000);
break;
}
}
stepperx.run();
steppery.run();
}

To make it easier for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Your code is too long for me to study quickly without copying to a text editor.

Maybe it would make sense to use an Arduino program (such as GRBL) that can interpret GCode?

...R

The delay statements:

      stepperx.moveTo(2000);
      delay(5000);
      steppery.move(200);
      delay(5000);
      stepperx.moveTo(0);
      delay(5000);
      steppery.move(-200);
      delay(5000);
      stepperx.moveTo(2000);
      delay(5000);
      break;

will prevent the following statements working until these have all completed:

  stepperx.run();
  steppery.run();

Which is clearly not what you want.

You have to use millis() instead. Look at the "blink without delay example" in the Arduino IDE.
You could also try repeating the two stepper command after each move just to see what happens.

Use code tags when posting here.