2023年4月16日 星期日

[PI PICO RP2040] Starting First Program @ C/C++

When we receive a new board, we usually start by blinking the LED and printing a message. Then, we proceed to test various examples. This is also where we begin with Raspberry Pi Pico RP2040 & C/C++.

The print display on the Raspberry Pi Pico RP2040 board uses UART (Default) output, which is UART 0, represented by the dark purple UART0_TX (1) and UART0_RX pins. The default baud rate is 115200 bps.



 // Enable UART
 stdio_init_all();
 

To initialize UART and USB, we can use the standard input/output functions such as printf(), scanf(), etc.

Blink and printf Implementation


int main() {
    // Enable UART
    stdio_init_all();


    gpio_init(25);
    gpio_set_dir(25, GPIO_OUT);    
    
    while (true) {
        gpio_put(25, 1);
        sleep_ms(1500);
        gpio_put(25, 0);
        printf("blink test\n");
        sleep_ms(1500);
    }


    return 0;
}

UART0_TX (1) and UART0_RX are connected to a USB to UART converter to begin receiving strings.

If you want to use USB CDC functionality, you can simply modify the cmake (CMakeLists.txt) file.


pico_enable_stdio_usb(newblink1 1)
pico_enable_stdio_uart(newblink1 0)

That is, enabling USB and disabling UART.

Device Manager

Serial Settings in PuTTY

Output

Source Code Link

https://github.com/cold63/Pico_C_Project/tree/main/newblink1