Home | Links | Contact |

Printed from www.nzmeccano.com

Top Home Bottom

Section 8 of XY Plotter Instructions

(Author: Peter Harwood)

The Arduino Sketch

 The complete X-Y Plotter Instructions are in the User Gallery in Peter Harwood 2.  These instructions are in the form of a pdf file. The Arduino sketch in the instructions becomes corrupted in the conversion process from a PDF to a text file, so here is the complete sketch as text.

Don't be put off by the size of it.  The whole thing is in sections that are described in the instructions!

8. The Arduino Sketch

/*[200217a_with_MECCANO]
X-Y Plotter Sketch by Peter Harwood 11/03/2020
Drives two stepper motors in precision
mode to plot an ellipse and 'MECCANO'.
Runs at two speeds selected by Digitalpin(12):
0v 100 points/sec
5v 30 points/sec
A point is ~.25mm
*/
int S1count = 0; //Accumulated posn of Stepper 1
int S1posn = 0; //Incremental posn, one of eight w. Phase 1= posn 0
int S2count = 0; //Accumulated posn of Stepper 2
int S2posn = 0; //Incremental posn, one of eight w. Phase 1= posn 0
float currentX = 0;
float startX = 0;
float startY = 0;
int targetX = 0;
int targetY = 0;
float currentY = 0;

//Array giving start point of each stage
//Stage 0(line) 1(line) 2(ellipse) M E C C A N O 9(line) 10(line) 11(line)
float Xarray[13] = ;
float Yarray[13] = ;

int MXarray[32] = ;
int MYarray[32] = ;
int EXarray[39] = ;
int EYarray[39] = ;
int CXarray[51] = ;
int CYarray[51] = ;
int AXarray[37] = ;
int AYarray[37] = ;
int NXarray[33] = ;
int NYarray[33] = ;
int OXarray[52] = ;
int OYarray[52] = ;

float G = 0; //Gradient of line from (startX,startY) to targetX,targetY)
float Angle = 195; // Angle in ellipse, this is the start value
float k = 2 * 3.14 / 360; //Converts angle from degrees to radians
int Stage = 0; // The plot occurs in 12 stages
int Lstage = 0; // Stage 2, the ellipse, is a series of vectors using Lstage
float deltaY = 0;
int Xstep = 0;
int Ystep = 0;

void setup()

void loop()
}
}

if (Stage == 1) //Stage 1 goes to(36,211)

}
}

if (Stage == 2) // goes from and to (36,211)
//Calculate x and y for Angle 0-360 in degree steps

}
}

if (Stage == 3) //M. Stage 3 from(36,211) to (257,211))

}
//End of overall Stage
if (Lstage == 32)

}

if (Stage == 4) //E. Stage 4 from(257,211) to (364,208)

}
//End of overall Stage
if (Lstage == 40)

}

if (Stage == 5) //C. Stage 5 from (364,208) to (435,208)

}
//End of overall Stage
if (Lstage == 51)

}

if (Stage == 6) //C. Stage 6 from (435,208) to (465,211)

}
//End of overall Stage
if (Lstage == 52)

}

if (Stage == 7) //A. Stage 7 from (423,211) to (419,211)

}
//End of overall Stage
if (Lstage == 37)

}

if (Stage == 8) //N. Stage 8 from (554,211) to (664,208)

}
//End of overall Stage
if (Lstage == 35)

}

if (Stage == 9) //)O. Stage 9 from (664,208) to (664,208)

}
//End of overall Stage
if (Lstage == 52)

}

if (Stage == 10) //Stage 10 from (664,208) to(750,208)

}
}

if (Stage == 11) //Stage 11 from(750,208) to(750,0)

}
}

if (Stage == 12) //Stage 12 from(750,0) to(0,0)

}
}
currentX = (S2count - S1count) / 2;
currentY = (S1count + S2count) / 2;

Xstep = 0; // Sets initial condition
Ystep = 0;

//Determine path to take to next point. The start, current and
// target X and Y points are known when each point is calculated.
// This procedure works out the straight line between the start
//and target points and decides which X and Y steps to take to
// stay on the line.

// Compute distance deltaY in Y direction from current posn. to Start-Target line. (G is float)

if ((targetX - startX) != 0) //Slope not vertical

}

if ((targetX - startX) == 0) //Slope vertical

/*
Serial.print(Stage);
Serial.print(" deltaY = ");
Serial.print(deltaY);
Serial.print(" Xstep = ");
Serial.print(Xstep);
Serial.print(" Ystep = ");
Serial.print(Ystep);
Serial.print(" currentX = ");
Serial.print(currentX);
Serial.print(" currentY = ");
Serial.print(currentY);
Serial.print(" G = ");
Serial.print(G);
Serial.print(" startX = ");
Serial.print(startX);
Serial.print(" startY = ");
Serial.print(startY);
Serial.print(" targetX = ");
Serial.print(targetX);
Serial.print(" targetY = ");
Serial.print(targetY);
Serial.print(" Angle = ");
Serial.println(Angle);
*/

//Update count
S1count = S1count - Xstep + Ystep;
S2count = S2count + Xstep + Ystep;

//Establish updated posn from eight
S1posn = S1count % 8; // Gives 0 to 7 and -7 to 0
if (S1posn < 0) S1posn = 8 + S1posn;
S2posn = S2count % 8;
if (S2posn < 0) S2posn = 8 + S2posn;

//Set posn of stepper motor 1 from 0 - 7
if (S1posn == 0)

else if (S1posn == 1)

else if (S1posn == 2)

else if (S1posn == 3)

else if (S1posn == 4)

else if (S1posn == 5)

else if (S1posn == 6)

else if (S1posn == 7)

//Set posn of stepper motor 2 from 0 - 7
if (S2posn == 0)

else if (S2posn == 1)

else if (S2posn == 2)

else if (S2posn == 3)

else if (S2posn == 4)

else if (S2posn == 5)

else if (S2posn == 6)

else if (S2posn == 7)

if (digitalRead(12) == 1) delay(30);
else delay(10);
}
 

 

If you have any interesting information or comments about this page, please add them here:


Your name:
Your message:
Security check: (Please type in the text to prove you're a person!)
 
Login status:  You have not yet entered your user name and password. You cannot create or edit documents until you do.
Enter your user name and password to log in

Remember me

If you click on the box marked 'remember me next time', you will not have to log in again on this computer for three months.

If you don't have a user name yet, please click here

Chat:

 
 
(Neil Bedford and John Rogers)
Midlands Meccano Guild
104th Model Report 
by Peter Stuart, Meccano Modellers Association Sydney Inc 
(Richard Smith and Neil Bedford)
Midlands Meccano Guild
102nd Meeting Model Report 
Spanner Challenge 
A G gauge model 
(Colin Bull & Richard Smith)
Midlands Meccano Guild
99th Meeting Model Report 
(G. Eiermann and M. Schild)
A Short History of MARKLIN Metall
 
96th Meeting Model Report 
83rd Meeting Model Report 
Picks up three golf balls 
The Spanner Challenge 
 
94th Meeting Report 
(Michael J. Walker)
Meet the new MMG President
Geoff Wright 
The Spanner Challenge 
(Michael Walker)
Midlands Meccano Guild
93rd Model Report 
(Stan Knight)
Minimal Meccano
Pocket Meccano Sets of the 1970s 
Little Lever, Bolton 
The Spanner Challenge 
(Bob Thompson)
Back to the beginning
Shop Display Model 
90th Meeting Report 
(Old Blue Gold)
Getting Old
A screwy story 
The Spanner Challenge 
Model report written by Michael J. Walker 
Exhibition in Nelson, New Zealand 
(Barry Gerdes)
Meccano Radio
 
(Rod Socket)
Dear Mrs Spanner
Survival techniques for the Meccanoman's wife 
(Stan Knight)
The Top Ten Tools
Indispensable Tools for the Meccanoman 
A call for help 
The Spanner Challenge 
(Stephen Heafield)
Waterslide Transfers
Refurbishing 0 & 00 Aero Models 
Mobile Morris Crane from 1968 MM 
The dangers of internet auctions 
Selected Spanner messages 18th to 24th January 
Selected Spanner messages 11th to 17th January 
Selected Spanner messages 4th to 10th January 
 
 
 View all | Chat | Models | Hints and Tips | Opinion | Reviews | Mine