Build Your Own AI Assistant Part 1 - Creating the Assistant
115007 Views
Is the new Raspberry Pi AI Kit better than Google Coral?
103855 Views
Control Arduino with Python using Firmata / PyFirmata
86426 Views
How to Map with LiDAR - using a Raspberry Pi Zero 2W, RPLidar and Rviz
55270 Views
Node-Red Automation, MQTT, NodeMCU & MicroPython
51306 Views
Creating a Supercomputer with a Raspberry Pi 5 Cluster and Docker Swarm!
50568 Views
Installing and Using DeepSeek-R1:1.5 on a Raspberry Pi with Docker
Gamepad & BurgerBot
Level Up your CAD Skills
Operation Pico
Raspberry Pi Home Hub
Hacky Temperature and Humidity Sensor
Using the Raspberry Pi Pico's Built-in Temperature Sensor
0h 24m
Getting Started with SQL
0h 32m
Introduction to the Linux Command Line on Raspberry Pi OS
0h 42m
How to install MicroPython
0h 8m
Wall Drawing Robot Tutorial
0h 22m
BrachioGraph Tutorial
0h 16m
Learn Linux from the basics to advanced topics.
Learn how to use a Raspberry Pi Pico
Learn MicroPython the best language for MicroControllers
Learn Docker, the leading containerization platform. Docker is used to build, ship, and run applications in a consistent and reliable manner, making it a popular choice for DevOps and cloud-native development.
Learn how to build SMARS robots, starting with the 3D Printing the model, Designing SMARS and Programming SMARS
Learn how to build robots, starting with the basics, then move on to learning Python and MicroPython for microcontrollers, finally learn how to make things with Fusion 360.
Learn Python, the most popular programming language in the world. Python is used in many different areas, including Web Development, Data Science, Machine Learning, Robotics and more.
Learn how to create robots in 3D, using Fusion 360 and FreeCAD. The models can be printed out using a 3d printer and then assembled into a physical robot.
Learn how to create Databases in Python, with SQLite3 and Redis.
KevsRobots Learning Platform
35% Percent Complete
By Kevin McAleer, 4 Minutes
Welcome to Lesson 6 of the Raspberry Pi Pico with MicroPython - GPIO Mastery course. In this lesson, we will learn how to control LEDs using Pulse Width Modulation (PWM) with the Raspberry Pi Pico and MicroPython.
Raspberry Pi Pico with MicroPython - GPIO Mastery
In this lesson, you will learn:
After you have completed this lesson, you will know how to control the brightness of an LED using Pulse Width Modulation (PWM) with the Raspberry Pi Pico and MicroPython. You will be able to set up an LED circuit and write MicroPython code to control the LED’s brightness using PWM.
To follow this lesson, you will need:
Digital input and output are used to read or write binary values (0s and 1s) from or to the Raspberry Pi Pico pins. You can use digital input and output to control various types of devices, such as LEDs, motors, and sensors.
To use a pin on the Raspberry Pi Pico for digital input or output, you need to configure it for digital I/O. This is done using the Pin class in MicroPython. To configure a pin for digital output, you can use the following code:
Pin
from machine import Pin # Configure pin 0 for digital output led = Pin(0, Pin.OUT)
To set the value of a digital output pin, you can use the value() method of the Pin class. For example, to turn on an LED connected to pin 0, you can use the following code:
from machine import Pin # Configure pin 0 for digital output led = Pin(0, Pin.OUT) # Turn on the LED led.value(1)
PWM can be used to control the brightness of an LED. PWM works by rapidly turning the LED on and off at a specific frequency, and varying the duty cycle (the percentage of time the LED is on) to control the brightness of the LED.
To use PWM to control the brightness of an LED connected to a Raspberry Pi Pico pin, you can use the PWM class in MicroPython. To set up a PWM pin, you can use the following code:
PWM
from machine import Pin, PWM # Configure pin 0 for PWM led_pwm = PWM(Pin(0))
To control the brightness of the LED, you can use the duty() method of the PWM class. The duty() method takes a value between 0 (LED off) and 1023 (LED fully on) to set the duty cycle of the PWM signal. For example, to set the LED brightness to 50%, you can use the following code:
duty()
from machine import Pin, PWM # Configure pin 0 for PWM led_pwm = PWM(Pin(0)) # Set the LED brightness to 50% led_pwm.duty(512)
In this lesson, you learned about digital input and output, how to configure Raspberry Pi Pico pins for digital I/O, and how to use PWM to control the brightness of an LED. You can use this knowledge to control various types of devices in your Raspberry Pi Pico projects, and create dynamic and interactive projects with LEDs, motors, and sensors.
In this lesson, you will learn how to control the brightness of an LED using Pulse Width Modulation (PWM) with the Raspberry Pi Pico and MicroPython. You will learn how to set up an LED circuit and write MicroPython code to control the LED’s brightness using PWM.
< Previous Next >