How to begin with Yoctopuce devices on Linux

How to begin with Yoctopuce devices on Linux

This week we continue our series of articles "For the beginners". We provide the answer the two most frequently asked questions regarding Linux: Why does the executable not work? And, why do I get the error message "the user has insufficient permissions to access USB devices" ?

I start the executable but nothing happens

This is probably the most frequently asked question. Users download the command line library or the VirtualHub, start the executable but Linux does not execute it.

In allmost all cases, it is just due to the fact that you are running the wrong version of the binary. Unlike Windows or OSX, Linux can be installed on many architectures, that are incompatible with each other. For this reason, we provide several versions of the VirtualHub and the command line binaries.

We provide executables for the 6 most common architectures:

  • 32-bit Intel in the 32Bits directory
  • Intel 64 bits in the 64Bits directory
  • ARM soft float in the armel directory
  • ARM hard float in the armhf directory
  • ARM 64 bits in the aarch64 directory
  • Big-endian MIPS in the mips directory
  • Little-endian MIPS in the mipsel directory

If you use the wrong version of the executable, sometimes an error message indicates that it's not compatible, but with for minimalist distributions, such as OpenWRT, the shell gives control back without any error message, which can be confusing.

In order to determine which binary to use, it is necessary to know what type of CPU your system uses, but also in what mode it is running: an Intel processors can run in 32 bit or 64 bit modes, an ARM processor can operate in "soft float" or "hard float" mode and finally a MIPS processor can work in "little-endian" or "bin-endian" mode. In general, it's easy to find which processor your Linux machine is using by looking at the manufacturer's site, or using the uname -m command.

For the mode in which the processor works, it's more complicated because it depends on the options used during the compilation of the Linux kernel of the distribution. For example, on a Raspberry Pi, the official Raspbian distribution uses the "hard float" mode while the ARCHLinux distribution uses the "soft float" mode.

Unfortunately there is no universal way to determine in which mode your CPU works. If you do not know what is the architecture of your system, the easiest way is to try all the binaries until there is one that runs. It is crude, but it works: -)

The executable stop with the the message: "the user has insufficient permissions to access USB devices"

By default, Linux prevents write access to USB devices for non-root users. This is due to udev device manager.

To work around the problem, the most basic solution is simply to run the executables as root using the sudo command.

pi@raspberrypi:~/Binaries/linux/armhf $ sudo ./YModule inventory LIGHTMK3-33FB1 YBUZZER2-345B9 pi@raspberrypi:~/Binaries/linux/armhf $

However, for convenience and security, it is better to add an udev rule that grants users or groups write access to Yoctopuce devices.

The udev rules are stored in files placed in the /etc/udev/rules.d directory. The file name must matche the "##-ArbitraryName.rules" pattern. When starting the system, udev will read in alphabetical order all files with the extension ".rules" in this directory, and apply the rules.

Writing a udev rules is quite complex, but we will see how to create the two rules that should correspond to 99% of the use case. If your case is not covered, turn to the official documentation to write your own rule.

Allow all users to use Yoctopuce modules

The following rule allows all users to read and write to Yoctopuce USB devices. Access rights for all other devices are not changed.

# udev rules to allow write access to all users for Yoctopuce USB devices SUBSYSTEM=="usb", ATTR{idVendor}=="24e0", MODE="0666"

Allow users in a group to use Yoctopuce modules

If you need more control it is possible to allow only one user group to use Yoctopuce USB devices. For example, with the following rule only users who are members of the "yoctogroup" group can access the Yoctopuce modules.

# udev rules to allow write access to all users of "yoctogroup" for Yoctopuce USB devices SUBSYSTEM=="usb", ATTR{idVendor}=="24e0", MODE="0664", GROUP="yoctogroup"

To use one of these rules, simply save the rule in a file named "51-yoctopuce.rules" and place it in the directory "/etc/udev/rules.d" and reboot your system. Note that to add a rule you will need to have root access on the system.

Once the new rule is installed, users can use Yoctopuce modules.

pi@raspberrypi:~/Binaries/linux/armhf $ ./YModule inventory LIGHTMK3-33FB1 YBUZZER2-345B9 pi@raspberrypi:~/Binaries/linux/armhf $

Add a comment No comment yet Back to blog

Yoctopuce, get your stuff connected.