The raspberry pi pico w has a LED on it.
This LED is not connected to the GPIO pins of RP2040 microcontroller directly.
As you can see in the image of the pinout taken from the official datasheet.
The onboard LED is connected to a pin ‘WL_GPIO0’.
WL_GPIO0 is an internal pin.
There are different ways to program the pico W.
The easiest method is to install thonny IDE. And install micropython on the pico w.
Download Thonny IDE
After you have installed thonny. Now connect you raspberry pi pico w board to the computer USB port while holding the onboard BOOTSEL button. Then follow the steps shown in the following images.
After you have done the above steps. You now have to install a MicroPython library.
picozero is a MicroPython library which has functions for Wifi and other RP2040 chip.
To complete the projects in this path, you need to install the picozero library as a Thonny package.
In Thonny, choose Tools > Manage packages.
Code
import machine
import time
# create a Pin object to control the LED on pin 'WL_GPIO0'
led_pin = machine.Pin('WL_GPIO0', machine.Pin.OUT)
# enter an infinite loop
while True:
# set the LED pin to a high (on) state
led_pin.value(1)
# pause the program for one second
time.sleep(1)
# set the LED pin to a low (off) state
led_pin.value(0)
# pause the program for one second
time.sleep(1)
In this program, we first import the machine module and the time module. The machine module provides access to hardware-level features on the Raspberry Pi Pico, while the time module provides functions for time-related operations.
Next, we create a Pin object called led_pin to control the LED connected to the pin labeled ‘WL_GPIO0’. The machine.Pin() function is used to create the led_pin object, with the first argument specifying the pin label and the second argument specifying that the pin is an output pin, i.e. we can set its state to high or low.
Then, we enter an infinite loop using the while True: statement. Within the loop, we use the value() method of the led_pin object to set the state of the LED pin to high (on) or low (off), with a one second delay between each state change using the time.sleep() function.
Comments are added to explain each line of code and make it easier to understand the purpose and function of the program.
Leave a Reply