Raspberry Pi Pico Tutorial

Joined
Jul 30, 2021
Messages
20
Likes
3
Product Description
Raspberry Pi Pico is an official Raspberry Pi designed low-cost, high-performance microcontroller development board with a flexible digital interface. Hardware, using Raspberry Pi official self-developed RP2040 microcontroller chip, equipped with ARM Cortex M0 + dual-core processor, up to 133MHz running frequency, built-in 264KB of SRAM and 2MB of memory, and up to 26 multi-functional GPIOs onboard pins on board. The software can be developed with the C/C++ SDK provided by Raspberry Pi or with MicroPython, and there is a comprehensive development material tutorial to facilitate quick start development and embedding into the product. This is a Raspberry Pi Pico tutorial.

Product Features
Adopts the RP2040 microcontroller chip designed by Raspberry Pi

  • Dual-core ARM Cortex M0+ processor running at 133MHz flexible clock
  • Built-in 264KB SRAM and 2MB on-chip Flash
  • Stamped hole design for direct solder integration into user-designed backplanes
  • 1 host and device support
  • Supports low power sleep and hibernate modes
  • Drag-and-drop program download via USB recognition for mass storage
  • Up to 26 multi-functional GPIO pins
  • 2 SPI, 2 I2C, 2 UART, 3 12-bit ADCs, 16 controllable PWM channels
  • Precise on-chip clock and timer
  • Temperature sensors
  • On-chip accelerated floating-point library
  • 8 programmable I/O (PIO) state machines for custom peripheral support
Pinouts
Raspberry-Pi-Pico-Tutorial

Get Started Quickly
Instructions For Use
  • Download the test firmware to your computer and unzip it.
  • There are two uf2 files, one of which is the pico_micropython_20210121.uf2 file is MicroPython firmware
  • Press and hold the button on the Pico board, connect the pico to the USB port of the computer via the Micro USB cable, and then release the button.
  • Once connected, the computer will automatically recognize a removable disk (RPI-RP2)
Raspberry-Pi-Pico-Tutorial

  • Copy and drag the firmware file downloaded earlier to the RPi-RP2 mobile disk.
  • After the copy is complete, the Raspberry Pi Pico will automatically reboot. After the automatic reboot, the pico will be recognized as a virtual serial port.
Raspberry-Pi-Pico-Tutorial

Note: If the mobile disk is not automatically recognized after accessing the pico.

  1. check whether the BOOTSEL button is not pressed or released in the middle.
  2. The Micro USB cable used must be a data cable, only the power supply USB cable can not be used.
Software Environment Configuration (WIndows)
To facilitate the development of the Pico board using MicroPython on your computer, it is recommended to download the Thonny IDE.

  • Download the Thonny IDE and follow the steps to install it.
  • Thonny IDE download link (Windows version).
  • Once the installation is complete, configure the language and motherboard environment for the first time. Since we are using Pico, take care to select the Raspberry Pi Option.
Raspberry-Pi-Pico-Tutorial

Control LED Routine
  • Plug the Pico into your computer (without pressing a button), if you have not flashed MicroPython before, follow the flash firmware procedure.
  • Select Tools -> Options… -> Interpreter.
  • Select Raspberry Pi Pico in the Interpreter option (be careful to download the latest version of Thonny, otherwise, there is no such option).
  • After selecting the port to access the Pico, the COM port recognized by the computer is good.
  • Then confirm.
  • After confirming, you can see that there will be more than one Pico information in the command-line interface, now you can enter the MicroPython program here to control the pico.
Raspberry-Pi-Pico-Tutorial

Thonny Settings
Raspberry-Pi-Pico-Tutorial

Thonny Set Up The Port
Raspberry-Pi-Pico-Tutorial

Thonny Pico Interface
  • Looking at Pico’s pin diagram we know that the control pin for Pico’s onboard LED is GPIO25, here we try to control the onboard LED.
  • In Thonny, run the following code in sequence.
>>> from machine import Pin

>>> led = Pin(25, Pin.OUT)

>>> led.value(1)

>>> led.value(0)

After running the code in sequence, you can see the LEDs on the Pico board are lit and then turned off

Note

If you want to know more about the functions of Raspberry Pi Pico Micropython, you can check the Pico Python SDK manual.

• The default serial port of Raspberry Pi is used for serial terminal debugging, if you want to use the serial port normally, you need to modify the Raspberry Pi settings. If you turn off the serial terminal debugging function, you can no longer access the Raspberry Pi through the serial port, you need to turn it on again before you can control the Raspberry Pi through the serial port.

I. Release The Serial Port
Execute the following command to enter the Raspberry Pi configuration

sudo raspi-config

Select Interfacing Options ->Serial ->no -> yes to disable the serial debugging function and open the serial port.

• Open the /boot/config.txt file and find the following configuration statement to enable the serial port, if not, you can add it at the end of the file.

enable_uart=1

II. Use Minicom To Debug The Serial Port
• After setting up the serial port can be used normally, you can test whether the Raspberry Pi UART is working properly, Pioneer600 expansion board with USB to UART function, use the USB cable to connect to the computer. minicom is a simple and useful tool. minicom is a Linux platform serial debugging tool. It is equivalent to a serial debugging assistant on windows.

1、Minicom Installation
sudo apt-get install minicom

2、Minicom Start
minicom -D /dev/ttyS0

• The default baud rate is 115200, if you want to set the baud rate to 9600, add the parameter -b 9600, -D stands for port, /dev/ttyS0 is similar to COM1 in windows.

Raspberry-Pi-Pico-Tutorial

Also, open the serial port assistant in windows. Set the baud rate to 115200 and select the corresponding serial port number.
 
Last edited by a moderator:
Top