infinite quanta, inc., a 501(c)(3) NonProfit Scientific Research Organization Home Page The Peptide Reseach Project Our Organization Our Associates Collaboration News & Events [ Log In | Sign Up | Lost password? ]

GPIB on the Raspberry

Saturday, January 09, 2021 - GPIB is a bus system for connecting instruments together with computers. Integrating GPIB for the Raspberry is a necessary step for communicating with legacy and some modern scientific instruments.

The Raspberry Pi (RPi) has GPIO, USB, and ethernet built onto its motherboard to connect to external devices and instruments. Most legacy and some modern instruments still connect to computers through GPIB, short for General Purpose Interface Bus, cabling and protocols, designed under the IEEE-488 standard. The other connection and communication protocols will be covered under VISA on the Raspberry.

To setup GPIB on the RPi, its going to connect through the USB port of the Raspberry to an GPIB dongle, such as the National Instruments GPIB-USB-HS dongle. It's probably the most stable but also expensive hardware interfaces out there. The Linux Raspbian kernel will need to be recompiled to include the GPIB interfacing and protocols into the OS. The most direct recipe for this process is at:, and is stated here as the ultimate reference and trouble shooting guide. I will be recreating the essential commands from the latter link and report on the progress below for a Raspberry 4 with its native Raspbian Linux, kernel version 5.10, and Python 3.7. The NI-GPIB-USB-HS is shown:

You'll only need to have a single GPIB-to-USB dongle for the bus will allow multiple instruments connected to the GPIB with only GPIB-to-GPIB cabling after the dongle. Setting up the RPi with Raspbian is cover under my blog at: The Raspberry Pi (RPi)

Before getting under way, here is the Linux kernel version under BASH CLI:

> uname -a
Linux IQaRPi4a8GB 5.10.17-v7l+ #1403 SMP Mon Feb 22 11:33:35 GMT 2021 armv7l GNU/Linux

or kernel version 5.10. And then run:

> apt-get update
> apt-get upgrade -y
> reboot now

then download kernel headers, install certain packages, update gcc and g++, and then make the kernel headers:

> wget -O /usr/bin/rpi-source
> cd /usr/bin/
> chmod +x rpi-source
> /usr/bin/rpi-source -q --tag-update
> apt-get install -y bc bison
> apt-get install -y tk-dev build-essential texinfo texi2html libcwidget-dev libncurses5-dev libx11-dev binutils-dev bison flex libusb-1.0-0 libusb-dev libmpfr-dev libexpat1-dev tofrodos subversion autoconf automake libtool mercurial
> gcc --version
gcc (Raspbian 8.3.0-6+rpi1) 8.3.0
> apt-get install -y gcc-4.9 g++-4.9
> update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 50
> update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 50
> gcc --version
gcc (Raspbian 4.9.4-2+rpi1+b19) 4.9.4
> update-alternatives --config gcc
> rpi-source
> reboot now

where "rpi-source" will create the "/root/linux-*hashed_out*.tar.gz file and associated directory and symbolic links. The following downloads the GPIB source and compiles and install it. I disagree with Illya Tsemenko in that, I've had difficulty with the SVN download source and instead download it directly from the source manager for the GPIB source code, the page at: Linux GPIB Package, or the source code at: Linux GPIB Versions.

> cd ~
> mkdir -p install/GPIB
> cd install/GPIB
> wget
> tar -xzvf linux-gpib-4.3.4.tar.gz
> ln -s linux-gpib-4.3.4.tar.gz linux-gpib
> cd linux-gpib
> tar -xzvf linux-gpib-kernel-4.3.4.tar.gz
> ln -s linux-gpib-kernel-4.3.4 kernel
> tar -xzvf linux-gpib-user-4.3.4.tar.gz
> ln -s linux-gpib-user-4.3.4 user
> cd kernel
> make
> make install
> cd ../user
> ./bootstrap
> ./configure
> make
> make install
> nano /usr/local/etc/gpib.conf
# and edit the line under "interface" from 'board_type = "ni_pci"' to 'board_type = "ni_usb_b"'
>> Ctrl-X, Save? >> Y, Enter 
> reboot now

Make sure your Pi powered with good short high-current USB cable and +5 VDC power supply with at least 2 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.

> lsusb
.. .
Bus 001 Device 008: ID 3923:709b National Instruments Corp. GPIB-USB-HS
.. .
> lsmod | grep ni
ni_usb_gpib            40960  0
gpib_common            49152  2 lpvo_usb_gpib,ni_usb_gpib
.. .
> ldconfig
> gpib_config
> nano /etc/rc.local
#before "exit 0" add:
chgrp gpio /dev/gpib*
chmod g+rw /dev/gpib*
>> Ctrl-X, Save? >> Y, Enter 
> reboot now

where the last two lines ensure that user "pi" or any user to the group "gpio" have access to the GPIB device, especially when accessing it through python3.

At this point the GPIB should be working within the RPi. Running "ibtest" will confirm that the bus is working properly. Have a GPIB device connected and ready to send/receive GPIB commands, then:

> 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]:
>> 8
trying to open pad = 8 on /dev/gpib0 ...
You can:
.. .
>> w
enter a string to send to your device:
>> *IDN?
sending string: *IDN?
.. .
You can:
.. .
>> r
enter maximum number of bytes to read [1024]:
>> 100
trying to read 100 bytes from device...
received string: 'Stanford_Research_Systems,SR830,s/n81963,ver1.07 
Number of bytes read: 50
.. .
>> quit

where the instrument's ID is properly read from the device. That confirms the GPIB communications are all working. Almost there. Now the Python libraries have to be installed. The target here is Python 3.

> apt-get install -y python3-dev
> cd ~/install/GPIB/linux-gpib/user/language/python
> python3 ./ install
running install
running build
running build_py
running build_ext
running install_lib
running install_egg_info
Writing /usr/local/lib/python3.7/dist-packages/gpib-1.0.egg-info
> python3
Python 3.7.3 (default, Jan 22 2021, 20:04:44) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>> import Gpib
>> sr = Gpib.Gpib(0, 8)
>> sr.write('*idn?')
>> r =
>> r
b'Stanford_Research_Systems,SR830,s/n81963,ver1.07 \n'
>> Ctrl-D
>reboot now

OR, the following file can be added, under user "pi":

> nano
#!/usr/bin/env python3
import Gpib
sr = Gpib.Gpib(0, 8)
r =
print('"%s"' % r.decode('utf-8').replace('\n', '').strip().split(','))
>> Ctrl-X, Save? >> Y, Enter 
> chmod +x
> ./
"['Stanford_Research_Systems', 'SR830', 's/n81963', 'ver1.07']"

And that should do it. The completed task and there should be full GPIB communications between the RPi and any of your GPIB legacy instruments. The rest is up to you and your Python 3 prowess.

Please Register / Login here to post or edit comments or questions to our blog.

Back to the Main Blog Page