Several people have asked previously about the X and Y axes of the plotter, or have complained of the pen moving in the wrong direction. I sorted this problem out a few months ago, but have only recently looked at how the confusion arose. Here is what to do if you don’t think your plotter is behaving as you expect it to.
You will need to know how to use the Arduino IDE to edit and upload programs to the Orion motherboard. If you haven’t yet done this, go to the Arduino site and study their notes for using the IDE, then go to the Makeblock main page, and look for their examples under the Orion Motherboard and other modules, for how to install the Makeblock Library for the Arduino, and how to include the necessary headers.
First, the terminology of the steppers, axes and limits.
There are two stepper motors. One is fixed to the outer frame and does not move, but drives two belts. One is on a sliding carriage, and drives a single belt.
The fixed stepper drives the two X-axis belts, the moving stepper drives the single Y-axis belt.
The setup diagram when you run mDraw and select the XYBot is correct, it shows the origin of the two axes by the fixed stepper, and identifies which direction in which each axis increases.
The stepper motor which moves the Y-axis should be connected to Port 1 on the motherboard.
The stepper which drives the X-axis should be connected to Port 2 on the motherboard.
The button marked “Wire” in mDraw shows this very clearly, and also names the two stepper motors.
Stepper A is connected to Port 1 and drives the Y-axis
Stepper B is connected to Port 2 and drives the X-axis
Now for the limit switches.
None of the help drawings show which ports the limit switches plug into. I built my plotter in February 2015, and the build instructions then specified the limit switches for the X-axis were connected by a short cable to Port 3, and the limit switches for the Y-axis by a long cable to port 6.
Since there was never a revised build diagram, I have left my switches as-built. (At least one other poster has mentioned he had to rewire his limit switches to make them work with the Arduino code properly).
Checking the build
Start by looking at your machine, without powering it on, and check these connections:
Port 1 goes to stepper A for the Y-axis (drives one belt)
Port 2 goes to Stepper B for the X-axis (drives two belts)
Port 3 goes to the X-limit switches (fixed to the main frame)
Port 6 goes to the Y-limit switches (slide from side to side)
(* IF your build instructions told you to connect the X-limit switches to port 6 and the Y-limit switches to port 3 then make sure you do see the correct values in the setup test and skip to the section on stepper motors.*)
Finally, check that on each stepper control board, the small Dip switches are set to HHH
Manually pull the carriage until the pen position is in the middle of the plotting area.
Connect the USB cable, power up the stepper motors, and start mDraw.
Change the bot type to XY from the drop down menu, connect to the Comms port, and wait until the green lettering advises success.
Click on the gear icon.
Press each limit switch in turn while watching the display, and see if the correct letters go from 1 to 0 when the switch is pressed.
X+ is the limit switch on the main frame furthest away from Stepper B, X- is the closer
Y+ is the limit switch on the opposite side of the pen to the stepper which drives it, Y- is on the same side as the stepper.
If you see X+ instead of X- and X- instead of X+, it means that the two connectors on the board where the wires from the limit switches meet the RJ12 cable need swapping around. Similarly for Y. (It is best to power down and change these plugs).
If you don’t see the correct letters ( X+ instead of Y+, etc), close mDraw and power off the stepper motors.
Correcting the limit switches (You can skip this if you get the correct switches in the previous test)
Make a backup copy of xybot.ino, saving it in a different folder and possibly even renaming it xybot_001.ino so we can go back and review changes if necessary.
Double click on xybot.ino to open the Arduino IDE
Work down through the lines of code until you come to
MePort stpA(PORT_1);
MePort stpB(PORT_2);
MePort ylimit(PORT_3);
int ylimit_pin1 = ylimit.pin1();
int ylimit_pin2 = ylimit.pin2();
MePort xlimit(PORT_6);
int xlimit_pin1 = xlimit.pin1();
int xlimit_pin2 = xlimit.pin2();
Notice here that Stepper A is assigned to Port 1, stepper B is assigned to port 2, BUT the Y-limits are on port 3 and the x-limits on port 6 (this is from the actual release code)
Edit the line “MePort ylimit (PORT_3)” and change the 3 to a 6.
Edit the line “MePort xLimit (PORT_6)” and change the 6 to a 3.
Save the code, then press the tick button to check it. If it gives you errors, they are either saying it can’t find Makeblock.h which means you haven’t installed the Makeblock library correctly, or they are hinting at some mistake in the lines you typed in.
Once the checks are OK, press the upload button. The Leds on the motherboard should flash, and the servo probably rattle.
Close the Arduino IDE and power up the steppers, then start mDraw.
Again, select the XY bot, connect to the right comms port, and press the Gear icon.
Check each limit switch again. This time, you should see the X limit switches showing an X result, and similarly for the Y. You may still need to swap the two connectors over on the board if you get X+ instead of X- and Y+ instead of Y-. It is crucial to get the correct switches operating for the Home function to work without crashing into the frame.
Now that the limit switches are agreeing with the code, it’s time to look at the stepper motors.
Checking the stepper motors
Close mDraw, power down the steppers, make a backup copy of your xybot.ino. (Perhaps xybot_002.ino).
Open xybot.ino in the Arduino IDE.
Page down through the file until you come to the function “void prepareMove()”
Look for two lines
tarA = tarX*STEPS_PER_MM;
tarB = tarY*STEPS_PER_MM;
Remember earlier we said the Y-axis was driven from Stepper A on Port 1 and the X-axis from stepper B on Port 2? Well, these two lines don’t agree with that, so we have to change them. (Again, these lines come from the actual release code).
Alter the first line so that it uses tarY, and alter the second line so it uses tarX
Save the file, and check it compiles without errors before moving onto the next step.
Scroll down a few lines to the GoHome() function, and note that the xlimits pins are checked whilst stepper B is being worked, and the ylimit pins are checked whilst stepper A is being worked. (Isn’t it a good thing we checked that the X and Y limit switches were actually correct before we rushed to press the Home button?)
Scroll down through the file until you come to the function “void initRobotSetup()”
Scroll down a few lines until you come to two lines
roboSetup.data.motoADir = 0;
roboSetup.data.motoBDir = 0;
We don’t need to change them (yet), just remember where you saw them.
Scroll down through the code until you come to the section with a comment “// init motor direction"
Two lines below this is a comment " // A = x, B = y”
As this is a comment there is no need to change it since it won’t affect anything, but it is a warning that the programmer here was getting a bit lost, and it probably explains why we had to correct the tarA and tarB lines above. (This is what happens when programmers drink too much black coffee and work too late at night)
We don’t need to change the direction settings (yet) until we have found out if our motors go the way we want them too.
Save the file, check it compiles, then upload it to the Orion. Once it says “done uploading” close the Arduino IDE.
Pull the pen carriage so it is in the middle of the work area, power up the steppers, start mDraw, select XY from the drop-down, and connect to the comms port. Use the gear icon to bring up the settings window, and just check your limit switches all still work. (I do this out of habit now).
Take a note of the directions shown on the two motors, then press OK.
You should now be back on the main page, with the blue dot showing the extruder head in the bottom left corner.
Wait until the servo has worked and the green message appears to say the connection has been successfully made.
Double click a short distance to the right of the blue dot and see which way the X-axis moved. If it increased (moved away from the stepper motor motor which drives it), the direction is OK
Double-click a short distance above the blue dot and see which way the Y-carriage moved. if it increased (moved away from the stepper motor which drives it), the direction is OK
If one or both of the steppers moved in the opposite direction to that which it should have, click on the gear icon, and remembering that Stepper A is for the Y-axis and Stepper B is for the X-axis, press the appropriate buttons to change the direction the motor rotates in, keeping a note of which ones you had to change.
Click OK, wait for the green message to report successful restart, and then repeat the two tests of X-movement and Y-movement.
When both X and Y axes increase when you click to the right and above the extruder dot, try clicking below and to the left of the blue dot a short distance to check that the steppers run in the reverse direction. (If they don’t then you maybe have a loose wire or wrong connection on the plug).
Once happy that the motors are running in the proper direction, click the home button and see if the carriage goes all the way back to the 0,0 position.
(If it stops short, try clicking the home button again, and if you need to click the home button more than once to get back to 0,0 you will need to see my other post about debouncing limit switches).
Close mDraw, power off the steppers, take a backup copy of xybot.ino, then open it in the Arduino IDE.
Scroll down through the file to the setup lines I mentioned earlier,
roboSetup.data.motoADir = 0;
roboSetup.data.motoBDir = 0;
If you had to reverse the direction of Motor A, then change the MotoADir value to 1;
If you had to reverse the direction of Motor B, then change the MotoBDir value to 1;
Save the file, check it compiles, then upload it to the Orion.
Close the Arduino IDE, power up the steppers, start mDraw, and test your changes. You should now find that when you go into the setup screen, the motor directions have already been set by the software and you don’t need to change them.
Your plotter should now work as expected.
Don’t forget, the upload firmware button will not upload your changed code to the Arduino, but instead uploads a pre-compiled hex file that ships as the factory default, and which may contain the very errors you have spent all this time correcting.
So, if every now and then you set the stepper switches to HHL, and run BenBox or GRemote, when you are done and want to run mDraw, after setting the stepper switches back to HHH, use the Arduino IDE to upload your xybot.ino file, otherwise all sorts of strange things will happen, (if anything happens at all).
In a follow-up post I will show how to add some code to obey the limit switches whilst drawing.