Feb 192018
 
Raspberry Pi controlled K40 laser cutter using k40 whisperer

I bought a Chinese K40-style laser cutter about three weeks ago and I’ve been spending quite a bit of time playing with it learning how best to use it.

It’s an eminently hackable design, and while mine could cut 3mm acrylic OK ‘straight out of the box’, there are many things that can be done to make it better, easier to use and more user-friendly. I’ve had great fun doing a whole host of upgrades and improvements to it, but that’s not what I’m focusing on today. Last week, Les Pounder published a blog article here where he showed the setup they use at the Blackpool MakerSpace. He described the use of K40 Whisperer by @scorchworks and from the screenshots I could tell he was using it in Linux.

I’d come across a page mentioning K40 Whisperer while researching K40 upgrades, but hadn’t downloaded it or tried it out so far. But the fact that Les had it up and running made me think “OK that’s definitely worth a look then.” And then I thought “I wonder if it runs OK on a Pi? That would be cool!” Not just cool, but really helpful too. My laser cutter occupies half of my workbench (until I can work out where to move it to)…

My K40 laser cutter takes up about half the space on my LARGE workbench. This is NOT sustainable

My K40 laser cutter takes up about half the space on my LARGE workbench. This is NOT sustainable

…and the old XP laptop running it takes up a lot of the remaining available space. So being able to run it on a Pi and SFTP job files to it instead of using a USB stick would be very useful.

My K40 Laser engraver/cutter turned around so you can see the laser tube

My K40 Laser engraver/cutter turned around so you can see the laser tube

Let’s Backtrack – What’s Wrong with the Supplied Software?

Why would you need alternative software to drive your laser cutter? Good question. And in reality, I don’t NEED it, but maybe it’s easier to use? I spent the first week learning how best to use the included Corel Laser software (complete with USB security dongle) and managed to create a workflow that let me do what I wanted to do.

However, I spent a lot of time ‘piddling about’ before I realised my software was set on the wrong control board. Once I’d got that fixed it was a bit easier. But the workflow using the Corel Laser package (based on a, frankly, suspicious copy of Corel Draw with a dongle-protected laser engraving and cutting plugin) is rather lengthy and complex – and it only works on Windows.

The software is a bit fussy. There are lots of settings to get wrong and, initially I wrote myself a 3 page procedure so I wouldn’t forget how to do it.

3 page procedure for Corel workflow

3 page procedure for Corel workflow

It’s fairly involved. Oh – and did I mention, even when you have the “cut inside first” box ticked, sometimes it will cut the perimeter first and ruin your job for you (at no extra charge)? The way round this issue is to set up the final perimeter cut in a separate layer which gets done last. But it’s an additional faff I can do without. Enough ranting about Corel Laser!

So when someone waves an ‘open source laser cutter control package that might work on a Pi‘ under my nose, I owe it to myself to at least take a look at it. So I did.

Downloading and Installing K40 Whisperer

I read the Linux installation instructions and it really didn’t look too scary. I was also delighted to see that K40 Whisperer is written in Python. This means that if I ever want to change anything, there’s a fighting chance I might be able to. YAY!

The most complex thing in the Linux installation instructions is adding a udev entry to help with USB permissions, so it’s really no big deal. I went through the procedures in the instructions and amended them slightly because I got some error messages. There were a couple of ‘assumed’ packages missing. So here is my amended version of the installation instructions (which I will be sharing with @scorchworks in case he wants to include/amend the instructions for use on Pi).

I used a fairly clean installation of Raspbian Stretch and, before starting ran…

sudo apt-get update
sudo apt-get upgrade

Then over to the official instructions, with my additional comments in bold and italic

Setting up K40whisperer on Linux (by Dr. med. Jan Schiefer):

# Requirements

Prerequirements:
* python 2.7.x
* unzip
* udev
* inkscape

## Instructions

1. Create a group for the users who are allowed to use the laser cutter:
sudo groupadd lasercutter

2. Add your yourself to this group, replace [YOUR USERNAME] with your unix username:
sudo usermod -a -G lasercutter [YOUR USERNAME]

3. Eventually add other users who will use the laser cutter to the group

4. Plug in your laser cutter to your computer

5. Find out the usb device id of your laser cutter:
lsusb

lsusb will output something like this:
Bus 002 Device 003: ID 04f2:b34c Chicony Electronics Co., Ltd
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 8087:07da Intel Corp.
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 003: ID 1a86:5512 QinHeng Electronics CH341 in EPP/MEM/I2C mode, EPP/I2C adapter
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

“QinHeng Electronics CH341 in EPP/MEM/I2C mode, EPP/I2C adapter” is your laser cutter in this case.
In this example “1a86” is the VENDOR ID and “5512” the PRODUCT ID.

6. Create a udev control file for your laser cutter as root (i will use gedit in this example):
sudo gedit /etc/udev/rules.d/97-ctc-lasercutter.rules

I don’t have gedit on my pi, so used nano. So it became
sudo nano /etc/udev/rules.d/97-ctc-lasercutter.rules

Put the following text into the file and replace [VENDOR ID] and [PRODUCT ID] with the information you obtained from lsusb:
SUBSYSTEM=="usb", ATTRS{idVendor}=="[VENDOR ID]", ATTRS{idProduct}=="[PRODUCT ID]", ENV{DEVTYPE}=="usb_device", MODE="0664", GROUP="lasercutter"

Now save the file. (ctrl+o, ctrl+x)

6. Reboot your computer!

6a. For Raspberry Pi
sudo apt-get install libxml2-dev libxslt-dev
sudo apt-get install inkscape
(the dev packages are omitted from the instructions)

7. Download the K40whisperer source code, for example “K40_Whisperer-0.17_src.zip”
I used this wget command from the Pi directly
wget http://www.scorchworks.com/K40whisperer/K40_Whisperer-0.17_src.zip (0.17 is the current version)

8. Unzip the source code, for example:
unzip K40_Whisperer-0.17_src.zip -d /home/[YOUR USERNAME]/
Already in /home/pi, I just used unzip K40_Whisperer-0.17_src.zip

9. Go to the K40 whisperer source directory, for example:
cd /home/[YOUR USERNAME]/K40_Whisperer-0.17_src/

10. Install the required python packages:
pip install -r requirements.txt

11. Run K40whisperer: python2 ./k40_whisperer.py OR python ./k40_whisperer.py
For some reason the udev thing didn’t seem to grant the pi user permission to use USB, so it failed when I tried to initialise the laser cutter. But then I tried…
sudo python k40_whisperer.py

…and that worked perfectly. I know many people frown on running things with sudo. But I don’t care as long as I can make the machine do what I want it to.

12. Go to Setting –> General settings

13. Select your laser control board name (usually LASER-M2)

14. HAPPY CUTTING!

I’m sure there’s a way to sort out the udev/sudo thing, but I was after a quick result so I haven’t pursued that yet. I got this software up and running and was cutting Perspex within an hour. That’s the kind of result I like.

What is the Workflow? How Well Does it Work?

My usual workflow looks something like this…

  • Create design in QCAD (on my Mac) and save as .dxf and .svg (to get usable .svg you need to purchase a license for QCAD, but for .dxf you don’t. K40 Whisperer can open .dxf as well)
    A quick design for a GoPro shelf mount

    A quick design for a GoPro shelf mount

  • Add any graphical elements to the .svg in InkScape (on Mac & Pi, certain fonts like the RasPi.TV and RasP.iO font Mandela only work as graphics, so I can’t use .dxf for those) black for engrave, blue for vector engrave, red for vector cut
  • SFTP the completed .svg to the Pi (which is always on)
  • Switch on the laser cutter and its peripheral devices (extraction, lighting etc.)
  • Position the material to be cut and align it with the bed and the laser
  • In K40 Whisperer, load the .svg we sent to the Pi
    K40 Whisperer GUI control panel

    K40 Whisperer GUI control panel

  • Position the laser head so it’s aligned on the material so that top-left of our loaded .svg is the starting point
  • Run Raster Engrave (engraves all BLACK elements in the .svg) at 8% power (manually set) and 200 mm/s (software set)
  • Run Vector Cut (cuts all RED lines in the .svg) at 16% power and 8 mm/s
  • Remove the workpiece
    GoPro shelf mount freshly cut

    GoPro shelf mount freshly cut

  • Do any additional operations required (e.g. thread tapping, heat bending etc.)
Completed GoPro shelf mount after heat bending and tapping

Completed GoPro shelf mount after heat bending and tapping

Your optimum power and speed settings will not be the same as mine. They will depend on quality, age and condition of laser, lens, mirrors, setup and alignment of everything. So there is some experimentation required. It’s good to have some scrap material handy for such experimentation and tweaking.

How Well Does it Work?

In general I find it has improved my workflow considerably. There is a lot less piddling about needed to get an engrave and a cut both done on the same workpiece. I love the fact that I can send job files to the cutter by SFTP. This saves time as well. The adjustable ‘jog-step’ feature is excellent for helping to get your laser positioned quickly.

I’m using a Pi 3B. Sometimes it can take a minute or so to generate the raster lines for a complex or large engraving, or to import and process a large cut file, but it’s perfectly usable. A Pi Zero would work too if you were patient enough (I’m not).

I’m using K40 Whisperer routinely now instead of the supplied software. It meets my needs better and saves me time. WIN!

You can also use inkscape or even (Illustrator – EUW!) to create your designs, but I prefer a CAD package because I’ve already learnt how to use it. The point is, you have choices.

If you need to tweak anything in the .svg files you can also use inkscape locally on the Pi. It works at a perfectly usable speed.

Anything Bad?

Nothing much to report in the way of negatives…

  • Sometimes you get USB timeout errors, but I haven’t had one spoil a cut yet.
  • I have to run it as sudo for the moment, but I expect that’s relatively easily fixed by someone who knows about all things USB and permissions.

Summary

If you have a K40 laser cutter (and they’re becoming ever more popular) then you should seriously consider ditching the supplied software and running it with K40 Whisperer on a Pi.

Raspberry Pi Bases Made with K40 Whisperer

I’ve actually just launched two simple bases for the Raspberry Pi B and Zero models. Both of these are cut using K40 Whisperer. I don’t know of any other Raspberry Pi cases or bases being manufactured using a Pi. I think this might be a first. They’re available in the RasPiO online shop or you can add them to your cart right from this page…

  21 Responses to “Run a K40 Laser Cutter from Your Raspberry Pi with K40 Whisperer”

  1. I think this:

    “For some reason the udev thing didn’t seem to grant the pi user permission to use USB, so it failed when I tried to initialise the laser cutter. But then I tried…”

    Is because this line:

    SUBSYSTEM==”usb”, ATTRS{idVendor}==”[VENDOR ID]”, ATTRS{idProduct}==”[PRODUCT ID]”, ENV{DEVTYPE}==”usb_device”, MODE=”0664″, GROUP=”lasercutter”

    … configures a device node with permissions to suit a member of the ‘lasercutter’ group (r/w for root and group members, read-only for everyone else). You didn’t mention adding yourself to the group so try:

    sudo adduser pi lasercutter

    Logout and in, confirm you (“pi”) have been added to the group (via ‘groups’) and away you go.

    • thanks I’ll check it out and try it.

      I thought that’s what this command did…

      sudo usermod -a -G lasercutter [YOUR USERNAME]

      Actually it must do because groups output is…

      pi@raspberrypi:~ $ groups
      pi adm dialout cdrom sudo audio video plugdev games users input netdev gpio i2c spi lasercutter
      pi@raspberrypi:~ $ 
      • I think the `adduser` version is considered the newer/better/more correct way, but they both achieve the same thing. How do you do code formatting here? Is it Markdown?

        • Ah, sorry, I’d failed (twice!) to notice the `sudo usermod -a -G lasercutter …` in the original writeup. In which case, I’m out of ideas!

        • In WP itself you can use their ‘code’ tag which is like html < and > with code in the middle </ > to close.
          But in post comments you can do the same with square brackets [ ]

  2. Thanks for posting this!

    Can you recomend a site to purchase the laser cutter used in this project?

    • Actually, sorry I can’t because the company I bought it from haven’t got any left and I don’t know any of the other suppliers. I will only recommend known good suppliers. There are loads (of unknowns) on ebay though.

  3. Take a look on Ebay..that’s where I got mine. They are pretty cheap.

    • Thanks lain, Alex. I guess K40 is the name of the laster cutter. Right?

      • Sort of..the K40 is more of a generic name for the cutter as far as I can make out and there are a number of companies selling them. I think they are pretty much the same unit, but there may be some subtle differences. Then some people seem to do some enhancements and you can find those on ebay too. I’m very new to all this, so I could be totally wrong, but that is how I think it works.

        • I see. Is there any chance you still have a link to the one you bought?

        • I’ve done lots of enhancements to mine, but those are a story for another blog article :)

          I also think there is variability in the quality of the components, motors, assembly, mirrors, laser tube, lens etc.
          K40 is the generic term for the A4 laser cutter out of china that looks like this one. Some are identical, some are different.
          I haven’t yet seen anyone else post a photo of one exactly the same as mine.

          That’s not overly helpful (sorry) but it’s true. It’s also the reason why I won’t make a recommendation. If the place I bought mine from had any left, I would have linked it. But they don’t! Even if they get any more in, they might not be the same. That’s the nature of buying things from China.

      • I just searched for K40 laser cutter on ebay then looked through what came up. Mine was second hand (nearly new) and cost about £300.

  4. there’s a GitHub repo that provides an installation script for the Raspberry Pi:
    https://github.com/the-real-orca/k40_whisperer
    see the Raspberry Pi Readme …

  5. No video, whats the point

    • Back in the dark ages when kids could read, people shared information using words and pictures with no sound. You don’t need a video to show you how to install this software.

  6. I’ve been looking at one of these on eBay for ages, haven’t got the room :(, yet. The 3B+ you’ve just reviewed should make a nice driver for one of these.
    I do have Visio though which exports to SVG and DXF, Blue and Red lines are no problem with Visio.. just need to find the room… Cheers for the notes, very useful.

    • No problem. I’ve had a lot of fun with mine. Will be publishing some blogs with some of my mods in the not too distant future :)

      • Love the flat laser cut plates for Pi’s – look forward to your mods – your mods are invariably great bits of engineering – I’ve watched a couple of the K40 setup videos so get the picture that they are kind of thrown together…

Leave a Reply