Raspberry Pi Pico -- Getting Started -- on Board Blink LED (2024)

Introduction: Raspberry Pi Pico -- Getting Started -- on Board Blink LED

By PugazhM

More by the author:

The "Raspberry Pi Pico -- Getting Started -- On Board Blink LED" explains about, getting started and accessing the on-board LED, through Python program

Getting Started Video Link

Step 1: Abstract

The Raspberry Pi Pico is a tiny, fast, and versatile board built using RP2040 features a dual-core Arm Cortex-M0+ processor with 264KB internal RAM and support for up to 16MB of off-chip Flash. It provides wide range of flexible I/O options includes I2C, SPI, and uniquely Programmable I/O (GPIO) pins.

This experimentation explains about, getting started and accessing the on-board LED, through Python program

Step 2: Components

Raspberry Pi Pico = 1 No

Micro USB Cable

Step 3: Reference

Get started with MicroPython on Raspberry Pi Pico” by Gareth Halfacree and Ben Everard

Step 4: Schematic

Connect the RPi Pico board to USB port of the PC / Laptop as illustrated.

Download and install the Thonny Micro Python integrated development environment (IDE) from following web site or githhub thonny.org https://github.com/thonny/thonny/releases/tag/v3....

Run Thonny IDE

Select the Tools -- Options – Interpreter – MicroPython (Raspberry Pi Pico)

Plug in the RPi Pico to micro-USB cable for connecting to PC or Laptop. “

BOOTSEL” switch is used for selecting two start up modes of RPi Pico.

Pressing “BOOTSEL” switch, then plug in into micro-USB cable to laptop. After 3 to 10 seconds, release the “BOOTSEL” switch.

Now the RPi Pico will be identified as removable mass storage drive, called RPI-RP2 on PC or Laptop. Drag and drop the needed python (“.py”) files.

The RPi Pico drive has two more files. The file INDEX.HTM, contains the “welcome page” and information about download option of MicroPython firmware “micropython.uf2”.

Download the firmware and save it to local drive.

Drag and drop the “micropython.uf2” file to RPi Pico drive, root folder.

The file INFO_UF2.TXT, contains the information about RPi Pico boot loader version, etc.

Drag and drop the needed python (“.py”) files. The “main.py” is the first starting file, which start executes after power up.

Step 5: Slow Blink

RPi Pico contains an on-board LED, which is connected to GP25 general purpose Digital In / Out pin.

Import Pin and Timer libraries

The document related to MicroPython “TIMER” class can be found on the following link

o https://docs.micropython.org/en/latest/library/ma...

MicroPython’s Timer class defines a baseline operation of executing a callback with a given period (or once after some delay)

timer.init function callbacks the blink functionality for toggling the LED at 500mS duration. (frequency = 2 per second)

Write the main.py into RPi Pico board, and “power OFF” then “power ON” will slow blink the on board LED at 500mS duration.

Step 6: Slow Blink Python Program

'''
Description: Onboard LED Blink Program.Author : M.PugazhendiDate : 07thJul2021
A. Intialize timer_one, trigger LED blink period to 500 mSec.
'''
from machine import Pin, Timerled = Pin(25, Pin.OUT)timer = Timer()
def blink(timer): led.toggle()
timer.init(freq=2, mode=Timer.PERIODIC, callback=blink)

Attachments

  • OnboardLEDBlink_2Hz._500mS.py

    Download

Step 7: Fast Blink

RPi Pico contains an on-board LED, which is connected to GP25 general purpose Digital In / Out pin.

Import Pin and Timer libraries

The document related to MicroPython “TIMER” class can be found on the following link

o https://docs.micropython.org/en/latest/library/ma...

MicroPython’s Timer class defines a baseline operation of executing a callback with a given period (or once after some delay)

timer.init function callbacks the blink functionality for toggling the LED at 100mS duration. (frequency = 10 per second)

Write the main.py into RPi Pico board, and “power OFF” then “power ON” will slow blink the on bord LED at 100mS duration.

Step 8: Fast Blink Python Program

'''
Description: Onboard LED Blink Program.Author : M.PugazhendiDate : 07thJul2021
A. Intialize timer_one, trigger LED blink period to 100 mSec.
'''
from machine import Pin, Timerled = Pin(25, Pin.OUT)timer = Timer()
def blink(timer): led.toggle()
timer.init(freq=10, mode=Timer.PERIODIC, callback=blink)

Attachments

  • OnboardLEDBlink_10Hz._100mS.py

    Download

Step 9: Pattern Blink

RPi Pico contains an on-board LED, which is connected to GP25 general purpose Digital In / Out pin.

Import Pin and Timer libraries

timer.init function callbacks the ChangeState functionality at 100mS duration, for toggling the LED. (frequency = 10 per second)

Count variable is used for turning on / turning off LED, at 3 Times On/Off LED at 100mS duration, and then 2500mS off

Write the main.py into RPi Pico board, and “power OFF” then “power ON” will execute the program.

Step 10: Pattern Blink Python Program

'''
Description: Onboard Timer Pattern Program.Author : M.PugazhendiDate : 03rdJul2021
A. The timer_one is used for changing the state @100 mSec intervalB. Count variable is used for turn on / turn off LED. 3 Times On/Off LED and 250mS off..'''
from machine import Pin, Timer
#Initialize the onboard LED as ouputled = Pin(25, Pin.OUT)
#Initialize timer_one. Used for toggeling the LEDtimer_one = Timer()
#Initialize count variable. Used for changing the Statecount = 1 def ChangeState(timer_two): global count if count < 6: # Toggle LED led.toggle() count = count+1 else: # Turn off LED led.off() count = count+1 if count == 30: # Reset Count count = 1 timer_one.init(freq=10, mode=Timer.PERIODIC, callback=ChangeState)

Attachments

  • OnLED_PatternBlink.py

    Download

Step 11: Change State, Using Two Timers

RPi Pico contains an on-board LED, which is connected to GP25 general purpose Digital In / Out pin.

Import Pin and Timer libraries

Two timers are initialized.

The timer_two is used for changing the state @20 Sec interval.

And initialize timer_one ,for triggering LED blink period either 100mSec or 250mSec or 1Sec

Timer_two.init function callbacks the ChangeState functionality at 20 Sec duration, for toggling the LED, as per state change.

State variable is used for changing the count.

Write the main.py into RPi Pico board, and “power OFF” then “power ON” will execute the program.

Step 12: Change State, Using Two Timers Python Program

'''
Description: Onboard Timer / Scheduler Program.Author : M.PugazhendiDate : 03rdJuly2021
A. Two timers are initialized.B. The timer_two is used for changing the state @20 Sec intervalC. And initialize timer_one, trigger LED blink period either 100mSec or 250mSec or 1Sec.
'''
from machine import Pin, Timer
#Initialize the onboard LED as ouputled = Pin(25, Pin.OUT)
#Initialize timer_one. Used for toggeling the LEDtimer_one = Timer()
#Initialize timer_two. Used for changing the Statetimer_two = Timer()
#Initialize state variable. Used for changing the Statestate = 1
def BlinkLED(timer_one): led.toggle() def ChangeState(timer_two): global state if state == 1: # 100mS Timer initialization timer_one.init(freq=10, mode=Timer.PERIODIC, callback=BlinkLED) state = state+1 elif state == 2: # 250mS Timer initialization timer_one.init(freq=4, mode=Timer.PERIODIC, callback=BlinkLED) state = state+1 elif state == 3: # 1000mS Timer initialization timer_one.init(freq=1, mode=Timer.PERIODIC, callback=BlinkLED) state = 1 else: # Default state # 100mS Timer initialization state = 1 timer_one.init(freq=10, mode=Timer.PERIODIC, callback=BlinkLED) # Initialize the timer one for first timetimer_one.init(freq=10, mode=Timer.PERIODIC, callback=BlinkLED)state = state+1
#Subcequent timer states for 20 seconds intervaltimer_two.init(freq=0.05, mode=Timer.PERIODIC, callback=ChangeState)

Attachments

  • OnBoardTimerScheduler.py

    Download

Step 13: Conclusion

The project is successfully completed with RPi Pico, on board LED and educated on following subjects.

Install and running the Tonny python compiler.

Connecting and identifying the RPi Pico as mass storage device.

Flashing the MicroPython firmware (micropython.uf2) into RPi Pico.

Utilizing micropython “Pin” and “Timer” libraries Simple timer event generation and task execution mechanism for executing the python program.

Programming on board LED, and executing the program on RPi Pico hardware

Step 14: Results Video and Links

SlowBlink.mp4

FastBlink.mp4

PatternBlink.mp4

ChangeState.mp4

Please Visit You Tube for the Videos:,

"Raspberry Pi Pico -- Getting Started -- on Board Blink LED"

If you enjoyed this instruct-able, then make sure you
subscribe

Thanking You

Attachments

  • Raspberry Pi Pico -- Getting Started -- on Board Blink LED - Step #14

    Download

  • Raspberry Pi Pico -- Getting Started -- on Board Blink LED - Step #14

    Download

  • Raspberry Pi Pico -- Getting Started -- on Board Blink LED - Step #14

    Download

Raspberry Pi Pico -- Getting Started -- on Board Blink LED (2024)
Top Articles
Latest Posts
Article information

Author: Terrell Hackett

Last Updated:

Views: 6483

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Terrell Hackett

Birthday: 1992-03-17

Address: Suite 453 459 Gibson Squares, East Adriane, AK 71925-5692

Phone: +21811810803470

Job: Chief Representative

Hobby: Board games, Rock climbing, Ghost hunting, Origami, Kabaddi, Mushroom hunting, Gaming

Introduction: My name is Terrell Hackett, I am a gleaming, brainy, courageous, helpful, healthy, cooperative, graceful person who loves writing and wants to share my knowledge and understanding with you.