Example Code

Raspberry Pi Pico Python and LabVIEW Drivers

Code and Documents

Attachment

Download All

Description

Overview

 

A sample framework for LabVIEW control of a Raspberry Pi Pico.

 

The Pico module is a very inexpensive, only costing a few pounds, and can run Python. It includes a large amount of digital IO and has Python routines for SPI and I2C. Connection to the computer is via USB.

 

Using the Raspberry Pi Pico test fixtures and device controllers can be produced/tested/updated very quickly, and can be controlled by Windows, Mac and Linux.

 

Description

 

Attached is some example code, the Python "main.py" to be placed on the Pico module, plus LabVIEW VIs for communicating with the Pico.

 

The "main.py" Python code is loaded onto the Pico module using Thonny and when run it provides a command prompt where it can be sent commands in plain ASCII text. Some example commands are included, such as a SPI command for communicating with SPI devices. Using a simple text based command line interface allows the added functions to be run and tested from Thonny or any terminal emulator such as Tera Term, Putty etc.

 

The main LabVIEW routine, "RPiPico - Talk USB.vi", is used to communicate with the Pico device. It looks for a command prompt, and if seen it sends the required command and receives the reply. If the Pico module is in the incorrect mode then control characters are sent to reset/reboot the Pico module and start it running "main.py" again. Also included in the example code are LabVIEW routines for running the individual commands and processing their replies.

 

One use of this code is for the creation of simple test fixtures for use within automated test systems. Included in the code is a function for writing a fixture title to the Pico file system and having the main.py code setup various port functions on startup as required.

 

Hardware and Software Requirements

 

LabVIEW, Raspberry Pi Pico, Thonny.

 

If using the Pico for SPI/I2C I would suggest using SPI and I2C isolators to allow the control of 3V3 and 5V devices and protect the computer and Pico from any damage from higher voltages.

 

Steps to Implement or Execute Code

 

Thonny should be used to prepare the Pico module and to save the "main.py" code to the Pico. The Pico module will auomatically run main.py every time it is started up.

 

On a Mac NI Max should be used to provide the Pico module with a device alias/address the LabVIEW code can use for communication.

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

Comments
Wazig
Member
Member
on

Hello Antony,

 

Nice example of LabView use with RPi Pico !

 

Can you please make this code available for LabView V21 or lower...

(we don't like to upgrade to LV22/23 due to the yearly extreme costs of LabView....)

antony.g
Member
Member
on

Sorry, I didn't see your request until today. I have just uploaded a LabVIEW 2016 version.

hahaman
Member
Member
on

Could you please do it one more time for LabVIEW 2015 version?

Many Thanks in advance!

antony.g
Member
Member
on

Just added a LabVIEW 2014 version.

Contributors