yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
Raspberry Pi Pico 2📖
1. About Pico 2
  • Introduction to Raspberry Pi PICO 2
2. Development-python
  • 1. Flash the firmware
  • 2. Software environment configuration
  • 3. Download a program
3. Development-C
  • 1. Software environment configuration
  • 2. Download a program
4. Python course
  • 1. Flash the onboard LED light
  • 2. Onboard temperature sensor reading
  • 3. Button control LED light
  • 4. Buzzer
  • 5. PWM pin
5. C course
  • 1. Flash the onboard LED light
  • 2. Onboard temperature sensor reading
  • 3. Button control LED light
  • 4. Buzzer
  • 5. PWM pin
Download
  • C software
  • Python software
  • Official information
Download ZIP

Welcome to Raspberry Pi Pico 2 repository

5. PWM pin

5. PWM pin

1. Learning objectives

  1. Learn to control LED lights with the Raspberry Pi Pico 2.
  2. Understand the PWM output of the Raspberry Pi Pico 2.

2. Hardware construction

This course.

LED light*1

220Ω resistor*1

image.png

3. Program analysis

Thonny programming

For the use of ThonnyIDE, please refer to the previous environment construction related courses.

xxxxxxxxxx
import machine
import utime
​
led = machine.PWM(machine.Pin(15))
led.freq(1000)
​
while True:
    for i in range(65535):
        led.duty_u16(i)
        utime.sleep(0.0005)

import machine

The machine library contains all the instructions MicroPython needs to communicate with Pico and other MicroPython-compatible devices, extending the language of physical computing.

 

import utime

The "utime" library. This library handles everything to do with time, from measuring it to inserting delays into your program. The units are in seconds.

 

led = machine.PWM(machine.Pin(15))

Set IO15 to PWM output, that is, use the B output of PWM slice 7.

 

led.freq(1000)

Set the frequency to 1000 Hz - 1000 cycles per second.

 

led.duty_u16(i)

Set the duty cycle.

 

Through the While loop, modify the PWM duty cycle value through the for loop.

 

4. Experimental phenomenon

After the program is downloaded, we can see the process of the LED light slowly turning on from off.

Buzzer
Flash the onboard LED light

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文