Sunday, May 30, 2021

Raspberry Pi Pico/MicroPython: uasyncio

Raspberry Pi Pico MicroPython exercise of using uasyncio:

"""
MicroPython uasyncio exercise on RP2040
"""
from sys import implementation
from os import uname
import uasyncio as asyncio
from machine import Pin
import utime

led = Pin(25, Pin.OUT)

print(implementation.name)
print(uname()[3])
print(uname()[4])
print()
print(asyncio.__name__)
print(asyncio.__version__)

#Toggle onboard LED every 500ms
async def asyncTask1():
    while True:
        led.toggle()
        await asyncio.sleep_ms(500)

#print time every 1 second
async def asyncTask2():
    while True:
        print(utime.time())
        await asyncio.sleep_ms(1000)
        
loop = asyncio.get_event_loop()
loop.create_task(asyncTask1())
loop.create_task(asyncTask2())
loop.run_forever()

print("- bye -")




~ More exercise on Raspberry Pi Pico

Raspberry Pi Pico: restore factory Flash memory

For any reasons, you want to restore your Raspberry Pi Pico to factory flash memory:
you can visit Raspberry Pi RP2040 Getting Started Guide > About Raspberry Pi Pico tab, scroll down to Resetting Flash memory section to download the flash_nuke.uf2. And flash it on your Pico.



Saturday, May 29, 2021

RPi Pico BOOTSEL button broken! How to enter BOOTLOADER mode using Python code; without BOOTSEL button and un-plug/re-plug USB.


The BOOTSEL button on my Raspberry Pi Pico broken! Here is how to reset Pico and enter BOOTLOADER mode using Python (MicroPython/CircuitPython) code; such that no need touch BOOTSEL button and un-plug/re-plug USB.
 

In case the Raspberry Pi Pico is flashed MicroPython:

import machine
machine.bootloader()

In case of CircuitPython:

import microcontroller
microcontroller.on_next_reset(microcontroller.RunMode.BOOTLOADER)
microcontroller.reset()