element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Legacy Personal Blogs Step-by-step guide how to use GPIB with Raspberry Pi Linux
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: tin_xdevs
  • Date Created: 15 Aug 2015 7:22 PM Date Created
  • Views 14808 views
  • Likes 5 likes
  • Comments 15 comments
  • raspberry
  • python
  • pi
  • interfacing
  • linux-gpib
  • gpib
  • embedded
  • code
  • instrumentation
  • keithley
  • kernel
  • sudo_open
  • engineering
  • arm
  • automation
  • linux
Related
Recommended

Step-by-step guide how to use GPIB with Raspberry Pi Linux

tin_xdevs
tin_xdevs
15 Aug 2015

Using PC to control GPIB instruments, such as oscilloscopes, multimeters, power supplies is easiest thing, as most of vendors already supply ready to use libraries and packages to interface their instruments via GPIB. But if you want use using Linux-based OS or something like Raspberry Pi, things get tricky, especially for engineers who are not quiet familiar with Linux. Simple plugging GPIB adapter into Linux box will make nothing useful, as there are some compiling and packet tossing required, to make things exciting. Let's see how hard is that..

 

National Instruments GPIB-USB-HS dongle

 

First, take a look on hardware interface which we will be using in this tutorial.


There are multiple versions of USB-GPIB interfaces from National Instruments, and in this case I used previous generation GPIB-USB-HS.

While NI site lists Linux support, it’s declared only for RedHat, Scientific Linux and SUSE. If we want use it with something like Raspberry Pi with it’s Debian-based Linux system we are alone in the wild.

 

image

 

Very brief datasheet just covers basic installation and specification.

 

image image

Raspberry Pi setup

 

All information below is tested on Raspberry Pi 1 model B revision 2, using on-board USB connection. Linux version used was RASPBIAN Debian Wheezy, which we already go through basic setup doing I2C stuff before, in this article. If you need to setup system from scratch on blank SD card, suggest to reference that article first.

Below step by step tutorial for whole process of setting up GPIB-USB-HS to work with Raspberry Pi system, I'd like to give credits to “Forum thread on EEVBlog.com” and member bingo600, which was a great help

 

  1. Before installing stuff, I'd highly recommend to update current packets. All commands below are issued under admin root rights, so if you don’t usually logon under root, you may need use sudo.

 

apt-get update

 

  1. Install Linux kernel image, as linux-gpib module versions are specific for each kernel branch, and they both need match.

 

apt-get install linux-image-rpi-rpfv

 

In my case it put kernel verison 3.18.0. You can locate it in /boot directory, where two files should be present, such as initrd.img-3.18.0-trunk-rpi and vmlinuz-3.18.0-trunk-rpi


  1. In boot/config.txt append this at end of file , or it will boot the default “Foundation kernel”

 

************* SNIP ***********************
# Set params for "raspbian debian-style kernel" boot
kernel=vmlinuz-3.18.0-trunk-rpi
initramfs initrd.img-3.18.0-trunk-rpi followkernel

 

  1. Double check filenames and presence of files in /boot, otherwise your Raspberry Pi will not boot. If such happens, fix is easy. Just remove SD card, plug it into your PC and change config.txt file, as it’s accessible from FAT filesystem under usual OS, unlike rest of linux partitions on Raspberry’s SD card.
  2. After success with kernel change and boot, we can check kernel version and install header package:

 

pi@tin ~ $ uname -a
Linux tin.pi 3.18.0-trunk-rpi #1 PREEMPT Debian 3.18.5-1~exp1+rpi16 (2015-03-28) armv6l GNU/Linux
pi@tin ~ $ sudo apt-get install linux-headers-rpi-rpfv

 

  1. Since we will be compiling lot of stuff later, worth to preinstall all packages and libraries, to make sure dependency are met correctly.

 

apt-get install build-essential texinfo texi2html libcwidget-dev tcl8.4-dev tk8.4-dev libncurses5-dev libx11-dev binutils-dev bison flex libusb-1.0-0 libusb-dev libmpfr-dev libexpat1-dev tofrodos subversion autoconf automake libtool

 

  1. Now install linux-gpib itself. Enter home directory and run next:

 

root@tin:/home/# mkdir linux-gpib  
root@tin:/home/# cd linux-gpib
root@tin:/home/linux-gpib# svn checkout svn://svn.code.sf.net/p/linux-gpib/code/trunk linux-gpib-code
A    linux-gpib-code/linux-gpib
A    linux-gpib-code/linux-gpib/test
A    linux-gpib-code/linux-gpib/test/runtest
...
...
root@tin:/home/linux-gpib# cd linux-gpib-code/linux-gpib/

 

  1. At this moment we have latest linux-gpib from SVN and ready to configure and install it.

 

root@tin:/home/linux-gpib# cd linux-gpib-code/linux-gpib/
root@tin:/home/linux-gpib/linux-gpib-code/linux-gpib# ./bootstrap
libtoolize: putting auxiliary files in `.'.
libtoolize: copying file `./ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'
configure.ac:102: installing `./compile'
configure.ac:39: installing `./config.guess'
configure.ac:39: installing `./config.sub'
configure.ac:20: installing `./install-sh'
configure.ac:20: installing `./missing'
examples/Makefile.am: installing `./depcomp'
...
...

 

  1. linux-gpib is using kernel headers, which version must match our kernel version. So make sure those installed as well:

 

root@tin:/home/gpib/linux-gpib-3.2.21# apt-get install linux-headers-3.18.0
Reading package lists... Done
Building dependency tree
Reading state information... Done
...
...
The following NEW packages will be installed:
  linux-headers-3.18.0-trunk-all linux-headers-3.18.0-trunk-all-armhf
  linux-headers-3.18.0-trunk-rpi2
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 857 kB of archives.
After this operation, 6,807 kB of additional disk space will be used.
Do you want to continue [Y/n]? Y
...
...
Fetched 857 kB in 2s (365 kB/s)
Selecting previously unselected package linux-headers-3.18.0-trunk-rpi2.
(Reading database ... 97166 files and directories currently installed.)
Unpacking linux-headers-3.18.0-trunk-rpi2 (from .../linux-headers-3.18.0-trunk-rpi2_3.18.5-1~exp1+rpi16_armhf.deb) ...
Selecting previously unselected package linux-headers-3.18.0-trunk-all-armhf.
Unpacking linux-headers-3.18.0-trunk-all-armhf (from .../linux-headers-3.18.0-trunk-all-armhf_3.18.5-1~exp1+rpi16_armhf.deb) ...
Selecting previously unselected package linux-headers-3.18.0-trunk-all.
Unpacking linux-headers-3.18.0-trunk-all (from .../linux-headers-3.18.0-trunk-all_3.18.5-1~exp1+rpi16_armhf.deb) ...
Setting up linux-headers-3.18.0-trunk-rpi2 (3.18.5-1~exp1+rpi16) ...
Setting up linux-headers-3.18.0-trunk-all-armhf (3.18.5-1~exp1+rpi16) ...
Setting up linux-headers-3.18.0-trunk-all (3.18.5-1~exp1+rpi16) ...

 

  1. Now run ./configure in linux-gpib directory to prepare it for our system environment.

 

root@tin:/home/linux-gpib/linux-gpib-code/linux-gpib# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking build system type... armv6l-unknown-linux-gnueabihf
checking host system type... armv6l-unknown-linux-gnueabihf
checking Linux kernel directory... ok
checking Linux kernel compile flags... Makefile:10: *** mixed implicit and normal rules: deprecated syntax ok
checking for gcc... gcc

 

  1. Compile and install linux-gpib

 

root@tin:/home/gpib/linux-gpib-3.2.21# make
make  all-recursive
make[1]: Entering directory '/home/gpib/linux-gpib-3.2.21'
Making all in include
make[2]: Entering directory '/home/gpib/linux-gpib-3.2.21/include'
make  all-am
make[3]: Entering directory '/home/gpib/linux-gpib-3.2.21/include'
make[3]: Nothing to be done for 'all-am'.
...
...
root@tin:/home/gpib/linux-gpib-3.2.21# make install

Configuration for linux-gpib and interfacing

 

After everything successfully installed without errors, let’s connect GPIB-USB-HS adapter to Raspberry Pi and try to talk with it.

Make sure your Pi powered with good high-current USB cable and +5 VDC power supply with at least 1 Amp , as NI GPIB-USB-HS is taking some decent amount of power and with cheap USB cable connected to PC port it was causing unstable operation, LAN LEDs on Pi were blinking like crazy and nothing worked, as voltage drop too much.

Checking interface connection is simple, just run lsusb to see which devices are present on USB bus:

 

root@tin:/etc# lsusb
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 3923:709b National Instruments Corp. GPIB-USB-HS

 

Unlike old GPIB-USB-B, which need Cypress FX firmware upload after connection, GPIB-USB-HS does not need any firmware uploads and ready to work right from the box.
Let’s load kernel module with modprobe:

 

root@tin:/home/gpib/linux-gpib-3.2.21# modprobe ni_usb_gpib
root@tin:/home/gpib/linux-gpib-3.2.21#

 

Should be no error messages here. Can check if module was correctly used as well by lsmod.

 

root@tin:/home/gpib/linux-gpib-3.2.21# lsmod
Module                  Size  Used by
i2c_dev                 6970  0
i2c_bcm2708             5306  0
ni_usb_gpib            26063  0
gpib_common            31031  1 ni_usb_gpib

 

Modify /etc/gpib.conf like below:

 

board_type = "ni_usb_b">/* type of interface board being used */

 

Everything should be working well by now:

 

root@tin:/home/gpib/linux-gpib-3.2.21# gpib_config
root@tin:/home/gpib/linux-gpib-3.2.21# 

 

No errors, yey! Let’s test how it works now.

 

Testing GPIB operation

 

To test I had NI GPIB-USB-HS connected to Keithley 2002 bench digital multimeter. Instrument is configured with GPIB Address = 17.

 

root@tin:/# ibtest
Do you wish to open a (d)evice or an interface (b)oard?
        (you probably want to open a device): d
enter primary gpib address for device you wish to open [0-30]: 17
trying to open pad = 17 on /dev/gpib0 ...
You can:
        w(a)it for an event
        ...
        ...
        (r)ead string
        perform (s)erial poll (device only)
        change (t)imeout on io operations
        request ser(v)ice (board only)
        (w)rite data string
: w
enter a string to send to your device: *IDN?
sending string: *IDN?

gpib status is:
ibsta = 0x2100  < END CMPL >
iberr= 0

ibcnt = 6
You can:
        w(a)it for an event
        ...
        ...
        (r)ead string
        perform (s)erial poll (device only)
        change (t)imeout on io operations
        request ser(v)ice (board only)
        (w)rite data string
: r
enter maximum number of bytes to read [1024]: 1024
trying to read 1024 bytes from device...
received string: 'KEITHLEY INSTRUMENTS INC.,MODEL 2002,1167961,A09  /A02'
Number of bytes read: 57
gpib status is:
ibsta = 0x2100  < END CMPL >
iberr= 0

ibcnt = 57

 

Now can see data send/received correctly.

 

Python-application to talk GPIB from Raspberry Pi

 

Let's use fresh GPIB setup to talk with Python.

To use GPIB in Python we just need to do few steps here, install python-dev:

 

root@tin:/# apt-get install python-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  libssl-dev libssl-doc python2.7-dev
The following NEW packages will be installed:
  libssl-dev libssl-doc python-dev python2.7-dev
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 2,699 kB/31.4 MB of archives.
After this operation, 41.4 MB of additional disk space will be used.
Do you want to continue [Y/n]? Y
....
Setting up python2.7-dev (2.7.3-6+deb7u2) ...
Setting up python-dev (2.7.3-4+deb7u1) ...

 

Now we can install python egg to include Gpib module with our python system environment:

 

root@tin:/home/linux-gpib-code/linux-gpib/language/python# python ./setup.py  install
running install
running build
running build_py
creating build
creating build/lib.linux-armv6l-2.7
copying Gpib.py -> build/lib.linux-armv6l-2.7
running build_ext
building 'gpib' extension
creating build/temp.linux-armv6l-2.7
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I../../include -I/usr/include/python2.7 -c gpibinter.c -o build/temp.linux-armv6l-2.7/gpibinter.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-armv6l-2.7/gpibinter.o -L../../lib/.libs -lgpib -lpthread -o build/lib.linux-armv6l-2.7/gpib.so
running install_lib
copying build/lib.linux-armv6l-2.7/Gpib.py -> /usr/local/lib/python2.7/dist-packages
copying build/lib.linux-armv6l-2.7/gpib.so -> /usr/local/lib/python2.7/dist-packages
byte-compiling /usr/local/lib/python2.7/dist-packages/Gpib.py to Gpib.pyc
running install_egg_info
Writing /usr/local/lib/python2.7/dist-packages/gpib-1.0.egg-info

 

Simple Python test can help to check access, for multimeter sitting on GPIB bus with address 17. Test is simple sending IDN? request and reading back 100 bytes:

 

root@tin:/home/linux-gpib/linux-gpib-code/linux-gpib/language/python# python

Python 2.7.3 (default, Mar 18 2014, 05:13:23) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information.

>>> import Gpib

>>> inst = Gpib.Gpib(0,17) # Device address 17

>>> inst.write("*IDN?")

>>> inst.read(100) # read 100 bytes

'KEITHLEY INSTRUMENTS INC.,MODEL 2002,1167961,A09  /A02  \n'

>>>

 

Hope this article help to link your free Raspberry Pi with industry standard GPIB intruments. No need big bulky computer with Windows tied to it anymore!

 

image

 

I had this article hosted on own site as well, in case you want check latest version

  • Sign in to reply

Top Comments

  • Former Member
    Former Member over 9 years ago in reply to tin_xdevs +1
    Here https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=137781&p=918312#p918312 someone proposed using rpi-source to built the kernel headers (I'm no expert), but it did work. So to summarize, for…
  • Former Member
    Former Member over 9 years ago in reply to Former Member +1
    Okay, so it turns out "pip install pyvisa" and "pip install pyvisa-py" are enough. Everything works out of the box, the problems I had were related to the Keithley instrument, not the raspberry. (Just…
Parents
  • Former Member
    Former Member over 9 years ago

    Thank you very much for this detailed guide tin_xdevs image

    I have a question regarding the kernel headers though.

    Is there any way to use a more up-to-date version of the kernel?

     

    I have the "official" /inch touchscreen, and it doesn't properly work with the 3.18 kernel it seems (no touch input)

    Furthermore, my SPI pins stop working with the 3.18 kernel (I have a RPi B+)

    If I use a "normal" kernel, everything but GPIO works fine...

     

    Is there any way to get all of it to work at the same time?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • tin_xdevs
    tin_xdevs over 9 years ago in reply to Former Member

    I could not find kernel headers for newer version though. Not that experienced in linux, but I'll try.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 9 years ago in reply to tin_xdevs

    Here https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=137781&p=918312#p918312 someone proposed using rpi-source to built the kernel headers (I'm no expert), but it did work.

    So to summarize, for future reference: (I use an RPi B+, with an up to date raspbian jessie)

    - Use this https://github.com/notro/rpi-source to build kernel headers for current kernel (follow the example at  https://github.com/notro/rpi-source/wiki)

    - skip steps 2,3,4,5 of this here guide made by tin_xdevs (don't install old kernel and headers)

    - In step 6, I had to change the packages "tcl8.4-dev" and "tk8.4-dev" to "tcl-dev" and "tk-dev". Otherwise, apt-get wanted to uninstall python completely

    - After installing linux-gpib, I had some additional problems.

    - I had to run "sudo ldconfig" to link some of the newly installed libraries

    - only then does "sudo gpib_config" work for me (has to be run as root for me. even tough I added the user to the gpib group ("sudo usermod -a -G gpib pi")

    - I also have to run "sudo gpib_config" after every reboot, does somebody know how to change that?

    - After that, running "ibtest" works fine, and I can communicate with a Keithley 2400 sourcemeter (so far I only tried *IDN?)

    - Now I am stuck at the step of getting pyvisa https://pyvisa.readthedocs.org/en/stable/ and pyvisa-py https://pyvisa-py.readthedocs.org/en/latest/ to work.

     

    If anyone is able to get that to work, please do tell. :-)

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 9 years ago in reply to Former Member

    Okay, so it turns out "pip install pyvisa" and "pip install pyvisa-py" are enough.

    Everything works out of the box, the problems I had were related to the Keithley instrument, not the raspberry. (Just for completeness: Some Keithley devices support two protocols, "SCPI" and "488.1". Make sure "SCPI" is selected)

    I still have to run "sudo gpib_config" after rebooting, but the rest works.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • tin_xdevs
    tin_xdevs over 9 years ago in reply to Former Member

    I updated article, your method working just fine.

    Actually had some issues running long GPIB datalogs (over a day) having GPIB errors and aborts, which get fixed only by unplug/plug of NI GPIB-USB-HS. Maybe new kernel will fix it.. Will see.

     

    Thanks!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • khanalb
    khanalb over 6 years ago in reply to Former Member

    I followed your steps with kernel 4.14.98-v7+ on rpi 3B. Everything went well without error except that I could not run gpib_config is not working for me. I am getting 'failed to open device file:/dev/gpib0 no such file or directory exists' do you have any suggestion?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • khanalb
    khanalb over 6 years ago in reply to Former Member

    I followed your steps with kernel 4.14.98-v7+ on rpi 3B. Everything went well without error except that I could not run gpib_config is not working for me. I am getting 'failed to open device file:/dev/gpib0 no such file or directory exists' do you have any suggestion?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube