Goodbye Moshi or How to Run Your Laser Printer on Arduino
by Downunder35m in Workshop > Laser Cutting
44416 Views, 203 Favorites, 0 Comments
Goodbye Moshi or How to Run Your Laser Printer on Arduino
Update 19/04/2016:
MarlinKimbra is here!
This is one of the best firmwares based on Marlin I have seen for a long time, no feature is missing.
But for our purpose here it is just about being up to date and getting better results.
Please check the last step of this Ible as I will keep future updates there.
Update 11/04/2016: The new firmware is available now in my Ible about 8bit engraving.
This means the power level is now from 0 to 10000, giving a higher resolution for the power without compromising speed or other functions.
Engravings on fragile things like paper are now possible without burning holes.
All SD and display functions have been modified to suit the firmware, so you can move the head, do testburns at various power levels and even tweak most of the settings to be totally independant from a PC / laptop.
I tried my best to implement WiFi as well but could not get it working properly, so if you do want to transfer your Gcode files without swapping the SD use a WiFi enabled SD card instead.
Never tried it due to a lack of hardware but it should also work using Octoprint.
Update 27/02/2016:
True 8bit photo engraving is now possible, please check the addition here.
Update 26/02/2016:
I was able to change the Marlin code so that now a much higher resolution for the Laser PWM signal is possible.
Please beware that I also found a problem in the code.
The curent power settings are not deviced in 256 steps but limited to 100 - reflecting the original machines 0-100% settings!
I will do some tests on the weekend and if all good upload the modified firmware for everyone interested to test.
With that it should now be possible to do true 8bit engravings with a CO2 laser - something even Picengrave can't do at this stage.
I will also add links to the software used to used to generate the code the true greyscale engravings and how to modify the Gcode for proper placement on the machine. - Stay tuned!
When it comes to starting with CO2 lasers the beginner on a budget will be tempted to get one of the K40 clones from china.
As requests, problems and postings of general frustration about these machines flood the internet I though I jump in too.
Don't get me wrong, I did it on purpose as the price for the entire machine was about the same as just a 40W laser tube imported to Australia - and that is without a power supply...
I already started a topic in the forum on why not buy them but if you already did or still want to get one, this Ible might be helpful on your way.
What you will get in this Instructable:
All the info, sofware and tips you need to convert your budget laser cutter to run on an Arduino board - for far under 50$.
Also the satisfaction that you can now create all your things directly in Inkscape (or other vector programs).
What you need, tools, and such:
1. Patience...
If your machine is anything like mine you don't want to rush things as not everything is perfect in China.
2. A basic understanding of wiring some cables and some very soldering skills.
3. Basic toolset.
Flat and phillips head screwdriver, 7mm spanner (keep the set at hand, you never know...), pliers, side cutters, soldering iron, heat shrink tube or if in doubt electrical tape.
4. Arduino Mega with Ramps board, optional a display with encoder and SD support to have a stand alone solution.
5. Some old computer cables, connectors and such - I tried to keep the original cables the way they are, it is no problem not to use connectors and to solder directly.
The only thing I really suggest using connectors fo is on the pins for the ramps board, I used single LED pins from an old computer.
You can source the complete kits including Ramps and stepper drivers for around 30-40$ either through Ebay or your trusted local dealer.
6. Two 10kOhm resistors.
First to the specs:
40W CO2 laser - claimed power, so we can assume it is around 30W when you would measure it.
Unlike most of them I got mine with a digital power control and not the analog meter with potentiometer.
Rest is like any other chinese clone out there except the electronics...
Here can already make out if you might get some fun out of it or not.
Mine came with the totally outdated "Corel Laser draw", from 2013 and with a golden dongle.
Others have newer software and other dongle colors, indicating a newer control board.
The 2016 versions also support vector cutting and speed/power settings by line color definition (but they cost more and are very hard to find).
So unless you got the latest model you will most likely have it shipped with Moshi Draw, Corel Laser Draw (2013-2014) or in very rare cases with real software like you would find on high end machines - again for a much higher price.
Is this Ible interesting for me and does help my machine?
If you can only do engravings and cuts with raster images like BMP,JPG,TIF,PNG but not in any vector format then it can help you.
If your machine and software already come with full vector support and a print driver to use it with any software out there you might want to find other reading material.
Although some of the mods might be of interest to you anyway... ;)
I will start with some basics of the crippled stuff and how to improve your work a bit but the real deal starts at step 4 with the replacement of the controller board.
Can I use it for something else?
Of course you can!
As it is a "generic" approach this mod can also be used on your homemeade diode laser engraver.
You will need to modify the Marlin firmware to suit your needs though in terms of endstops, buil dimensions and such (easy!).
Info on the above images:
The pegasus was engraved on cheap, 3mm plywood - not a good choice LOL
My niece was engraved on plywood too but with the original Turnkey release and before the full 8 bit support was added.
And the old movie image with Billy the kid was engraved on Arakaria wood with the latest firmware mods.
The Hardware Limitations of the Original Controller
If you don't have one of the latest controllers installed you won't have any DSP or true vector support.
Even if it looks in the software like you do, you might have notices that your dimensions come out wrong in a lot of cases.
This is due to the simple fact that the cutter can only handle raster images but no true vector images.
Moving the head line by line to "print" and engraving is easy enough as simply the image is transfered line by line and pixel by pixel.
Where there is a dot there will be a burn mark.
That of course is also the reason why you can't just take a nice color image and burn it on some wood.
The software will transfer it to a grayscale image and use some algorithm to determine at which level there should be a burn or no burn.
Usually the result is far from satifying...
When you create some simple cuts within the software it will really look like it is doing vector cuts, while in relality the software just uses the lines to move the head around.
Saving such a cut and analysing it with a Hex editor shows everything is saved within the cryptic file, like dimensions of the table and work area but also the stuff to cut - as a transparent PNG image - again raster format.
All this comes from a controller that is unable to move the axis like a CNC machine.
The later software versions can sometimes cover for this but never really satisfy in the long run.
Ok, the controller might be crap, what about the rest?
On my tube was no sticker, mark or so telling me the claimed power or other electrical data.
The Y-axis has a linear rod and bearing only on one side, might be enough for a small work area but the loose other end tends to cause vibrations.
The X-axis is made from a weird profile that gives really good stability and uses only simple rollers to hold the laser head in position - again for short distance it might be enough.
You see where I'm getting?? ;)
Enough but never really good enough, like using just bots and nuts, no washers, lock washers or lock nuts.
If someting is a no fit or not aligned properly force it into the right place as the customer might never see it...
Let's just say you really get what you paid for it.
This means identical looking machines costing twice as much as the china version might have started the same way.
The difference is that someone took the time to make them compliant with local safety and electrical standards.
Things like adding a switch for the lid, flow and temp control for the water, plug on the machine for the fan and pump...
Means someone spent a lot of work hours getting the machine right for you ;)
Software Limitations of the Original Setup
As said if you can't define power or at least speed with different colors you might be frustrated every now and then.
The 2013, 2013 and 2014 software versions (to my knowledge) only support raster images.
To make things worse doing cuts from raster images might at first look like it is working fine but:
A vector line is a straight line, no matter what angle, a line on a raster image is always made from dots and quite often these dots overlap.
With a software being unable to put this into a clean and single movement you often see your head doing all sorts of movements except following the lines in the image.
Engraving seems to be the only thing really working with these machines but even there you need a lot of time and external programs to get really good results.
But if you manage to transfer a nice picture into a B/W bitmap that does not look to have too many totally black areas the result can be stunning.
Ripping the Old Machine Apart, Well Sort Of...
At first I decided to take a lot of pictures for this step so every little detail is covered.
Then the reality hit me by letting me know that there are several variations of the hardware out there :(
So I will try too keep it really simple....
Disconnect power and USB!!!
The original controller has to go out, same for the laser power supply.
The controller is mounted with 4 screws - take them out including the spacers and washers - if you find washers...
The power supply is mounted with 4 screws towards the inside on the machine, in some cases it might be mounted to the floor instead.
There might be a short cable channel or just cable ties used to sort the wires, get all wires loose without disconnecting them so you take out the power supply and controller with all cables attached.
Important!!: Now take a permanent marker and mark all connectors and sockets so if you have to re-connect you will be able to know where and in which direction!!
Check your pic so you are certain you see all details you need!
Disconnect all cables from the controller, it should be one plug with 4 wires going to the power supply, two 4-wire connectors for the stepper motors and one 3-wire connector for the endstops.
Put the controller, dongle and software somewhere safe.
Slide out the power supply if not already done to get access to the control panel above.
If you have problems getting to the 4 nuts holding it use a small ratchet and 7mm socket instead - I tried for 30 minutes to break my fingers until I realised the ratchet was right next to me.
Once you have the panel out take another pic of the connectors there - just in case...
Disconnect the panel from the laser power supply.
Here you either have a flat ribbon cable or similar plugs like used on the stepper motors.
Check the images from my hardware for comaprison - I will refer to them later again for the wiring of the Arduino.
As you can see the vital wires are all clearly marked on the circuits boards to make it easier for us ;)
Adding the Arduino
A huge thanks for doing all this hard work already goes to Dan Beaven who inspired my to try it myself.
Also without the work of Turnkey Tyranny we would not have a working firmware for our Arduinos or the Incscape G-code export plugin - great job!
Of course I also need to mention the great guys at the Lansing Makers Group who started all this pioneering work.
So don't be fooled to think I did all the hard work - thank those above for it!
To continue please prepare your RAMPS board so it can cater for 24V.
Check the Wiki page, in the power section you will find the location of the D1 and D2 diodes - D1 needs to be removed!
The two big, yellow plates are polyfuses and we need to short them with a lenght of wire so the board can handle the 24V properly if not done you might encounter random disconnections.
If you want to keep them for safety reasons please replace them with 30V types.
Now it is time to connect everything - I won't bother too much at this stage to make proper mounts an such as I still plan do some further mods to be covered in another Ible.
Please use the images from the last step as a reference, your internals might differ a bit but the basics are still the same, even if yours has a analog meter.
On the ramps board you need to check under the drivers if the jumpers are set correctly for 1/64 microstepping!
As it is the maximum these cheap drivers support you can put all 3 jumpers in there.
Dending on you skills and material at hand you will either use connectors or solder the wires without the right connectors directly - either I will only refer as "connecting" in this matter.
Check this nice diagram Dan Beaven made as a reference:
In my case there was no ribbon cable at all, just two identical connectors for the steppers, which caused me a bit of a headache at first.
To spare the headache use the above image a s a reference and do this:
The big cables between controller and PSU are the power supply, start with them and disregard the wire on the "LO" connction - you only need 5V, 24V and GND.
Only if your Laser power supply does not offer a PWM control you still need the power adjustment and the analog meter - plus make some minor changes in the firmware (documented).
Next connect the Laser fire and PWM signal wires - if your PSU is different check the circuit boards for the corresponding connections and use them.
Now do the stepper motors and if you have a ribbon cable for motor and endstops follow the above diagram, otherwise plug the motor in and prepare the endstop or cable to cater for pull up resistors.
If you are unsure about this step check this Wiki for the wiring details of the resistors.
Connect the endstops to ramps board, 5V and GND - it does not matter which 5V terminal or ground terminal is used here.
There is a chance your stepper motors will run in the wrong direction, if that happens simply put the connectors on in "reverse".
That should be the electronics for now, display with full motion control will be covered in the next Ible.
Flashing the Firmware Onto the Arduino
Update 19/04/2016:
Please ignore the files here as there is another step added for the latest firmware.
Go there and download always the lastest release I offer.
Right now all should be mechancially good on your end, the electronics back in the machine and all wiring double checked.
Time to get the software part working...
I tried firmwares directly from Dan Beaven as well as other releases based on the Turnkey Tyranny mods but either they totally failed to compile or did not work together with my machine.
The solution was to modify the firmware to suit the needs of a direct conversion without display or additional controls.
You will need the Arduino 1.05 ISP with the corresponding libraries to compile the firmware.
I spared you this nightmare and packed all the software for this Ible into one archive.
So please download it from here (200mb).
Everything is in there, so unpack to a folder on your computer and leave the folder structure as it is.
Connect the Arduino with the PC but do not power up the laser cutter yet.
Start the Arduino IDE and open the "Marlin.ide" file - the Marlin releas is located in the folder "My Machine/Marlin".
From the IDE tool menu set the Arduino Mega 2560 256 Serial Buffer as the board to make use of my changes in regards to the increased buffer sizes, but that is totally optional, you can use the standard Mega 2560 as well.
Select the serial port as it shows up in your systems device manager - it must be a match.
Upload the sketch and be patient it can take a while.
There should be no errors in regards to missing libraries, dependcies or includes and I won't help out if you used you own Arduino ISP to get it all going.
If your Ardunio does not connect or Windows can't find any drivers you might have a clone that uses the 341 chipset, I included them in the Archive as well.
The standard drivers for the Arduino are included with the IDE if Windoes fails to find the right ones online when you plug the Arduino in.
Firing Up the Machine
You are now at the point that turning on the machine should not cause any problems.
That means it is ready to use, well sort of...
Right now your new toy only knows how to communicate over USB and to accept G-Code commands through the serial connection.
Might not be as fancy as having dedicated printer drivers but our controller was well under the 50$ mark ;)
Does not look too nice right now but for the testing it was good enough, I suggest to screw the Arduino in place instead of placing it on isolating plastich sheets:
In the next stage this will be all cleaned up, a display and SD support added and if possible some tweaks in the firmware to get higher engraving speeds.
Note that only the drivers for the x- and y- axis are needed on the board, but I left them all on there for future upgrades and so I won't lose them.
Getting the Software Running
To generate the right g-code for this mod you need Inkscape and the corresponding plugin by Turnkey Tyranny.
I did not include Inkscape in the downloaded archive to be flexible with updates, please download your 32 bit version here.
I don't know if the plugin works with outher releases, like for the Mac but I do know it won't work with the 64 bit release.
After installing Inkscape copy the plugin into Inkscapes extension folder as explained in detail in the included "Readme.md" - basically just copy the .inx and .py file into the Inkscape extension folder C:\Program Files\Inkscape\share\extensions .
Now you can start Inkscape and select the plugin from the Extension menu.
A good start is to use the supplied "cutting_surface.svg" from the designs folder (in the folder of the plugin), it has some nice examples to try included.
WARNING:
Before you do anything with laser power make sure you never forget to keep the power levels low!
Through the direct PWM control of the Arduino the laser will be working at 18mA when 72% power is reached - this is the limit for these 40W tubes, 50 or 60W tubes might be able to use 100% if you dare to try.
Basic usage:
I won't explain all fine details of the possible settings, that will leave you some playtime for later.
But I will provide you with what you need to get going without ripping your hair out.
Inkscape can do a lot of things when it comes to creating your 2D designs but for the purpose of using the design with the laser we need to stick to some rules.
Line art:
Everything you design must end up as a path!!
This means you you have to convert your objects into a path to be able to cut it.
You can combine the paths group by group (e.g. make each hole into a seperate path) or for the entire object.
Keep in mind that overlapping lines in your design will be cut twice, so make sure all is "one piece".
Raster images:
If Inkscape can import it you can use it.
But I do not recommend using the plugin directly on any image that was not prepared prioe for laser cutting.
Tried it a few times with grascale and color images but the result was not really satisfying to say the best.
But if you convert your image before importing it into your project into a nice looking BW bitmap it will be "engraved" very nice indeed.
Preparing for the laser:
As said, make sure your design is either a raster image or a combined path.
The plugin works with two possible option to set the job.
a) Only trought the popup menu settings.
b) By naming your layer according to how you want to cut / engrave it.
Examples on the naming are included in the cutting_surface.svg file.
The good thing here is that you can set independent settings for each part of the job, like engraving an image at low speed and low power and a frame cutting at high power and medium speed.
A very nice feature is the PPM setting.
Here you specify how many pulses per mm are fired.
Depending on the material this really does make the job easier or gives better results.
Take glass engravings.
With the old hardware the machine fired a constant beam wherever there was someting to fire at.
Now you can specify to only fire 10 pulses per mm and prevent glass chipping for a nicer finnish.
Stinky materials like polysterene hard sheets just melt with the constant beam while with pulses you can shoot through the material without too much excess heat.
Requires some tweaking and testing to get it right though.
One of the big downsides I found is how the actual g-code is generated.
There is simply no way to specify the job order for a complex task.
To be precise: The plugin will only make sure that raster engravings come first, everything after seems to be total random to me.
So it is possible that by default the machine will cut out the part before trying to add the holes in the already dropped part.
If you use a nice honeycomb frame for the build area it does not matter too much for clamped objects it is not so nice.
I was unable to find a fix for this and I still struggle with Python to adjust the plugin to cater for some user settings for the cutting order.
But like for everything on Instructables there is a workaround.
Export the jobs one by one through the plugin in the order you wish and combine the g-code manually with an editor.
In the top of each .g file you will find something like this:
G21 ; All units in mm
M80 ; Turn on Optional Peripherals Board at LMN
; Raster data will always precede vector data
; Default Cut Feedrate 3600 mm per minute
; Default Move Feedrate 2400 mm per minute
; Default Laser Intensity 0 percent G28 XY; home X and Y
M5 ;turn the laser off
;(************************************************************)
;(***** Layer: 60 [feed=120] *****)
;(***** Laser Power: 60 *****)
;(***** Feed Rate: 120.0 *****)
;(************************************************************)
This defines the start and the initial setting for the first job are listed.
At the end of the file you always see something like this:
M5 ;turn the laser off
G00 X0 Y0 F4000 ; home
Turns off the laser and sends the head in the home position.
To combine your g codes you cut the M5 and G00 commands out of the first job.
From the next job you cut the top part off including the M5 command before the listing of the job details.
Add the second job to the first.
For the last job you only cut off the top part - again till the the listing of the job including the M5 command.
Leave the end of this job alone and add it to the rest.
Save the file with a new name and use it for your machine.
Cutting / engraving your creations
Sadly there is g-code sender included in the plugin so we have to substitude a program from the 3D printing world.
I included Proterface in the big download but other solutions should work the same.
Please keep in mind that Pronterface only acts as g-code sender but will be unable to give anything else.
You can load the g-code, start the job, pause it and adjust the speed on the fly - that's it.
Unless you added a lifting table to your machine the z-homing will not work.
So you should not use the home all button as otherwise the Arduino will wait forever for something to hit the z-endstop.
If I ever manage to get the compiler working properly I will change the UI of pronterface a bit to remove functions that are not needed.
You can see the machine running on the first firmware I got running properly in this video:
If you got enough from the engraving skip to 5:40 to see the raster engraving and cutting done.
Speeds:
I am still finetuning the firmware settings but vector cuts should work fine with up to 2400mm/s depending on the line lengths and complexity.
Raster engravings can run a bit faster but sometimes there is still a glitch causing massive rattling noise from the stepper and lost steps - if that happens lower your spped and reduce the laser power accordingly.
Simple things and contours can be lasered in vectors at up to 3600mm/min.
But I suggest to use lower speeds when possible and to test really high speeds on some cardboard first to prevent wasting some expensive material if you lose a step or two.
Accuracy:
The parts come out to the specified dimensions, some materials might cause a bit more loss, especially if the focus of the laser is not set properly.
Repeating a job did not give me any negative results at normal speeds, all lines match up perfectly.
If the speed is too high, or the motor current too low there will be lost steps though.
As cutting speeds are quite low anyway I guess for the time being the speed restrictions set in the firmware should still be higher than what the mechanics are good for.
Troubleshooting the Mechanics
If you really made it all the way here it means you either want to read it all or that something is not working as planned.
Before you continue confirm your driver boards are set to the correct stepping as the defined steps per mm are correctly defined in the firmware.
So any problems related to wrong dimensions should be gone once the stepping is jumpered correctly.
Loosing steps:
Although it should not happen it does not mean that it never will.
Assuming you did not lower the current for the motors too much the only thing left is the movement speed.
Trying to do a vector engraving of a really complex piece with 5000mm/min or more will just not work.
The algorithms in the firmware are optimised for 3D printing and have quite a bit of ballast we will never need and without documented changes I am unable to update all files to the latest Marlin RC.
This means you should keep your speed to sane levels.
Stepper motors won't work at all or stutter all the time:
If your stepping and the current setting on the driver boards is correct there is a chance that your EEPROM settings are messed up.
This happens quite easy if the Arduino was used for other projects before or simply by making a typo when manually sending commands to the machine.
To fix this open the example sketch in the EEPROM Library, replace the 512 for the memory size with 4096 and upload the sketch.
After that re-upload the Marlin firmware and your EEPROM should work as planned.
Axis won't move the right lenth:
This usually means the stepping on the driver boards is not a match for the motor stepping in the firmware.
Best solution is to set the jumpers on the Ramps board correctly or if the driver won't support the stepping to adjust the steps per mm in the firmware.
No complicated calculations needed, to go to the next lower stepping simply divide the steps per mm by two.
My cuttings and engravings burn through everything:
Keep in mind you no longer need to work with just a constant laser beam and that the laser is controlled differently now!
For cuts don't use the PPM control, for everything else do use it to get the best looking result.
The speed and power settings you are used to might no longer match now.
Things Planned for the Next Upgrade
For the second Ible on this topic you can expect the following:
1. Adding a nice case and fan for the Arduino.
2. Adding a display with encoder and SD support.
3. Adding a new control panel for the display and some more switches to remove all these plugs for fan, pump, compressor and so on.
4. Adding a better air assist system.
5. Adding safety switches for the lid and water flow.
6. Adding a manual firing button for testing purposes if I can add this into the firmware otherwise hardwired to the laser power supply.
These mods mostly depend on my long overdue display and finding the time to do the electrical mods, so it might be just a matter of two or three wekks.
For the third Ible on this topic you can expect the following:
1. Adding a motorized table with control through Pronterface.
2. Maybe adding a red laser for extra guidance with the manual control throught the display controller.
3. Checking the options to add a custom rotary adapter for round objects.
4. Making a new exhaust and adding a stronger fan.
5. If possible adding firmware support for the water pump, compressor and safety features.
6. Adding a lens mount with adjustable focus if the motorized table should fail for some reason.
Timeframe for these mods to be announced once the second part was running to my satisfaction for a while.
Firmware Mods
We now can cut in a proper way and also do raster engravings - but what about true 8bit engravings of greyscale images?
The above was done with a slightly modded firmware and the Gcode generated with Image2Gcode - the guys at vicious1.com did a great job with the tool.
But to get the best results from a CO2 cutter I had to make some slight changes.
If you are interested in quality engravings on your chinaware then check this Ible out - everything you need is there ;)
For the above image I had to do quite a few testruns as the target was a sheet of copy paper!
Size of the engraving is 65mm wide and 56mm high.
Engraving time: 26minutes.
The Latest Firmware Is Here!
I teamed up with some great guys working on the MarlinKimbra firmware.
Thanks to their work I can now offer the latest Marlin release to work with the K40 Laser clones.
Full 8bit engraving support through the Inkscape plugin allowing photo engravings with ease.
All configured for your K40.
Please download the attached hex file if you want to just flash with XLoader or go to Github and download the source files.
For the source files you will need the lates ArduinoIDE as the release requires it.
The firmware is already completly configured for the modifications of this Instructable.
Only if you use single pin control for firing your laser you need to check the wiring diagram and make the change in configuration_laser.h.
#define LASER_CONTROL 2
needs to be changed to
#define LASER_CONTROL 1
Display and SD are working fine so full standalone operation is possible.
No WiFi support as yet directly in the firmware but you can use a WiFi enabled SD card to transfer the files and forget about swapping the card.
Octoprint should work too but due to a lack of hardware I can't check.
Here is a video showing the machine engraving a photo.
Sorry for the bad quality but it is a pain to get proper focus through the orange lid - have to replace it with a clear one.
Here is an imaged engraved at 7200mm/min, size is 240x180mm, material: paper.
Time to engrave: 62minutes