Arduino code for the 2.5 axis draw bot I've been working on recently. Takes commands over serial to run. "SerialCommander" processing sketch runs command files generated by https://github.com/dankelley2/PlotterGen
Upon boot, the arduino will request a command by sending CMDREQUEST
over serial.
That is your key to type or send the next command. The arduino will immediately send another CMDREQUST
until
the commandBuffer (CommandBuffer class, cmd library) has stored 10 commands. This allows you to input more commands while the first command is still running.
To avoid too many string -> floating point conversions on the arduino, all distance related numerical command arguments (SPEED and STEPLEN commands have a different input) should be "distance in mm * 100". This allows you to use up to 1/100th of a mm for precision, while keeping the code clean and free of decimal places or scientific notation
COMMAND {newline}
or
COMMAND X_NUMBER Y_NUMBER {newline}
-
MA : Move Absolute. Moves to an absolute position.
- Example:"
MA 11053 5075
" Moves to the absolute position (110.53mm, 50.75mm)
- Example:"
-
MR : Move Relative. Moves to a position relative to the current position.
- Example:"
MR 1000 -2500
" Moves the relative position 10.00mm on the x axis and -25.00mm on the y axis
- Example:"
-
STEPLEN : Sets the number of steps per MM on the X and Y axis
- Example:"
STEPLEN 2325 6451
" Sets steps per MM on X axis to 23.25, and steps per MM on Y axis to 64.51. If more precision is needed, edit the defaults in the arduino sketch file
- Example:"
-
SPEED : Sets the maximum speed in steps per second. This is the only command that takes areguments as integers.
- Example:"
SPEED 600 400
" Sets speed on X axis to max 600 steps per second, and speed on Y axis to max 400 steps per second.
- Example:"
-
LIFT : Activate Servo to Lift pen. Servo 'UP' position defined in code as SERVO_UP
- Example:"
LIFT
"
- Example:"
-
DROP : Activate Servo to Drop pen. Servo 'DOWN' position defined in code as SERVO_DOWN
- Example:"
DROP
"
- Example:"
-
ZCHANGE : Toggles Servo position between up and down.
- Example:"
ZCHANGE
"
- Example:"
-
LIMITS : Set x and y limits (dimensions) of draw area defaults are 200mm X by 100mm Y
- Example:"
LIMITS 20000 10000
" Sets the size of the draw area and limits maximum travel to 200mm X by 100mm Y
- Example:"
-
HOME : Moves the X axis in a positive direction (right) until hitting an endstop (PIN_INPUT3), then moves Y in a negative direction until hitting an endstop (PIN_INPUT4), then moves back to the coordinates (0,0).
- Example:"
HOME
"
- Example:"
-
Z : Zero; Sets the current coordinates as (0,0)
- Example:"
Z
"
- Example:"
-
POS : Get current position in MM and print them via serial
- Example:"
POS
"
- Example:"
-
ON : Turns on outputs to stepper motors (Note: this is done automatically for MA and MR commands)
- Example:"
ON
"
- Example:"
-
OFF : Turns off outputs to stepper motors (Note: this is done automatically for MA and MR commands)
- Example:"
OFF
"
- Example:"
SPEED 600 400
LIFT
HOME
DROP
MR 1000 1000
MA 2000 1000
MA 2000 2000
MA 1000 2000
MA 1000 1000
LIFT
MA 0 0
LINE 1 - Limits draw area to 200mmX by 100mmY
LINE 2 - Sets max speed to 600 steps per second X and 400 steps per second Y
LINE 3 - Lifts pen off of paper
LINE 4 - Home carriage until endstops are hit, then go to (0,0)
LINE 5 - Lowers pen on to paper
LINE 6 - Move Right (X+) 10mm, and Down (Y+) 10mm
LINE 7..10 - Lines 7 through 10 draw a 1cm Square
LINE 11 - Lifts pen off of paper
LINE 12 - Moves back to (0,0), motors will be turned off automatically.