element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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
Test & Tools
  • Technologies
  • More
Test & Tools
Blog PST.. Have you worked with the Pico SCPI labTool?
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Test & Tools to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: shabaz
  • Date Created: 5 Aug 2023 12:54 AM Date Created
  • Views 4531 views
  • Likes 12 likes
  • Comments 25 comments
  • pico_usbtmc_scpi
  • pico
  • USBTMC
  • Pico SCPI labTool
  • labview
  • scpi
  • PST
  • pyvisa
Related
Recommended

PST.. Have you worked with the Pico SCPI labTool?

shabaz
shabaz
5 Aug 2023

Table of Contents

  • Introduction
  • How Does it Work?
  • What is Needed?
  • Setting up the PC
  • Download a SCPI Library
  • Create a replica of Pico SCPI labTool in your own GitHub Repository
  • Download the Pico SCPI labTool Project to your PC
  • Building the Code
  • Upload the Firmware to the Pi Pico
  • Using It
  • Next Steps
  • Summary

Introduction

The Pico SCPI labTool developed by Jan Cumps  allows you to connect your PC to equipment to control and monitor all sorts of things. The project grew from a series of blog posts beginning with this one: Pico SCPI Lab Switch project: automate your test setup with a standards compliant multi-channel switch   

As an example, if you have relays that need to be controlled, the Pico SCPI labTool’s general-purpose input/outputs (GPIO) can be wired up to them, and then you can issue a simple text command from your PC, all under remote control (for instance, using the USB connection).

image

The diagram above shows how it is used – it’s very straightforward. The Pico’s USB connection is plugged into a PC, and you can run software to switch things on or off, or to chart measurements, and so on. The PC sends instructions and receives responses from the Pi Pico. The Pico is physically attached to the hardware.

The underlying instructions and responses are in a standard text format, meaning software such as LabView and MATLAB can interface it all! Python can also be used.

One advantage of this solution is that even if you’re unfamiliar with coding, that’s OK! With some of the software tools this project is compatible with, minimal actual coding can be needed to begin interacting with hardware.

I was keen to explore the project and see what it could be used for. This blog post simply discusses how to get going with it.

How Does it Work?

The solution makes use of several technologies. In particular, a text form of instructions and responses called Standard Commands for Programmable Instruments (SCPI) is used. With SCPI, if you wished to set a particular GPIO pin to a logic level high, you’d type something like:

DIGI:OUTP0 1

The first part merely indicates that a command related to digital functionality is to follow. The next part narrows it down to output #0. The final part indicates that the output should be set to logic 1 (high).

The text command is sent over USB using a standard USB Test and Measurement Class (USBTMC) method. At the Pi Pico end, the SCPI content is extracted from the message and processed by the Pico SCPI labTool code. The code then instructs the appropriate GPIO to go high.

image

A great benefit of using SCPI and USBTMC is that it plugs in nicely with something known as Virtual Instrument Software Architecture (VISA), at the PC end of the solution. The VISA software can connect to various hardware, including USB devices running USBTMC. The VISA Resource Manager allows access to all the hardware devices regardless of the interface type, so that the user app running on the PC doesn’t need to concern itself with direct USB or Ethernet communication and so on.

For instance, if you plug in a supported device into the network, the VISA Resource Manager will provide access to it using an identifier (known as a VISA Resource Name) such as TCPIP0::0xAABB::DMM1000::60232::INSTR whereas if you plug in the Pico SCPI labTool into your PC, the VISA Resource Name might be USB::0xCAFE::0x4000::123456::INSTR. The connecting user application doesn’t need to care whether the device is Ethernet or USB connected, although the first part of the VISA Resource Name does specify that. The rest of the string contains the manufacturer identifier (0xCAFE), model identifier (0x4000), and product serial number (123456). The final part merely specifies that instrument control resources will be accessible with that VISA Resource Name.

If you were using Python on your PC to control the digital output, it would be easy. The following lines would achieve the result of setting an output high.

import pyvisa
rm = pyvisa.ResourceManager()
pst_instrument = rm.open_resource("USB0::0xCAFE::0x4000::123456::INSTR");
level=1;
pst_instrument.write(f"DIGI:OUTP0 {level}")
pst_instrument.close()

If you wanted to blink a LED connected to the output, you could insert this snippet of code:

import time
while True:
  pst_instrument.write(f"DIGI:OUTP0 {level}")
  level ^= 1
  time.sleep(0.5)

Each of the .write() commands in the code above would result in the SCPI text instruction being delivered over USBTMC, through the USB connection, into the Pi Pico, where the Pico SCPI labTool (PST) software would decode it and then send the GPIO control instruction to a particular pin.

By editing the PST code, you could add new commands, such as (say) ANA:INP to obtain analog input from an ADC so that you could plot the measurements on the PC.

What is Needed?

Absolutely nothing is needed apart from a Pi Pico ! For a quick test, I soldered an LED onto pin 29 (which is GPIO 22) with the other end connect to ground through a 220 ohm resistor. That is sufficient to initially experiment with the Pico SCPI labTool, because you can issue DIGI:OUTP commands to turn the LED on and off.

Note that for future use, it would be good to get two Pico boards, because you can configure one to become a PicoProbe, which will allow you to develop software for the Pico super-fast. Alternatively, you could build a Pico-EuroCard which contains a built-in PicoProbe. In any case, all that is unessential for this blog post; as mentioned, you just need a Pi Pico. 

The rest of this blog discusses how to set up the PC to build the Pico SCPI labTool firmware, and how to start using it.

Setting up the PC

The key thing that is required is the Pi Pico SDK. However, I like using an integrated development environment (IDE) called CLion, so I installed that too. CLion is free for 30 days, and after that is available at low cost to individuals (£79 + tax for a perpetual license, but there are also significant discounts – so it is worth checking if you qualify). If you don’t wish to use CLion, then Visual Code can be used. I think these two are amongst the best development environments available today; they are both extremely feature-rich. If you do try them both, I’d be interested to hear about your comparison.

To set up the PC for Pi Pico SDK and CLion development, follow the information here:  Using CLion for Easier Coding with Pi Pico and C/C++  


To set up the PC for Pi Pico SDK and Visual Code based development, you could follow the information at this link (I have not tried this).


Now that the PC is set up, you can work through the following tasks. All of these tasks are very quick; you can be complete in 15 minutes or less!

Note that if you don’t have a GitHub account, it is highly recommended to create one, and the tasks make use of your account. The reason is, that if you’re planning to use the PST, then you’re likely to want to make code enhancements to it over time, as you extend its capabilities. That is easiest to achieve if you have a GitHub account so that you have your own repository to make changes in, before submitting them to be merged into the original repository so that everyone can benefit from them. If you don't create a GitHub account, then you cannot do the step below containing a fork operation, and it will also mean you won't be able to follow the steps in future PST blog posts easily either, which rely on this step having occurred.

Once you have a GitHub account, proceed with the following steps! I used Windows, but all the steps will work with Linux too.

image

Download the scpi-parser Library

The Pico SCPI labTool requires a particular SCPI code library as a pre-requisite. You can either download the library and extract it, or you can use a Windows terminal (PowerShell) to download it automatically. It’s known as a clone operation in Git terminology.

I created a folder called C:\development\scpi and then typed the following in that folder using PowerShell:

git clone https://github.com/j123b567/scpi-parser.git

image

That’s it; this step is complete!

Create a replica of Pico SCPI labTool in your own GitHub Repository

Go to the Pico SCPI labTool GitHub project page, and click as shown below to fork the project! The fork action creates a replica of the entire project into your own GitHub account, so that you have your own repository of it.

image

Make sure you uncheck the box shown below before clicking on Create Fork.

image

Now a copy of the project will be visible in your GitHub account, for instance, I did the same thing:  https://github.com/shabaz123/pico_scpi_usbtmc_labtool  

Download the Pico SCPI labTool Project to your PC

This step creates a local copy of the files onto your PC, known as a clone operation. You could do this from the command line in a similar method as shown earlier. If you’re using CLion, then it’s easy directly from within the software. Once you start up CLion, click on Get from VCS on the main Welcome page:

image

From there, you can click on GitHub, and select the project from the list. Make sure the Directory box is set as you desire. In my case, I put all my Pi Pico projects into a C:\development\pico folder.

image

The next screen is super-important. One box needs filling in, and nothing else needs to be changed from the defaults. Type the following into the Environment box (note: it’s very important to use forward-slashes as shown, for at least the SCPI_LAB_PATH):

PICO_SDK_PATH=c:\development\pico\pico-sdk;SCPI_LIB_PATH=C:/development/scpi/scpi-parser/libscpi

image

Now the project will be loaded into CLion!

image

The yellow pop-up message in the screenshot above is OK.

Building the Code

This is a one-click task. Click on the hammer icon!

image

The folder shown in the screenshot below will contain the binary executable file you need:

image


Upload the Firmware to the Pi Pico

There’s a little button on the Pi Pico (it’s the only button on it). Holding it down, plug the Pico’s USB connector into the PC. Wait a couple of seconds, and then release the button.

A file explorer window will appear, i.e. the Pi Pico will look like a storage drive to the PC. You can drag-and-drop the .uf2 file into this window. Within seconds, the firmware will be installed.

Using It

The Pico SCPI labTool (PST) is quick. I plugged the USB connector from the Pi Pico into the PC, and it was detected by the driver software before I’d even let go of the plug!

image

I happened to have Tektronix software installed, which includes VISA code, and it can access instruments. I clicked on the software and it allowed me to type SCPI instructions, and see the results!

image

Of course, Tektronix software is not necessary. You could install VISA directly from the National Instruments website. 

Now you’re ready to try it out!

If you installed the NI software, then use a supplied tool called VISA Interactive Control, and select the PST as shown here, and double-click it:

image

A new window will open. Click on Input/Output and then type the following (it may be present as the default on startup anyway, in which case you don't need to type it!) and then press the button labeled Query:

*IDN?\n

You should see a response containing the text PICO-PI,LABTOOL.

image

Note: The NI Visa Interactive Control will require the user to type \n on the end of each command, whereas some tools such as the Tektronix one doesn't require that.

Now try typing DIGI:OUTP0 1 (followed by \n if you're using the NI Visa Interactive Control) and press the button labeled Write. If you have an LED soldered to GPIO 22 (pin 29) on the Pi Pico, it should light up!

If you have Python installed on the PC, then try out these example lines of code, which are the same as that shown in the introduction:

import pyvisa
rm = pyvisa.ResourceManager()
pst_instrument = rm.open_resource("USB0::0xCAFE::0x4000::123456::INSTR");
level=1;
pst_instrument.write(f"DIGI:OUTP0 {level}")
pst_instrument.close()

If you're using Matlab, then the following example code may be helpful. Note that this is using syntax that is backward compatible with older releases, but is deprecated; the visa object is replaced with visadev, and the older commands may be removed in future Matlab releases, although it works today.

pst1_resourcename = 'USB0::0xCAFE::0x4000::E66118604B727B22::0::INSTR';
pst1 = instrfind('Type', 'visa-usb', 'RsrcName', pst1_resourcename, 'Tag', '');
if isempty(pst1) % Create if it didn't exist
  pst1 = visa('NI', pst1_resourcename);
else
  fclose(pst1);
  pst1 = pst1(1);
end
fopen(pst1);
set(pst1, 'EOSCharCode', 'LF'); % use 0x0a aka \n aka line feed
set(pst1, 'EOSMode', 'read&write'); % use that code for read and write!
% ok send some stuff
identity = query(pst1, '*IDN?'); % do a *IDN? query
fprintf(pst1, 'DIGI:OUTP0 1'); % set output #0 (GPIO22) high
input_level = str2num(query(pst1, 'DIGI:INP2?')); % get input #2 (GPIO27) value

Next Steps

Now that the Pico SCPI labTool is installed on the Pi Pico, and you know how to build the code, modifying it to add new features should be possible. On the PC side, you may wish to install NI LabVIEW or MATLAB, or you may wish to continue with Python. There are many other options, too; it would be great to hear about how people use the PST project.

Summary

The Pico SCPI labTool has enormous potential. It is easy to install and use, and the fact that it runs standard protocols means it can be directly interfaced with Python, LabVIEW, and MATLAB. Multiple PST devices could be controlled, in conjunction with off-the-shelf lab instruments such as oscilloscopes and bench multimeters, to build automated solutions or to capture or control devices that would ordinarily not interface to a PC easily. The PST is ultra-low-cost yet is extremely powerful.

As mentioned earlier, it will be interesting to see how people use it.

Thanks for reading!

  • Sign in to reply

Top Comments

  • flyingbean
    flyingbean over 1 year ago in reply to shabaz +1
    Yes. I gave up to use my main Windows PC for this Pico instrument project group since I tied it with many valuable licenses. So I took one of my spare laptops and installed Window 10 from fresh start.…
  • ggabe
    ggabe over 1 year ago +1
    To build the firmware with zero local tool installation on your own computer I made a git builder that posts the firmware on git after each commit. The "magic" is in this file: https://github.com/u77345…
  • shabaz
    shabaz over 1 year ago

    After lots of troubleshooting with Jan Cumps  we got to the bottom of why Matlab didn't play nice with PST. It turns out that (at least my version of Matlab, which is not up-to-date), the Matlab defaults for line termination insertion are bad or are broken. The 'scan' feature in the instrument control toolbox might not work if you have an older buggy version of Matlab. It's not a big deal, since the workaround is to not do a scan (or to reboot the PST after a scan), or simply use a more recent release of Matlab.

    The following code shows how to set outputs and read inputs, and works with older and current Matlab releases.

    The visa object is deprecated and will be removed in a future release of Matlab; the newer visadev object is the replacement.

    However, the code below should work with older releases as well as the current ones. I've added this example to the body of the blog too.

    pst1_resourcename = 'USB0::0xCAFE::0x4000::E66118604B727B22::0::INSTR';
    pst1 = instrfind('Type', 'visa-usb', 'RsrcName', pst1_resourcename, 'Tag', '');
    if isempty(pst1) % Create if it didn't exist
        pst1 = visa('NI', pst1_resourcename);
    else
        fclose(pst1);
        pst1 = pst1(1);
    end
    fopen(pst1);
    set(pst1, 'EOSCharCode', 'LF'); % use 0x0a aka \n aka line feed 
    set(pst1, 'EOSMode', 'read&write'); % use that code for read and write!
    % ok send some stuff
    identity = query(pst1, '*IDN?'); % do a *IDN? query
    fprintf(pst1, 'DIGI:OUTP0 1'); % set output #0 (GPIO22) high
    input_level = str2num(query(pst1, 'DIGI:INP2?')); % get input #2 (GPIO27) value

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago in reply to TRLA

    TRLA , untested 2018 export

    usbtmc_scpi_labtool 2018.zip

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • TRLA
    TRLA over 1 year ago in reply to TRLA

    image

    Unfortunately, 

    It won't work in 2018

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago in reply to ggabe

    ggabe , I've used part of that work in the PST - next to your Service Request solution - and learned some new things from that magic.

    I've taken over your idea to add the SCPI-LIB as a submodule and adapt the build for that.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • TRLA
    TRLA over 1 year ago in reply to Jan Cumps

    Thanks Jan. I should have just said 2018. My work computer has 20 and I am not allowed to use it for personal use. This will help someone who has 20 though, so many thanks.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
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