PICO-Cam-A

From Waveshare Wiki
Jump to: navigation, search
PICO-Cam-A
PICO-Cam-A.jpg

RP2040
USB Type-C
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

{{{name6}}}

Overview

Introduction

PICO-Cam-A is a high-performance microcontroller development board designed by Waveshare. Despite its small form factor, it integrates a 1.14inch LCD, Cam camera, buttons, and other peripherals, and exposes some GPIO and Debug interfaces for user development and product integration.

Features

  • RP2040 microcontroller chip officially designed by Raspberry Pi
  • Dual-core ARM Cortex M0+ processor, flexible clock running up to 133 MHz
  • Built-in 264KB of SRAM and 16MB of on-chip Flash
  • Type-C connector, keeps it up to date, easier to use
  • Onboard HM01B0 grayscale camera
  • Onboard 1.14inch 240×135 pixels 65K color IPS LCD display
  • USB1.1 host and device support
  • Low-power sleep and dormant modes
  • Drag-and-drop programming using mass storage over USB
  • 13 GPIO pins are routed through a 1.27 pitch female header
  • 2 × SPI, 2 × I2C, 2 × UART, 4 × 12-bit ADC, 13 × controllable PWM channels
  • Accurate clock and timer on-chip
  • Temperature sensor
  • On-chip accelerated floating-point library
  • 8 × Programmable I/O (PIO) state machines for custom peripheral support

Specifications

LCD parameters
Control chip ST7789V Resolution 135(H)RGB x 240(V)
Communication interface SPI Display Size 14.864 (H) x 24.912 (V) mm
Display Panel IPS Pixel size 0.1101 (H) x 0.1035 (V) mm

Pinout Definition


800px-PICO-Cam-A-details-inter.jpg

Dimensions


800px-PICO-Cam-A-details-size.jpg

Pico Getting Started

Basic Introduction

Raspberry Pi Pico Basics

C/C++ Series

For C/C++, it is recommended to use Pico VS Code for development. This is a Microsoft Visual Studio Code extension designed to make it easier for you to create, develop, and debug projects for the Raspberry Pi Pico series development boards. No matter if you are a beginner or an experienced professional, this tool can assist you in developing Pico with confidence and ease. Here's how to install and use the extension.

  • Official website tutorial: https://www.raspberrypi.com/news/pico-vscode-extension/
  • This tutorial is suitable for Raspberry Pi Pico, Pico2 and the RP2040 and RP2350 series development boards developed by Waveshare
  • The development environment defaults to Windows11. For other environments, please refer to the official tutorial for installation

Install VSCode

  1. First, click to download pico-vscode package, unzip and open the package, double-click to install VSCode
    Pico-vscode-1.JPG
    Note: If vscode is installed, check if the version is v1.87.0 or later
    Pico-vscode-2.JPG
    Pico-vscode-3.JPG

Install Extension

  1. Click Extensions and select Install from VSIX
    Pico-vscode-4.JPG
  2. Select the package with the vsix suffix and click Install
    Pico-vscode-5.JPG
  3. Then vscode will automatically install raspberry-pi-pico and its dependency extensions, you can click Refresh to check the installation progress
    Pico-vscode-6.JPG
  4. The text in the right lower corner shows that the installation is complete. Close VSCode
    Pico-vscode-7.JPG

Configure Extension

  1. Open directory C:\Users\username and copy the entire .pico-sdk to that directory
    Pico-vscode-8.JPG
  2. The copy is completed
    Pico-vscode-9.JPG
  3. Open vscode and configure the paths for the Raspberry Pi Pico extensions
    Pico-vscode-10.JPG
    The configuration is as follows:
    Cmake Path:
    ${HOME}/.pico-sdk/cmake/v3.28.6/bin/cmake.exe
    
    Git Path:
    ${HOME}/.pico-sdk/git/cmd/git.exe    
    
    Ninja Path:
    ${HOME}/.pico-sdk/ninja/v1.12.1/ninja.exe
    
    Python3 Path:
    ${HOME}/.pico-sdk/python/3.12.1/python.exe             
    

New Project

  1. The configuration is complete, create a new project, enter the project name, select the path, and click Create to create the project
    To test the official example, you can click on the Example next to the project name to select
    Pico-vscode-11.JPG
  2. The project is created successfully
    Pico-vscode-12.JPG
  3. Select the SDK version
    Pico-vscode-13.JPG
  4. Select Yes for advanced configuration
    Pico-vscode-14.JPG
  5. Choose the cross-compilation chain, 13.2.Rel1 is applicable for ARM cores, RISCV.13.3 is applicable for RISCV cores. You can select either based on your requirements
    Pico-vscode-15.JPG
  6. Select Default for CMake version (the path configured earlier)
    Pico-vscode-16.JPG
  7. Select Default for Ninjaversion
    Pico-vscode-17.JPG
  8. Select the development board
    Pico-vscode-18.JPG
  9. Click Complie to compile
    Pico-vscode-19.JPG
  10. The uf2 format file is successfully compiled
    Pico-vscode-20.JPG

Import Project

  1. The Cmake file of the imported project cannot have Chinese (including comments), otherwise the import may fail
  2. To import your own project, you need to add a line of code to the Cmake file to switch between pico and pico2 normally, otherwise even if pico2 is selected, the compiled firmware will still be suitable for pico
    Pico-vscode-21.JPG
    set(PICO_BOARD pico CACHE STRING "Board type")

Update Extension

  1. The extension version in the offline package is 0.15.2, and you can also choose to update to the latest version after the installation is complete
    Pico-vscode-22.JPG

Open Source Demos

Raspberry Pi official C/C++ demo (github)
Arduino official C/C++ demo (github)

Demo

C Demo

Flash Firmware

Method 1: After holding down the BOOT button and connecting to the computer, release the BOOT button, a removable disk will appear on the computer, copy the firmware library with the suffix .uf2 into it
Method 2: After connecting to the computer, press the BOOT button and the RESET key at the same time, release the RESET key and then release the BOOT button, a removable disk will appear on the computer, copy the firmware library with the suffix .uf2 into it

Code Analysis

Demo description
This demo mainly captures images through a camera and displays them on a 1.14inch LCD. The demo uses multi-core processing, where Core 1 is responsible for acquiring image data and image processing, and Core 0 is responsible for image display
Code 1 analysis

  • Push data
    multicore_fifo_push_blocking() is a function provided by the Pico SDK to push data to the FIFO (First In, First Out) queue of a multi-core system. Here Core 1 will push FLAG_VALUE into the FIFO, and Core 0 will block waiting for data FLAG_VALUE from Core 1 during the execution process
    multicore_fifo_push_blocking(FLAG_VALUE);
    
  • Wait for data
    Core 1 blocks waiting for data from Core 0
    uint32_t ack = multicore_fifo_pop_blocking();
    
  • Initialize LCD
    Call DEV_Module_Init() to initialize the LCD-related pins and buttons, call LCD_1IN14_V2_Init() to initialize the LCD
    DEV_Module_Init();
    LCD_1IN14_V2_Init(HORIZONTAL);
    LCD_1IN14_V2_Clear(BLACK);
    UDOUBLE Imagesize = LCD_1IN14_V2_HEIGHT * LCD_1IN14_V2_WIDTH * 2;
    UWORD *BlackImage;
    if ((BlackImage = (UWORD *)malloc(Imagesize)) == NULL)
    {
        printf("Failed to apply for black memory...\r\n");
        exit(0);
    }
    
  • Display image
    Call Paint_DrawImage() to draw the image, then call LCD_1IN14_V2_Display() to display the image on the LCD
    Paint_NewImage((UBYTE *)BlackImage, LCD_1IN14_V2.WIDTH, LCD_1IN14_V2.HEIGHT, 0, WHITE);
    Paint_SetScale(65);
    Paint_SetRotate(ROTATE_0);
    Paint_DrawImage(gImage_waveshare, 0, 0, 240, 135);
    LCD_1IN14_V2_Display(BlackImage);
    DEV_Delay_ms(500);
    
  • Initialize the camera
    This code calls cam_config_struct() to initialize the camera configuration structure config, and then calls cam_init() to initialize the camera
    struct cam_config config;
    cam_config_struct(&config);
    cam_init(&config);
    

Process images
This code is a loop where the camera captures a frame of image in each iteration, then processes the image. Finally, the processed image data is stored in displayBuf, and the imageReady flag is set to 1, indicating that the image is ready to be displayed

    while (true) {
        cam_capture_frame(&config);
    
        uint16_t index = 0;
        for (int y = 134; y > 0; y--) {
            for (int x = 0; x < 240; x++) {
                uint16_t c = image_buf[(y)*324+(x)];
                uint16_t imageRGB = (((c & 0xF8) << 8) | ((c & 0xFC) << 3) | ((c & 0xF8) >> 3));
                displayBuf[index++] = (uint16_t)(imageRGB >> 8) & 0xFF;
                displayBuf[index++] = (uint16_t)(imageRGB) & 0xFF;
            }
        }
    
        imageReady = 1;
    }
    

Code 0 analysis

  • Start Core1
    multicore_launch_core1 is a function provided by the Pico SDK to start the execution of Core 1 on Raspberry Pi Pico. This line of code starts Core 1 to execute the specified function core1_entry() 1 by calling multicore_launch_core1()
    multicore_launch_core1(core1_entry);
    
  • Wait for data
    Core 0 blocks waiting for data from Core 1. If data is successfully received with FLAG_VALUE, it sends data to Core 1
    uint32_t ack = multicore_fifo_pop_blocking();
    if (ack != FLAG_VALUE)
        printf("Error: Core 0 failed to receive acknowledgment from core 1!\n");
    else {
        multicore_fifo_push_blocking(FLAG_VALUE);
        printf("Success: Core 0 Received acknowledgment from core 1!\n");
    }
    
  • Main loop
    The main loop continuously checks the imageReady flag. Once the imageReady flag is detected as 1, indicating that the image is ready to be displayed. Then LCD_1IN14_V2_Display() is called to display the image and the imageReady flag is reset to 0 after it is displayed
    while (1) {
        if (imageReady == 1) {
            LCD_1IN14_V2_Display((uint16_t*)displayBuf);
            // Reset the imageReady flag after displaying the image
            imageReady = 0;
        }
        DEV_Delay_ms(1);
    }
    

Run Demo


  • Flash the firmware, and the PICO-Cam-A will display the boot interface after powering on, and then display the footage captured by the camera in real time
    PICO-Cam-A-show.jpg


FAQ

Support




Technical Support

If you need technical support or have any feedback/review, please click the Submit Now button to submit a ticket, Our support team will check and reply to you within 1 to 2 working days. Please be patient as we make every effort to help you to resolve the issue.
Working Time: 9 AM - 6 PM GMT+8 (Monday to Friday)