Skip to main content

Working with MicroPython

This chapter contains the following sections. Please read as needed:

MicroPython Getting Started Tutorial

New to Pico MicroPython development and want to get started quickly? We have prepared a general introductory tutorial for you. These tutorial is designed to help developers quickly become familiar with Thonny IDE and start developing. It covers environment setup, project creation, component usage, and peripheral programming, helping you take the first step in MicroPython programming.

Setting Up Development Environment

Please refer to the Install and Configure Thonny IDE Tutorial to download and install the Thonny IDE.

Demo

The MicroPython demos are located in the examples\MicroPython directory of the demo package.

DemoBasic Program DescriptionDependency Library
01_GUILCD GUI display program-
02_SDMount TF card-
03_IMUGet six-axis IMU data-

01_GUI

Demo Description

  • Use SPI to communicate with the LCD and implement touch tracking on the LCD via GUI.

Hardware Connection

  • Connect the board to the computer using a USB cable

Code Analysis

  • lcd = LCD_1inch54(): Create an LCD object.
  • touch = Touch_CST816T(): Initialize the touch object.
  • touch_gesture(): Gesture test.
  • touch_hand_writing(): Draw points and display them on the LCD.

Operation Result

  • Upload all .py files from the 01_GUI folder to the development board using Thonny, and run the RP2350-Touch-LCD-1.54.py program.

    MicroPython-Example-1

02_SD

Demo Description

  • Uses SPI to communicate with the TF card and mounts the TF card to the development board. After successful mounting, you can view and modify the contents of the TF card via Thonny.

Hardware Connection

  • Insert a TF card
  • Connect the board to the computer using a USB cable

Code Analysis

  • sdcard.SDCard(spi, cs, baudrate): Creates a TF card object and binds the initialized SPI interface and CS pin to the TF card driver.
  • uos.mount(sd, '/sd'): Mounts the TF card file system to the /sd directory. After successful mounting, users can perform file read/write operations on the TF card via the /sd path, such as creating, reading, or deleting files.

Operation Result

  • Upload all py files from the 02_SD folder to the development board via Thonny and reset the board. After resetting, the development board will automatically mount the TF card to the sd directory according to the boot.py program.

    MicroPython-Example-2

03_IMU

Demo Description

  • Uses I2C to communicate with the onboard six-axis sensor and reads the sensor data.

Hardware Connection

  • Connect the board to the computer using a USB cable

Code Analysis

  • IMU = QMI8658(): Creates an IMU object.
  • IMU.Read_XYZ(): Reads the six-axis sensor data.

Operation Result

  • Run the py files in the 03_IMU folder using Thonny.

    MicroPython-Example-4