Close

Connecting USB lasers to linux

A project log for The Technique of Laser

Laser cutter usage notes

peter-walshPeter Walsh 10/16/2020 at 16:010 Comments

Overview

This post explains how to troubleshoot and fix USB laser cutter connection problems on linux.

More specifically, if:

...this post will take you through the steps needed to troubleshoot the problem.

Step 1: The Quick Fix

If you are reading this post for the first time, see if this fixes your problem.

In a command window, type:

> sudo usermod -a -G dialout $USER

Enter your password when prompted, and if no error is shown reboot your system.

If your software now works with your laser, you're done: It was a permissions problem, you fixed it, you can stop reading.

(Note: enter the command literally as shown, including the $USER field. $USER is a variable set by the command prompt containing your login name.)

If this does not fix the problem, the next steps will help you identify where the problem is, and give some suggestions on how to fix it.

Step 2: Hardware/Electrical

The first step is to check the physical USB connection to your laser.

With the laser disconnected from your computer, in a terminal window enter "lsusb" to list the USB devices. (Note: "lsusb" is one word, no spaces.)

Without rebooting, connect the laser to your computer and enter "lsusb" a second time.

Look for an extra device in the USB listing, one that appears after you connect your laser.

For example, on my system I see the following:


Before:

> lsusb
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

After: > lsusb Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 005 Device 002: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

When I connect my laser to my linux system, a new device of type "Future Technologies USB-Serial" is seen by the system, and all is good.

If you do *not* see a new device line (of any type) when connecting your laser, you have an electrical or physical problem with the USB connection.

Some things to try:

Step 3: Device drivers

If your laser is shown on the USB listing, the next step is to see if the system is using the correct device driver.

With the laser disconnected from your computer, in a terminal window enter "ls /dev" to list the available system devices. (Note: "ls /dev" is two words, with space between.)

Without rebooting, connect the laser to your computer and enter "ls /dev" a second time.

Look for an extra file that appears when you connect the laser.

For example, on my system I see the following:

Before:

> ls /dev
bsg dvdrw i2c-4 loop6 ppp snapshot ttyS14 ttyS26 uhid vcs5 vhci

After:

> ls /dev
bsg dvdrw i2c-4 loop6 ppp snapshot ttyS14 ttyS26 ttyUSB0 uhid vcs5 vhci

(The /dev listing is long, only the line with my laser device is shown.)

If you see a ttyUSB device appear when you plug in your laser, then your system has correctly identified your laser as a serial port device and you can move on to the next step. Most likely the file will be "ttyUSB0", but it might have a different digit on the end (ttyUSB1, ttyUSB5, or similar).

If not, then you have a device driver issue.

NOTE: All modern linux systems (less than 5 years old) are natively compatible with FT232 devices used by many lasers. Linux does not need to install extra drivers to interface to these devices.

All USB devices are identified by a "Vendor ID" (vid) and "Product ID" (pid). The "lsusb" listing shows these numbers, so one thing you can try is to google "laser" with those numbers and see if someone else had a similar problem, and what they did to fix it.

So for example, the FT232 serial port on my laser is USB ID 0403:6001. Googling "laser 0403:6001" returns a long list of people having trouble with the FT232 driver. Adding linux ("linux laser 0403:6001") returns the linux users having problems with that device.

Linux records major actions in the file /var/log/syslog, so to see how it handles the device driver we can print out the lines appended to this file when you connect to your laser.

The command "tail -f /var/log/syslog" will print the last few lines of this file, and the "follow" argument (-f) keeps the command running and printing new lines as they arrive.

I execute that command, and then when I connect my laser I see the following:

> tail -f /var/log/syslog

Oct 16 16:24:31 Vulcan kernel: [ 3854.500618] usb 5-3: new full-speed USB device number 5 using ohci-pci
Oct 16 16:24:32 Vulcan kernel: [ 3854.710880] usb 5-3: New USB device found, idVendor=0403, idProduct=6001
Oct 16 16:24:32 Vulcan kernel: [ 3854.710888] usb 5-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Oct 16 16:24:32 Vulcan kernel: [ 3854.710893] usb 5-3: Product: FT245R USB FIFO
Oct 16 16:24:32 Vulcan kernel: [ 3854.710896] usb 5-3: Manufacturer: FTDI
Oct 16 16:24:32 Vulcan kernel: [ 3854.710900] usb 5-3: SerialNumber: A5054ANB
Oct 16 16:24:32 Vulcan kernel: [ 3854.718919] ftdi_sio 5-3:1.0: FTDI USB Serial Device converter detected
Oct 16 16:24:32 Vulcan kernel: [ 3854.718978] usb 5-3: Detected FT232RL
Oct 16 16:24:32 Vulcan kernel: [ 3854.723026] usb 5-3: FTDI USB Serial Device converter now attached to ttyUSB0

 My workshop computer is "Vulcan", and the lines show a correct sequence of steps resulting in the device /dev/ttyUSB0 added to my system.

If there is a problem with the device driver, an error message will be entered, and that might indicate what the problem is and perhaps how to fix it.

You can also ask for help in one of the linux laser forums online or on your vendor's help section. If you paste the added syslog lines when you ask for help, someone can probably advise you.

The "Udev" system manages device creation on linux. When a new USB device is connected, Udev gets a notification: it reads the VID and PID from the device, decides which driver to use, and creates the associated device file in /dev.

If you are having trouble with your system at this point, you may need to force Udev to use a specific driver, or make some specific fix.

How to do this is beyond the scope of this document, but briefly you can create a text file in /etc/udev/rules.d that tells Udev what to do when it sees your laser device.

As an example, here is a Udev script that matches the FTDI device of my laser and sets the associated group on the device file to be "laserusers". Copy this file into /etc/udev/rules.d (using any name, with extension ".rules"), then whenever my laser is connected the device will be accessible to those users in the "laserusers" group.

I don't actually do this, it's just an example of how you might get around a Udev problem in linux.

SUBSYSTEM=="usb", ATTR{idProduct}=="0403", ATTR{idVendor}=="6001", MODE:="0660", GROUP="laserusers"

Step 4: File permissions

With the correct file in /dev, the next step is to examine the permissions.

With the laser connected, from a command prompt enter "ls -l /dev/ttyUSB*". This will give you the "long" listing of the file, which includes ownership and permissions. (Note: Command is three words, with spaces between). 

> ls -l /dev/ttyUSB*
crw-rw---- 1 root dialout 188, 1 Oct 16 17:34 /dev/ttyUSB0

>

The fields of interest here (highlighted) are the file permissions, the owner, and the group:

The permissions field contains three fields of 3 characters each (9 characters total), plus an extra "filetype" char on the front.

The first char "c" indicates that the file represents a character-oriented device, which is correct for a serial port. ("b" is a block-oriented device such as a disk, "d" is directory, and "-" is a normal file.)

The next three chars "rw-" give the owner ("root") read and write access to the file.

The three chars after that "rw-" give members of the group ("dialout") read and write access.

The final three characters "---" give all other users no access to the file.

By default, linux puts all serial ports in the "dialout" group, and also by default linux users are not members of this group. So by default, users are are in the "all other" category and have permissions given by the last three chars: "---" indicates no access.

On linux, this is the most likely reason your software can't access your laser. In the vast majority of cases, simply adding the user to the "dialout" group will allow file access, and the software will work normally.

To see which groups you belong to, from a command window enter "groups".

For example, when I type "groups" I see:

> groups
pwalsh adm dialout cdrom sudo dip plugdev lpadmin sambashare

>

This shows that I belong to the "dialout" group (among others). As a member of that group, I have "rw-" access to the device file.

To add yourself to the "dialout" group, from a command prompt enter:

> sudo usermod -a -G dialout $USER

Enter your password when prompted, and if no error is shown reboot your system.

Linux only checks the groups you belong to when you first log in to the system (at the GUI level), so to update these changes you have to log all the way out and back in again, or reboot the system. Rebooting is simpler.

If you have reached this point and your system is *still* not communicating correctly with your laser, it's time to contact your vendor and ask for help.

But here's some things you can try:

You can temporarily force the permissions to allow anyone access to the device and see if this helps. From a command prompt, enter:

> sudo chmod 666 /dev/ttyUSB0

Enter your password when prompted, then without rebooting see if your software can now connect to your laser. Be sure to type the device file for your laser, if it's isn't ttyUSB0 as shown.

This change is temporary, it will revert to the original permissions on the next reboot so once you change it you don't have to worry about undoing it later.

You can place the previous command ("chmod 666 /dev/ttyUSB0") in /etc/rc.local to force permissions at system boot, but this is not recommended: it will only work if your laser is powered on and connected when the linux system boots. Disconnect or power cycle the laser without rebooting linux and the permissions will revert to the original settings.

If you need to set a specific group or permissions, the right way is to tell Udev (the linux device manager) exactly what you want to see. For example, the following Udev script will match a particular USB vid and pid to set permissions and group access:

SUBSYSTEM=="usb", ATTR{idProduct}=="0403", ATTR{idVendor}=="6001", MODE:="0660", GROUP="laserusers"

You will need to modify this script to match your specific laser (by VID and PID), and also set the permissions and group ownership you want.

So for example, if a file containing that line is saved as "/etc/udev/rules.d/Laser.rules" it will be executed whenever the laser connects to the linux system and set the permissions appropriately. The filename "Laser" is arbitrary and can be just about anything.

Discussions