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.

Example

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

ExampleBasic Program DescriptionDependency Library
01_SDMount TF card-
02_RTCGet RTC data-
03_GUIGUI display program-

01_SD

Example 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 01_SD folder to the development board via Thonny and reset the board.

    MicroPython-Example-2

02_RTC

Example Description

  • Uses I2C to communicate with the onboard RTC chip, sets and reads RTC time data, and tests if the RTC interrupt is functioning correctly.

Hardware Connection

  • Connect the board to the computer using a USB cable

Code Analysis

  • RTC = PCF85063(): Creates an RTC object.
  • RTC.setDate(weekday, day, month, year): Sets the RTC date.
  • RTC.setTime(hour, minute, second): Sets the RTC time.
  • RTC.readTime(): Reads the RTC time.
  • RTC.setAlarm(second, minute, hour, day, weekday): Sets the RTC alarm.
  • RTC.enableAlarm(): Enables the RTC alarm.

Operation Result

  • Run the py files in the 02_RTC folder using Thonny.

    MicroPython-Example-2

03_GUI

Example Description

  • Drives the display via SPI communication, uses GUI drawing functions to draw text, borders, and color blocks, and refreshes the screen to complete the display.

Hardware Connection

  • Connect the board to the computer using a USB cable

Code Analysis

  • epd = EPD_1in54: Creates an LCD object.
  • epd.Clear(0xff): Clears the entire screen.
  • epd.fill(0xff): Fills the entire screen with a color.
  • epd.text("RP2350-Touch-ePaper-1.54", 0, 30, 0x00): Writes text on the screen.
  • epd.hline(10, 150, 80, 0x00): Draws a horizontal line.
  • epd.vline(10, 90, 60, 0x00): Draws a vertical line.
  • epd.display(epd.buffer): Refreshes the screen (makes it visible).

Operation Result

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

    MicroPython-Example-1