Using serial over USB to print messages from the Pico.
Python Interface
# Print a string
print(string)C Interface
#include "pico/stdlib.h"
// Initialise the Standard I/O interface.
stdio_init_all();
// Print a formatted string
stdio_printf(const char* format, ...);Python Instructions
MicroPython has a built in console so that you can send text to and from the Pico. This is useful for basic debugging.
To write some text to the console, use the following function:
print("Your text here")The output will appear in the MicroPico Terminal in VSCode.
To get input from the user, you can use this function:
str = input()The result is a string containing the text that the user entered.
C Instructions
You can use a USB serial monitor program to trace output logs from the Pico. This is useful to print out some basic debugging information or to get some external input.
In the C code, you need to add the following function call to your main() function, to turn on the serial communication:
stdio_init_all();VSCode has a built-in serial monitor, you can find it as one of the tabs in the “Terminal”:

Other serial monitor programs are:
- PuTTY (Windows)
minicom(Linux, macOS)
Build and upload the serial-monitor program, connect the serial port and then reset the Pico. You should see a message appear in the log.
- On Linux/macOS, the serial port is
/dev/ttyACM0 - On Windows, the serial port will be called
COM*where * is a number.
Serial Input
The serial monitor can also be used to send inputs to the Pico over USB. Open the serial-monitor-input.cpp file to see how to do this.
A helper function has been written to make the process easier.
size_t gets_s(char* string, size_t string_size);The code in serial-monitor-input.cpp asks the user for a password, then prints a message depending on whether it is correct or not.
Exercises
Exercise
Can you make a short quiz using the serial input and output?
Print a message to ask a question, and then when the user gives an answer, print out “Correct” or “Incorrect”.
Hint: use the
strcmpfunction to check if strings are equal.