Making the XY-Plotter and mDraw work together


#1

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.


#2

Adrian, thank you for the detailed comments. However, your X and Y axes do not match mine. In my mDraw Setup it shows the X axis as the one that the pen carriage is mounted on. This is the narrower dimension of the plotter. Of course, the Y axis is the other axis which is the longer dimension of the plotter and the axis that is driven by the fixed dual belt stepper. Looking at my plotter with the Orion Board facing me, the Y stepper is to the right of the Orion Board. Is this what your Setup looks like?

This difference causes a lot of confusion when I try to follow your comments. Perhaps we can work together to try and straighten this out.


#3

I assembled my plotter in February 2015 with the GRemote and Benbox software, which at that time suggested the pen-plotter carriage moved along the X-axis , and the fixed stepper motor to the right of the motherboard drove the Y-axis, as you have described in your post. The 0,0 origin was defined as the corner to the left of the motherboard.

In March, the first release of mDraw came out, which also conformed to that arrangement, and apart from having to change the dip-switches on the stepper motor, I could use either GRemote, Benbox or mDraw with no changes to hardware.

A subsequent mDraw release in May 2015 showed a different arrangement, where the pen-carriage was now the Y-axis, the X-axis driven by the fixed stepper motor, and the 0,0 origin now to the right of the motherboard, where the fixed stepper motor was mounted. I queried this change on these forums but had no reply.

Subsequent mDraw releases in August and September 2015 also continued this revised setup, and so my post was the result of an investigation I made into the software, both python and Arduino, to try and work out what changes I had to make to get the plotter I had built according to assembly instructions from February 2015 to work with software releases subsequent to this date.

If your version of the mDraw setup picture shows the X-axis as the one controlled by the stepper motor attached to the moving slide assembly than I suspect you have the earliest mDraw release, not the subsequent revisions. My investigations are only relevant to the May/August/September 2015 releases of mDraw and the Arduino code.


#4

Thanks for your reply. Makeblock has not been very good about keeping its software and firmware up to date. There are several versions floating around and it is difficult to determine which are the most current. Also, the documentation is not very good. I finally got everything working correctly after several weeks of effort. mDraw v 1.2.1 is the latest and it works correctly including Home. In XYSetup, it now shows S1, S2, S3, and S4 for the limit switches instead of -X, +X, -Y and +Y.

Makdblock’s tech support has been good and stuck with me until I got everything working correctly.


#5

Hi Adrian/Ollie…thanks for your dialogue …it’s helpful to see this stuff, especially as I have a COM issue that’s preventing me from starting up my newly constructed XY plotter. I’m new in this business of tweaking software and hardware to get it to work harmoniously …I have a few clues on how to do stuff… …but no detailed knowledge. So, ok, I got mDraw and the USB driver installed and hooked up to my plotter and nothing much happened…it fact see my post of 8/08/2016 about details. Then I read Adrian’s stuff about the Arduino IDE…huh? …there was nothing I saw before this that talked about even having Arduino IDE installed and getting into editing xybot.ino files to check limit switch settings etc? I must be missing the front end platform configuration of all this… I naively thought ok, install drivers, run mDraw and off you go. If you guys can fill me in on this front end configuration I’d much appreciate it. I have a new blockbuster application for the XY plotter and just wanna get the thing running so I can develop it.

Thanks, Jeff Turner, Vienna Austria


#6

I suggest you visit the Arduino home page to download their drivers and IDE, any advice I give will probably be out of date by now. Visit https://www.arduino.cc/ and get the IDE and drivers for your platform and go from there.


#7

Hi Adrian, thanks for your suggestion a few days ago. After a tip from tec support I realised my problem was actually with the incorrect com port setting. This was quickly fixed and the plotter is running great using the supplied USB driver - no need to get into the code …thankfully for me!!. I guess I’d get into Arduino etc if I wanted to modify it…

Thanks and regards, Jeff


#8

Thanks Adrian,

I followed your instructions exactly and my XY Plotter started working.

Thx a lot

Saleem


#9