Friday, January 20, 2017

Connecting Phidgets on Linux


To get up and running Artisan under Linux using Phidgets is not completely trivial (but doable). While the installation of Artisan should not pose any problem if the installation instructions are followed, getting Artisan to read data from connected Phidgets needs some preparation.

To allow an app to accessing data from a Phidget requires the installation of a device driver on for the corresponding OS platform. Additionally, most modern Linux configurations restrict the access to USB devices to the root user by default. Here are instructions on how to install the Phidgets device driver and allow any user to access Phidgets connected via USB.


Phidgets driver installation


On Linux the phidgets driver has to be installed from source code. The compilation of this source requires the libusb-1.0 development libraries to be installed.

Install the libusb development package


Type the commands after the sharp sign into a terminal shell.

  • on CentOS/Redhat
# sudo yum install libusbx-devl
  • Ubuntu/Rasbian/Debian
# sudo apt-get install libusb-1.0-0-dev

Install the Phidgets libs 


Download the libs from https://www.phidgets.com/downloads/phidget22/libraries/linux/libphidget22.tar.gz

# cd /tmp 
wget https://www.phidgets.com/downloads/phidget22/libraries/linux/libphidget22.tar.gz

Compile and install the libs

# cd libphidget-*
# ./configure
# make
# sudo make install

By default the phidget libs are installed in /usr/local/lib. However, some system like Raspbian do not search that path for libraries by default. In that case you either ask configure to install the libraries in /usr/lib using the following command instead of the above sequence


./configure --prefix=/usr && make && sudo make install

or you add  /usr/local/lib to the system-wide library path


echo /usr/local/lib >> /etc/ld.so.conf && sudo ldconfig

or you add /usr/local/lib in your local shell every time


export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib


See Phidgets on OS - Linux for further details.

Extend the USB access rules


Next we install the udev rules file for Phidgets to allow access to USB devices for non-root user. Note that this is documented in some detail in the Phidgets documentation for Linux under Advanced Uses.

# cd /tmp/libphidget22-*
# sudo cp plat/linux/udev/99-libphidget22.rules /etc/udev/rules.d

for the legacy Phidgets21 driver the path in the above line is:
# sudo cp udev/99-phidgets.rules /etc/udev/rules.d

Now we have to either reboot or enter the following commands to restart the udev system respecting those new rules.

# sudo udevadm control --reload

EDIT: on some systems (e.g. Raspbian) the udevadm command seems not to be enough to establish the new rules. A reboot should work in any case.




Testing the Driver


To test the driver installation you can download the HelloWolrd Phidgets test



# cd /tmp
# wget https://www.phidgets.com/downloads/phidget22/examples/c/Manager/Phidget22_HelloWorld_C_Ex.zip
# unzip Phidget22_HelloWorld_C_Ex.zip
# cd HelloWorld_Example
# gcc HelloWorld.c -o HelloWorld -lphidget22
# ./HelloWorld

if the above fails to list your connected Phidgets and only

# sudo ./HelloWorld

list them correctly,  you need to install the udev rules (or reboot after installation).

If the Phidgets HelloWorld does not list your Phidgets, Artisan will not be able to attach to them.



Configure Artisan


Finally, we need to select the Phidget type (here a 1048 module) as main device in Artisan via the Device Assignment dialog (menu Config >> Devices).


Thanks to Rob Gardner for his support on this!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.