Skip to content

LABOPlatform Library

If you want to quickly incorporate pico-jxglib's functionalities into your project, you can use the jxglib_LABOPlatform library. This library combines multiple libraries of pico-jxglib, providing functionalities useful for the development of Pico projects. pico-jxgLABO is a ready-to-flash UF2 Binary that uses the jxglib_LABOPlatform library, making it a great way to quickly see the functionalities of the library in action. See here for how to flash and use pico-jxgLABO.

Building and Flashing the Program

Create a new Pico SDK project named your-project.

Create Pico SDK Project
  1. In VSCode, run >Raspberry Pi Pico: New Pico Project in the command palette.
  2. In the dialog below, select C/C++. new-project-dialog

  3. Create a project with the following settings:

    • Name ... Enter the project name.
    • Board type ... Select your board type.
    • Location ... Select the parent directory where the project directory will be created.
    • Stdio support ... Leave Console over USB unchecked when you use LABOPlatform or other USB features because they conflict with each other. You can enable it by editing the CMakeLists.txt file later.
    • Code generation options ... Check Generate C++ code.

new-project

Open Existing Pico SDK Project

Open the project folder in VSCode using one of the following methods:

  • In a command prompt, change the current directory to the project folder and execute code ..
  • In a Explorer, choose the project folder, push Alt+D to focus the address bar, and execute code ..

    vscode-from-explorer

If the folder is already prepared as a Pico SDK project, just proceed with editing and building the project.

If not, you will see the following message at the bottom right corner of VSCode.

do-you-want-to-import

Click Yes and you will see the following window.

import-project

Click Import and the project will be prepared as a Pico SDK project.

When the Do you want to import this project as Raspberry Pi Pico project? message disappears before you click Yes, you can reveal it by clicking the icon notify-icon at the bottom right corner of VSCode.

Clone the pico-jxglib repository from GitHub so the direcory structure looks like this:

├── pico-jxglib/
└── your-project/
    ├── CMakeLists.txt
    ├── your-project.cpp
    └── ...
Clone the Repository

Change the current directory to the parent directory where you want to clone the pico-jxglib repository and run the following commands:

$ git clone https://github.com/ypsitau/pico-jxglib.git
$ cd pico-jxglib
$ git submodule update --init --recursive

pico-jxglib is updated almost daily. If you've already cloned it, run the following command in the pico-jxglib directory to get the latest version:

$ git pull

A directory from a Git repository can safely be moved to another location even after cloning.

Add the following lines to the end of CMakeLists.txt:

CMakeLists.txt
1
2
3
target_link_libraries(your-project jxglib_LABOPlatform_FullCmd)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../pico-jxglib pico-jxglib)
jxglib_configure_LABOPlatform(your-project)
  • jxglib_LABOPlatform_FullCmd links all the libraries of useful shell commands.
  • jxglib_configure_LABOPlatform() is required to configure libraries used by jxglib_LABOPlatform, such as TinyUSB and FatFS.

Edit your-project.cpp as follows:

your-project.cpp
#include "pico/stdlib.h"
#include "jxglib/LABOPlatform.h"

using namespace jxglib;

int main(void)
{
    ::stdio_init_all();
    LABOPlatform::Instance.Initialize();
    for (;;) {
        // Your code here
        Tickable::Tick();
    }
}

Build and flash the program to the board.

Build and Flash

The simplest way to build and flash the program is to use the UF2 file generated by the build process. Pico board, a USB cable, and a computer are all you need to get started. Here are the steps to build and flash the program:

  1. Pressing F7 on VSCode will build the project. If this is the first time you build the project, you will see the dialog shown below. Select Pico Using compilers: ... and the build process will start.

    select-a-kit

  2. After building, you can find the generated UF2 file in the build directory.

  3. Connect your Pico to the computer using a USB cable while holding the BOOTSEL button, and it will appear as a mass storage device. Copy the generated UF2 file to this device to flash it. No need to mind the destination directory, just copy it to the root directory of the device.

If you have a debug probe like this, you can also flash the program using OpenOCD and GDB. This is the recommended method for development, as it allows you to debug the program while running it on the board!

Program Explanation

LABOPlatform::Instance.Initialize() initializes the platform, including the shell and all the linked libraries. It also starts a background task that runs the shell, allowing you to use the shell commands immediately after initialization.

The function runs .startup script internally. Therefore, if you write pin configuration commands for devices or network configuration commands in the .startup script, those configurations are already done after the initialization.

In default, the shell is attached to a USB serial interface, so you can use the shell through USB serial. You can also attach the shell to a UART stdio provided by Pico SDK by calling LABOPlatform::Instance.AttachStdio().Initialize(). In that case, you also need to edit CMakeLists.txt to enable the stdio as described below:

Enable UART and/or USB stdio

Find the following lines in CMakeLists.txt:

CMakeLists.txt
pico_enable_stdio_uart(your-project 0)
pico_enable_stdio_usb(your-project 0)

You can set the value to 1 to enable stdio or 0 to disable it.

  • pico_enable_stdio_uart() enables UART stdio that uses GPIO0 (UART0 TX) and GPIO1 (UART0 RX).
  • pico_enable_stdio_usb() enables USB stdio that uses the USB interface. Make sure to disable USB stdio when you use USB features because they conflict with each other.

Following libraries are linked to use LABO-Platform features:

Library Name Description
jxglib_LABOPlatform LABOPlatform support
jxglib_LABOPlatform_FullCmd LABOPlatform full command support

These libraries link the following libraries:

Library Name Description
jxglib_Shell A command-line interface for interacting with the system
jxglib_Serial Serial communication functionalities
jxglib_FAT_Flash FAT file system support for flash memory
jxglib_FAT_SDCard FAT file system support for SD cards
jxglib_RTC_DS3231 Support for the DS3231 real-time clock
jxglib_USBDevice_MSCDrive USB Mass Storage Class (MSC) support
jxglib_USBDevice_CDCSerial USB CDC Serial support
jxglib_USBDevice_VideoTransmitter USB Video Transmitter support
jxglib_TelePlot TelePlot support
jxglib_LogicAnalyzer Logic Analyzer support

The following libraries provide shell commands that control Pico board itself:

Library Name Description
jxglib_ShellCmd_LogicAnalyzer la command that controls the built-in logic analyzer
jxglib_ShellCmd_FS File system commands such as ls, cat, and rm
jxglib_ShellCmd_ADC adc command that controls ADC
jxglib_ShellCmd_GPIO gpio command that controls GPIO
jxglib_ShellCmd_PWM pwm command that controls PWM
jxglib_ShellCmd_I2C i2c command that controls I2C interface
jxglib_ShellCmd_SPI spi command that controls SPI interface
jxglib_ShellCmd_UART uart command that controls UART interface
jxglib_ShellCmd_Resets resets command
jxglib_ShellCmd_LED led command that controls the built-in LED

The following libraries provide shell commands that control devices connected to the Pico board:

Library Name Description
jxglib_ShellCmd_Camera_OV7670 camera-ov7670 command that controls OV7670 camera device
jxglib_ShellCmd_Display_SSD1306 display-ssd1306 command that controls SSD1306 display
jxglib_ShellCmd_Display_TFT_LCD display-tft-lcd command that controls TFT LCD display
jxglib_ShellCmd_Display_WS2812 display-ws2812 command that controls WS2812 display
jxglib_ShellCmd_RTC rtc command that controls real-time clock
jxglib_ShellCmd_RTC_DS3231 rtc-ds3231 command that controls DS3231 real-time clock
jxglib_ShellCmd_Device_SDCard sdcard command that controls SD card
jxglib_ShellCmd_Device_WS2812 ws2812 command that controls WS2812 LEDs

When you use Pico W or Pico2 W, the following libraries are also linked:

Library Name Description
jxglib_ShellCmd_Net net command that configures network settings
jxglib_ShellCmd_NetUtil Network utility commands such as ping and nslookup
jxglib_ShellCmd_Net_Telnet telnet-server command that starts and stops the Telnet server