Example Code

Raspberry Pico with USBTMC and SCPI and LabVIEW driver

    Other

  • firmware, hardware, driver

Code and Documents

Third-Party Code Repository

Some users manage their code in repositories outside of ni.com. Use your best judgment when following links to third-party sites. https://github.com/jancumps/pico_scpi_labtool_labview_driver/releases/

Description

Firmware for Raspberry Pico that turns it into a SCPI instrument. 

  • SCPI
  • USBTMC
  • LabVIEW instrument driver
  • Instrument Specific registers
  • Service Requests

 

The project has C library, that handles the support for SCPI and usbtmc. An example application runs on a Pico without additional hardware and supports analog in-out and digital in-out.

mceclip0.png

How to Use

Pre-build firmware is available on github. There's a LabVIEW driver block for the major functions. Advanced functionality (instrument specific registers, service requests) are available via the typical SCPI constructs for them

Command reference

This section describes the supported (and not yet supported) commands. It lists

  • the SCPI syntax,
  • LabVIEW Virtual Instrument driver block
  • the pins that are used,
  • parameters, return values.

set digital output

drive digital output pin of PICO high or low

pins:

0: GP22
1: GP14
2: GP15

SCPI DIGItal:OUTPut# <0|1>

example: DIGI:OUTP0 1

#: pin
parameter 1: boolean (0|1 or OFF|ON )
return: na

VI

Public/Action-Status/Digital Out Control

image

inputs:
pin (int)
state (bool)
outputs:
na

 

 

 

get digital output query the state of a digital output

pins:

0: GP22
1: GP14
2: GP15

SCPI DIGItal:OUTPut#?

example: DIGI:OUTP0?

#: pin
return: state (bool 0|1)

VI

Public/Data/Read Digital Out

image

inputs:
pin (int)
outputs:
state (bool 0|1)
 

 

 

get digital input

query the state of a digital input

pins:

0: GP20
1: GP21
2: GP27

SCPI DIGItal:INPut#?

example: DIGI:INP0?

#: pin
return: state (bool 0|1)

VI

Public/Data/Read Digital In

image

inputs:
pin (int)
outputs:
state (bool 0|1)

 

 

 

get analogue input (standard) query an ADC input of the Pico

pins:

0: GP26 (ADC0)
1: GP28 (ADC2)

SCPI ANAlog:INPut#:RAW?

example: ANA:INP0:RAW?

#: pin
return: ADC value(integer 0-4095)

VI

Public/Data/Read Analog

image

inputs:
pin (int)
outputs:
ADC value (integer 0-4095)

 

 

 

get analog input (high resolution) query an input of attached ADS1115 ADC

pins:

ADS1115 pin 0 - 3
developed by  !
See the Extensions section below for hardware requirements.

SCPI ANAlog:HIRES:INPut#:RAW? #: pin
return: ADC value(integer 0-32766)
VI

Public/Data/Read Analog HiRes

image

inputs:
pin (int)
outputs:
ADC value (integer 0-32766)

 

 

 

set analog output control pin of Pico with variable duty cicle

pins:

0: GP16
1: GP17
2: GP18
developed by  

SCPI ANAlog:OUTPut#:RAW <0-4095> inputs:
pin (int)
Duty cycle value (integer 0-4095)
outputs:
na
VI

Public/Action-Status/Analog Out Control

image

inputs:
pin (int)
duty cycle (integer 0-4095)
outputs:
na

 

 

 

get analog output query the set duty cycle set on a pin of Pico

pins:

0: GP16
1: GP17
2: GP18
developed by  

SCPI ANAlog:OUTPut#:RAW? inputs:
pin (int)
outputs:
Duty cycle value (integer 0-4095)
VI

Public/Data/Read Analog Out

image

inputs:
pin (int)
outputs:
duty cycle (integer 0-4095)

 

 

 

init resource initiate connection VISA url: USB0::0xCAFE::0x4000::123456::INSTR
SCPI na, connect via VISA API client dependent
VI

Public/Initialize

image

inputs:
VISA url
outputs:
na

 

 

 

close resource release connection  
SCPI na, disconnect via VISA API client dependent
VI

Public/Close

image

inputs:
na
outputs:
na

 

Command reference: instrument specific registers

This section describes the supported (and not yet supported) commands. It lists

  • the SCPI syntax,
  • registers and bits that are used,
digital input registers query the registers of a digital input, set filter and fan-out to IEEE488.2 Operation Status register

bits:

0: GP20
1: GP21
2: GP27

 

registers:

CONDition
PTRansition
NTRansition
EVENt
ENABle

fan-out to IEEE488.2:

Operation Status[0]

SCPI STATus:OPERation:DIGItal:INPut:CONDition?
STATus:OPERation:DIGItal:INPut:PTRansition
STATus:OPERation:DIGItal:INPut:PTRansition?
STATus:OPERation:DIGItal:INPut:NTRansition
STATus:OPERation:DIGItal:INPut:NTRansition?
STATus:OPERation:DIGItal:INPut:EVENt?
STATus:OPERation:DIGItal:INPut:ENABle
STATus:OPERation:DIGItal:INPut:ENABle?

 

 

 

 

Simple Example 

VI read analogue pin

image image

Related Links

Documentation on element 14: Program the Pico SCPI labTool

Firmware (code and binary) and drivers available on github: The release has all you need to get started. The firmware contains the binary .uf2 that you can copy on your Pico. The LabVIEW VI Driver contains examples that you can run right away.

software latest release (source and bin) development branch (source)
Pico Firmware github release github branch
LabVIEW Virtual Instrument driver with examples github release github branch

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
jancumps
Member
Member
on

images showed when entering the text. I tried to edit and fix the images, but have no rights to edit the post.