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
NI LabVIEW Community
  • Products
  • Dev Tools
  • NI LabVIEW Community
  • More
  • Cancel
NI LabVIEW Community
LabVIEW Challenge Blogs Building Custom firmware for led control on Pi Pico using Labview
  • Blog
  • LabVIEW Challenge Blogs
  • Forum
  • Documents
  • Quiz
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join NI LabVIEW Community to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: cbohra00627
  • Date Created: 3 Nov 2023 4:45 PM Date Created
  • Views 669 views
  • Likes 4 likes
  • Comments 0 comments
  • labview 2023
  • pico and labview
  • pico
  • LAbVIEW challenge
  • labview
  • scpi
Related
Recommended

Building Custom firmware for led control on Pi Pico using Labview

cbohra00627
cbohra00627
3 Nov 2023

Introduction:

This blog is not part of the actual project. This is something I came across while learning labview with pi pico. So, I wanted to share it.

In this blog, I will share the steps I followed to create a custom pi pico firmware image with a custom SCPI command to enable led control on the pico.

The Prerequisites are:

  • pico sdk must be installed
  • pico_scpi_usbtmc_labtool must be cloned
  • pico_scpi_labtool_labview_driver should be cloned
  • pi pico must be setup

You can follow this blog to setup your pi pico with labview.

Building custom Firmware:

I went through the blink example in pico-sdk & the gpio_utils.c & gpio_utils.h files in the pico_scpi_usbtmc_labtool repo to understand how the led can be accessed. In the blink example, there is a function gpio_put which is being used to control the led.

The same function I have to use in pico_scpi_usbtmc_labtool and create a firmware image from it.

So, inside the pico_scpi_usbtmc_labtool/source folder, I created a new folder led and created two files led_utils.c & led_utils.h inside that.

led_utils.c:

#include "hardware/gpio.h"
#include "led_utils.h"

void initLED() {
    gpio_init(PICO_DEFAULT_LED_PIN);
    gpio_set_dir(PICO_DEFAULT_LED_PIN, true);
}

void setLED(uint32_t led_pin, bool on) {
    gpio_put(led_pin, on);
}

scpi_result_t SCPI_LEDOutput(scpi_t * context) {
  const uint32_t LED_PIN = PICO_DEFAULT_LED_PIN;
  scpi_bool_t param1;

  /* read first parameter if present */
  if (!SCPI_ParamBool(context, &param1, TRUE)) {
    return SCPI_RES_ERR;
  }

  setLED(LED_PIN, param1 ? true : false);

  return SCPI_RES_OK;

}

initLED() - To initialize the LED

setLED() - To turn the LED on/off

SCPI_LEDOutput() - Gets called whenever a particular SCPI command is called. Based on the value of the parameter with the SCPI command, it will turn on/off the LED.

led_utils.h:

#ifndef _LED_UTILS_H
#define _LED_UTILS_H

#include "scpi/scpi.h"

#define INSTRUMENT_LED_OUTP_COMMANDS \
    {.pattern = "LED:OUTPut", .callback = SCPI_LEDOutput,},

void initLED();

void setLED(uint32_t index, bool on);

scpi_result_t SCPI_LEDOutput(scpi_t * context);

#endif // _LED_UTILS_H

Contains function declarations and a macro that combines a SCPI command pattern with a function callback.

Now we add this macro to the SCPI command list in the file: pico_scpi_usbtmc_labtool/source/scpi/scpi-def.c

image

And add the initLED() function in the initInstrument() function in the same file.

image

Include the led_utils.h file in the same file.

image

Now in the pico_scpi_usbtmc_labtool/CMakeLists.txt file, add the led_utils.c file as an executable and the led folder as the target directory.
imageimage

Now build the project (follow this blog for build process) and load the .uf2 file generated onto the pico.

Making a VI:

We can create the VI similar to the digital out VI. The only difference will be the SCPI command string (Keep it in mind to connect this command string to the "format string" port of the format into string block and not to the initial string port. See this issue). Now, we can add this SubVI to other VIs and control the pico LED.
image

Controlling LED:

Now we can control the pico LED with the below VI.

image

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

The pico led is used by the USB code also. So, its not advised to use it for general purposes, but for demonstration, I have used it here.

  • Sign in to reply
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