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

by PugazhM in Circuits > Raspberry Pi

27064 Views, 5 Favorites, 0 Comments

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

Circuit_V01.jpeg

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

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

Components

Pico_GPIO_V01.jpg

Raspberry Pi Pico = 1 No

Micro USB Cable

Reference

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

Schematic

Circuit_V01.jpeg
thonny_ide_program-1024x722.png

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.

Slow Blink

SlowBlink_V01.jpeg

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.

Slow Blink Python Program

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

Fast Blink

FastBlink_V01.jpeg

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.

Fast Blink Python Program

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

Pattern Blink

PatternBlink_V01.jpeg

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.

Pattern Blink Python Program

'''
Description: Onboard Timer Pattern Program. Author : M.Pugazhendi Date : 03rdJul2021
A. The timer_one is used for changing the state @100 mSec interval
B. 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 ouput
led = Pin(25, Pin.OUT)
#Initialize timer_one. Used for toggeling the LED
timer_one = Timer()
#Initialize count variable. Used for changing the State
count = 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)

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.

Change State, Using Two Timers Python Program

'''
Description: Onboard Timer / Scheduler Program.
Author     : M.Pugazhendi
Date       : 03rdJuly2021
A. Two timers are initialized.
B. The timer_two is used for changing the state @20 Sec interval
C. And initialize timer_one, trigger LED blink period either 100mSec or 250mSec or 1Sec.
'''
from machine import Pin, Timer
#Initialize the onboard LED as ouput
led = Pin(25, Pin.OUT)
#Initialize timer_one. Used for toggeling the LED
timer_one = Timer()
#Initialize timer_two. Used for changing the State
timer_two = Timer()
#Initialize state variable. Used for changing the State
state = 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 time
timer_one.init(freq=10, mode=Timer.PERIODIC, callback=BlinkLED)
state = state+1
#Subcequent timer states for 20 seconds interval
timer_two.init(freq=0.05, mode=Timer.PERIODIC, callback=ChangeState)

Conclusion

Setup.jpg

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

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